diff --git a/src/state.ts b/src/state.ts index ec4a2cbd2..f1184c7ec 100644 --- a/src/state.ts +++ b/src/state.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import Analytics from './analytics'; import * as util from './utilities'; +import * as filesCache from './files-cache' import * as path from 'path'; import * as os from 'os'; import * as fs from 'fs'; @@ -140,14 +141,20 @@ export async function initProjectDir(uri?: vscode.Uri): Promise { } } -async function findLocalProjectRoot(projectFileNames, doc, workspaceFolder): Promise { +function isNamespace(path: string): boolean { + const content = filesCache.content(path); + const hasNsDecl = /^\(ns /.test(content); + return hasNsDecl; +} + +async function findLocalProjectRoot(projectFileNames: string[], doc: vscode.TextDocument, workspaceFolder: vscode.WorkspaceFolder): Promise { if (workspaceFolder) { let rootPath: string = path.resolve(workspaceFolder.uri.fsPath); setStateValue(PROJECT_DIR_KEY, rootPath); setStateValue(PROJECT_DIR_URI_KEY, workspaceFolder.uri); - let d = null; - let prev = null; + let d: string = null; + let prev: string = null; if (doc && path.dirname(doc.uri.fsPath) !== '.') { d = path.dirname(doc.uri.fsPath); } else { @@ -156,7 +163,7 @@ async function findLocalProjectRoot(projectFileNames, doc, workspaceFolder): Pro while (d !== prev) { for (let projectFile in projectFileNames) { const p = path.resolve(d, projectFileNames[projectFile]); - if (fs.existsSync(p)) { + if (fs.existsSync(p) && !isNamespace(p)) { rootPath = d; break; } @@ -192,8 +199,10 @@ async function findProjectRootUri(projectFileNames, doc, workspaceFolder): Promi const u = vscode.Uri.joinPath(searchUri, projectFileNames[projectFile]); try { await vscode.workspace.fs.stat(u); - setStateValue(PROJECT_DIR_URI_KEY, searchUri); - return; + if (!isNamespace(u.fsPath)) { + setStateValue(PROJECT_DIR_URI_KEY, searchUri); + return; + } } catch { } }