Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve leiningen project search #1403

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/state.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -140,14 +141,20 @@ export async function initProjectDir(uri?: vscode.Uri): Promise<void> {
}
}

async function findLocalProjectRoot(projectFileNames, doc, workspaceFolder): Promise<void> {
function isNamespace(path: string): boolean {
const content = filesCache.content(path);
const hasNsDecl = /^\(ns /.test(content);
return hasNsDecl;
}
Comment on lines +144 to +148
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit brittle. People have white space and comments and whatever before the ns form. I think that if we refactor out a version of src/namespace.ts:getNameSpace() that takes a string as its argument, that'll be more safer and more battle tested. I can help with this if you like. I think I might have created a thing that can be used in the mega-parinfer PR:

export class StringDocument implements EditableDocument {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And no that PR is merged!


async function findLocalProjectRoot(projectFileNames: string[], doc: vscode.TextDocument, workspaceFolder: vscode.WorkspaceFolder): Promise<void> {
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 {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 { }
}
Expand Down