forked from jasonnutter/vscode-codeowners
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcodeowners-diagnostic-provider.ts
More file actions
49 lines (40 loc) · 1.27 KB
/
codeowners-diagnostic-provider.ts
File metadata and controls
49 lines (40 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import vscode from "vscode"
import { OwnershipEngine } from "@snyk/github-codeowners/dist/lib/ownership"
function updateDiagnostics(
document: vscode.TextDocument,
collection: vscode.DiagnosticCollection,
): void {
if (document.languageId !== "codeowners") {
return
}
const engine = OwnershipEngine.FromCodeownersFile(document.uri.fsPath)
const diagnostics = engine.errors.map((err) => {
const line = document.lineAt(err.lineno)
return new vscode.Diagnostic(line.range, err.message, vscode.DiagnosticSeverity.Error)
})
collection.set(document.uri, diagnostics)
}
export function registerCodeownersDiagnostics(
context: vscode.ExtensionContext,
): void {
const collection = vscode.languages.createDiagnosticCollection("codeowners")
context.subscriptions.push(collection)
vscode.workspace.textDocuments.forEach((doc) =>
updateDiagnostics(doc, collection),
)
vscode.workspace.onDidOpenTextDocument(
(doc) => updateDiagnostics(doc, collection),
null,
context.subscriptions,
)
vscode.workspace.onDidChangeTextDocument(
(e) => updateDiagnostics(e.document, collection),
null,
context.subscriptions,
)
vscode.workspace.onDidCloseTextDocument(
(doc) => collection.delete(doc.uri),
null,
context.subscriptions,
)
}