Skip to content

Commit 38c5660

Browse files
committed
Basic Version of CodeLense
1 parent e97db65 commit 38c5660

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/stringRessources/commands.ts

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export class CommandStrings {
88
public static CompileAndRun: string = "dafny.compileAndRun";
99
public static ShowCounterExample: string = "dafny.showCounterExample";
1010
public static HideCounterExample: string = "dafny.hideCounterExample";
11+
public static ShowReferences: string = "dafny.showReferences";
1112
}
1213

1314
export class Config {

src/ui/commands.ts

+43
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,45 @@ export default class Commands {
1919
private provider: DafnyUiManager;
2020
private runner: DafnyRunner;
2121

22+
// todo move this function
23+
public static showReferences(jsonArgs: string) {
24+
// todo rm any
25+
function parsePosition(p: any): vscode.Position {
26+
return new vscode.Position(p.Line, p.Character);
27+
}
28+
function parseRange(r: any): vscode.Range {
29+
return new vscode.Range(parsePosition(r.Start), parsePosition(r.End));
30+
}
31+
function parseLocation(l: any): vscode.Location {
32+
return new vscode.Location(parseUri(l.Uri), parseRange(l.Range));
33+
}
34+
function parseUri(u: any): vscode.Uri {
35+
return vscode.Uri.parse(u);
36+
}
37+
38+
let obj;
39+
try {
40+
obj = JSON.parse(jsonArgs);
41+
} catch (e) {
42+
// todo show error msg
43+
}
44+
45+
const parsedUri: vscode.Uri = parseUri(obj.Uri);
46+
const parsedPosition: vscode.Position = parsePosition(obj.Position);
47+
const parsedLocations: Array<vscode.Location> = [];
48+
49+
for (const location of obj.Locations) {
50+
parsedLocations.push(parseLocation(location));
51+
}
52+
53+
vscode.commands.executeCommand(
54+
"editor.action.showReferences",
55+
parsedUri,
56+
parsedPosition,
57+
parsedLocations
58+
);
59+
}
60+
2261
private commands = [
2362
{
2463
name: CommandStrings.Compile,
@@ -47,6 +86,10 @@ export default class Commands {
4786
callback: () =>
4887
this.provider.getCounterModelProvider().hideCounterModel(),
4988
},
89+
{
90+
name: CommandStrings.ShowReferences,
91+
callback: Commands.showReferences,
92+
},
5093
/* Please note that the command "RestartServer" is registered in dafnyLanguageServer for a higher cohesion */
5194

5295
{

0 commit comments

Comments
 (0)