-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathactionVersionHoverProvider.ts
More file actions
48 lines (38 loc) · 1.52 KB
/
actionVersionHoverProvider.ts
File metadata and controls
48 lines (38 loc) · 1.52 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
import * as vscode from "vscode";
import {parseUsesReference, fetchLatestVersion} from "./actionVersionUtils";
export class ActionVersionHoverProvider implements vscode.HoverProvider {
async provideHover(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken
): Promise<vscode.Hover | undefined> {
const line = document.lineAt(position).text;
const ref = parseUsesReference(line);
if (!ref) {
return undefined;
}
// Ensure cursor is within the action reference range
if (position.character < ref.valueStart || position.character > ref.valueEnd) {
return undefined;
}
if (token.isCancellationRequested) {
return undefined;
}
const versionInfo = await fetchLatestVersion(ref.owner, ref.name);
if (!versionInfo || token.isCancellationRequested) {
return undefined;
}
const md = new vscode.MarkdownString();
const isCurrentLatest = ref.currentRef === versionInfo.latest || ref.currentRef === versionInfo.latestMajor;
if (isCurrentLatest) {
md.appendMarkdown(`**Latest version:** \`${versionInfo.latest}\` ✓`);
} else {
md.appendMarkdown(`**Latest version:** \`${versionInfo.latest}\``);
if (versionInfo.latestMajor && ref.currentRef !== versionInfo.latestMajor) {
md.appendMarkdown(` (major: \`${versionInfo.latestMajor}\`)`);
}
}
const range = new vscode.Range(position.line, ref.valueStart, position.line, ref.valueEnd);
return new vscode.Hover(md, range);
}
}