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

directories exclude support #39

Open
wants to merge 3 commits into
base: master
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
20 changes: 18 additions & 2 deletions src/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ export default class Linter {
}

let currentFile = this.codeDocument.uri.fsPath;
let currentDirectory = path.dirname(currentFile);
let startFolder = path.dirname(currentFile);
let wsRoot = getWorkspaceRootPath(currentFile)
if (wsRoot) {
startFolder = wsRoot;
}

let protoLintPath = vscode.workspace.getConfiguration('protolint').get<string>('path');
if (!protoLintPath) {
Expand All @@ -59,7 +63,7 @@ export default class Linter {
let lintResults: string = "";

await exec(cmd, {
cwd: currentDirectory
cwd: startFolder
}).catch((error: any) => lintResults = error.stderr);

return lintResults;
Expand All @@ -85,3 +89,15 @@ export default class Linter {
return result;
}
}

function getWorkspaceRootPath(filePath: string): string | undefined {
let workspaceFolders = vscode.workspace.workspaceFolders;
if (workspaceFolders) {
for (let folder of workspaceFolders) {
if (filePath.startsWith(folder.uri.fsPath)) {
return folder.uri.fsPath;
}
}
}
return undefined;
}