Skip to content
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;
}