forked from jasonnutter/vscode-codeowners
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcodeowners-hover-provider.ts
More file actions
55 lines (47 loc) · 1.46 KB
/
codeowners-hover-provider.ts
File metadata and controls
55 lines (47 loc) · 1.46 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
50
51
52
53
54
55
import vscode from "vscode"
export class CodeownersHoverProvider implements vscode.HoverProvider {
provideHover(
document: vscode.TextDocument,
position: vscode.Position,
): vscode.ProviderResult<vscode.Hover> {
const line = document.lineAt(position.line)
const m = line.text.match(/^\s*(\S+)/)?.[1]
if (m == null) {
return { contents: [] }
}
const idx = line.text.indexOf(m)
const x = new vscode.MarkdownString()
x.appendCodeblock(m)
const hasLeadingSlash = m.startsWith("/")
const hasTrailingSlash = m.endsWith("/")
const hasTrailingGlob = m.endsWith("/*")
const range = new vscode.Range(
new vscode.Position(position.line, idx),
new vscode.Position(position.line, idx + m.length),
)
if (!range.contains(position)) {
return { contents: [] }
}
const lines: string[] = []
if (hasLeadingSlash) {
lines.push("**Anchored to repo root** — only matches at the top level")
} else {
lines.push(
"**Matches at any depth** — applies to this path anywhere in the repository)",
)
}
if (hasTrailingGlob) {
lines.push(
"**Shallow match** — covers only direct children, not subdirectories",
)
} else if (hasTrailingSlash) {
lines.push(
"**Recursive directory match** — covers the directory and all its contents at any depth",
)
}
return {
range,
contents: [x, lines.join("\n\n")],
}
}
}