Skip to content

Commit 690b269

Browse files
Copilotcsyonghe
andcommitted
fix: skip slangpy auto-discovery when user include path already resolves slangpy
Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
1 parent 1098669 commit 690b269

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

client/src/nativeClientMain.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,29 @@ let worker: Worker;
2222

2323
const PYTHON_LOOKUP_TIMEOUT_MS = 2000;
2424

25+
function canFindSlangpyInUserSearchPaths(): boolean {
26+
const configuredSearchPathsRaw = vscode.workspace.getConfiguration('slang').get<unknown>('additionalSearchPaths', []);
27+
const configuredSearchPaths = Array.isArray(configuredSearchPathsRaw)
28+
? configuredSearchPathsRaw
29+
.filter((searchPath): searchPath is string => typeof searchPath === 'string' && searchPath.trim().length > 0)
30+
.map((searchPath) => searchPath.trim())
31+
: [];
32+
const workspaceRoots = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath) ?? [];
33+
34+
for (const configuredPath of configuredSearchPaths) {
35+
const candidatePaths = path.isAbsolute(configuredPath)
36+
? [configuredPath]
37+
: workspaceRoots.map((workspaceRoot) => path.resolve(workspaceRoot, configuredPath));
38+
39+
for (const candidatePath of candidatePaths) {
40+
if (fs.existsSync(path.join(candidatePath, 'slangpy.slang'))) {
41+
return true;
42+
}
43+
}
44+
}
45+
return false;
46+
}
47+
2548
async function findSlangpySearchPath(): Promise<string | undefined> {
2649
let pythonInterpreterPath: string | undefined;
2750
try {
@@ -177,7 +200,7 @@ function sendDidChangeTextDocument(event: vscode.TextDocumentChangeEvent) {
177200

178201
export async function activate(context: ExtensionContext) {
179202
const serverModule = getSlangdLocation(context);
180-
const slangpySearchPath = await findSlangpySearchPath();
203+
const slangpySearchPath = canFindSlangpyInUserSearchPaths() ? undefined : await findSlangpySearchPath();
181204
const serverOptions: ServerOptions = {
182205
run: { command: serverModule, transport: TransportKind.stdio },
183206
debug: {

0 commit comments

Comments
 (0)