From c8262b6e5cb192fd6aee3999419a59ba499ab1a0 Mon Sep 17 00:00:00 2001 From: Roman Nikulenkov Date: Fri, 26 Jan 2024 20:18:13 +0300 Subject: [PATCH 1/3] directories exclude support --- src/linter.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/linter.ts b/src/linter.ts index 35a2c51..f1197b1 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -42,7 +42,7 @@ export default class Linter { } let currentFile = this.codeDocument.uri.fsPath; - let currentDirectory = path.dirname(currentFile); + let wsRoot = vscode.workspace.workspaceFolders[0].uri.path let protoLintPath = vscode.workspace.getConfiguration('protolint').get('path'); if (!protoLintPath) { @@ -59,7 +59,7 @@ export default class Linter { let lintResults: string = ""; await exec(cmd, { - cwd: currentDirectory + cwd: wsRoot }).catch((error: any) => lintResults = error.stderr); return lintResults; From 52df81f959147379bd233385ef0f18c3e2bc6026 Mon Sep 17 00:00:00 2001 From: Roman Nikulenkov Date: Fri, 26 Jan 2024 20:56:55 +0300 Subject: [PATCH 2/3] directories exclude support --- src/linter.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/linter.ts b/src/linter.ts index f1197b1..615ddba 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -1,7 +1,6 @@ import * as cp from 'child_process'; import * as vscode from 'vscode'; import * as util from 'util'; -import * as path from 'path'; import { ProtoError, parseProtoError } from './protoError'; From 870636a8502a7b9ff3b8c43060f1a4c795af007b Mon Sep 17 00:00:00 2001 From: Roman Nikulenkov Date: Sat, 27 Jan 2024 22:24:44 +0300 Subject: [PATCH 3/3] fix multiroot workspaces --- src/linter.ts | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/linter.ts b/src/linter.ts index 615ddba..5fb7af6 100644 --- a/src/linter.ts +++ b/src/linter.ts @@ -1,6 +1,7 @@ import * as cp from 'child_process'; import * as vscode from 'vscode'; import * as util from 'util'; +import * as path from 'path'; import { ProtoError, parseProtoError } from './protoError'; @@ -41,7 +42,11 @@ export default class Linter { } let currentFile = this.codeDocument.uri.fsPath; - let wsRoot = vscode.workspace.workspaceFolders[0].uri.path + let startFolder = path.dirname(currentFile); + let wsRoot = getWorkspaceRootPath(currentFile) + if (wsRoot) { + startFolder = wsRoot; + } let protoLintPath = vscode.workspace.getConfiguration('protolint').get('path'); if (!protoLintPath) { @@ -58,7 +63,7 @@ export default class Linter { let lintResults: string = ""; await exec(cmd, { - cwd: wsRoot + cwd: startFolder }).catch((error: any) => lintResults = error.stderr); return lintResults; @@ -84,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; +} \ No newline at end of file