Skip to content

Commit e23d525

Browse files
committed
Add vscode support for gotoRelevantFile
1 parent e0acffc commit e23d525

File tree

5 files changed

+109
-1
lines changed

5 files changed

+109
-1
lines changed

vscode/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,23 @@
5959
"command": "rubyLsp.fileOperation",
6060
"when": "rubyLsp.activated && view == 'workbench.explorer.fileView'",
6161
"group": "navigation"
62+
},
63+
{
64+
"command": "rubyLsp.gotoRelevantFile",
65+
"when": "rubyLsp.activated && view == 'workbench.explorer.fileView'",
66+
"group": "navigation"
6267
}
6368
],
6469
"explorer/context": [
6570
{
6671
"command": "rubyLsp.fileOperation",
6772
"when": "rubyLsp.activated",
6873
"group": "2_workspace"
74+
},
75+
{
76+
"command": "rubyLsp.gotoRelevantFile",
77+
"when": "rubyLsp.activated",
78+
"group": "2_workspace"
6979
}
7080
]
7181
},
@@ -159,6 +169,11 @@
159169
"category": "Ruby LSP",
160170
"icon": "$(ruby)"
161171
},
172+
{
173+
"command": "rubyLsp.gotoRelevantFile",
174+
"title": "Goto relevant file (test <> source code)",
175+
"category": "Ruby LSP"
176+
},
162177
{
163178
"command": "rubyLsp.collectRubyLspInfo",
164179
"title": "Collect Ruby LSP information for issue reporting",

vscode/src/client.ts

+8
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,14 @@ export default class Client extends LanguageClient implements ClientInterface {
482482
return super.dispose(timeout);
483483
}
484484

485+
async sendGotoRelevantFileRequest(
486+
uri: vscode.Uri,
487+
): Promise<{ locations: string[] } | null> {
488+
return this.sendRequest("experimental/gotoRelevantFile", {
489+
textDocument: { uri: uri.toString() },
490+
});
491+
}
492+
485493
private async benchmarkMiddleware<T>(
486494
type: string | MessageSignature,
487495
params: any,

vscode/src/common.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export enum Command {
3333
StartServerInDebugMode = "rubyLsp.startServerInDebugMode",
3434
ShowOutput = "rubyLsp.showOutput",
3535
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
36+
GotoRelevantFile = "rubyLsp.gotoRelevantFile",
3637
}
3738

3839
export interface RubyInterface {

vscode/src/rubyLsp.ts

+14
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,20 @@ export class RubyLsp {
693693
);
694694
},
695695
),
696+
vscode.commands.registerCommand(Command.GotoRelevantFile, async () => {
697+
const uri = vscode.window.activeTextEditor?.document.uri;
698+
if (!uri) {
699+
return;
700+
}
701+
const response: { locations: string[] } | null | undefined =
702+
await this.currentActiveWorkspace()?.lspClient?.sendGotoRelevantFileRequest(
703+
uri,
704+
);
705+
706+
if (response) {
707+
return openUris(response.locations);
708+
}
709+
}),
696710
];
697711
}
698712

vscode/src/test/suite/client.test.ts

+71-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
ShowMessageParams,
2727
MessageType,
2828
} from "vscode-languageclient/node";
29-
import { after, afterEach, before } from "mocha";
29+
import { after, afterEach, before, setup } from "mocha";
3030

3131
import { Ruby, ManagerIdentifier } from "../../ruby";
3232
import Client from "../../client";
@@ -997,4 +997,74 @@ suite("Client", () => {
997997

998998
assert.ok(response.length > 0);
999999
}).timeout(20000);
1000+
1001+
suite("goto relevant file", () => {
1002+
let testUri: vscode.Uri;
1003+
let implUri: vscode.Uri;
1004+
1005+
setup(() => {
1006+
testUri = vscode.Uri.joinPath(
1007+
workspaceUri,
1008+
"test",
1009+
"requests",
1010+
"goto_relevant_file_test.rb",
1011+
);
1012+
implUri = vscode.Uri.joinPath(
1013+
workspaceUri,
1014+
"lib",
1015+
"ruby_lsp",
1016+
"requests",
1017+
"goto_relevant_file.rb",
1018+
);
1019+
});
1020+
1021+
test("for test file", async () => {
1022+
const response: { locations: string[] } = await client.sendRequest(
1023+
"experimental/gotoRelevantFile",
1024+
{
1025+
textDocument: {
1026+
uri: testUri.toString(),
1027+
},
1028+
},
1029+
);
1030+
1031+
assert.ok(response.locations.length === 1);
1032+
assert.match(
1033+
response.locations[0],
1034+
/lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/,
1035+
);
1036+
}).timeout(20000);
1037+
1038+
test("for implementation file", async () => {
1039+
const response: { locations: string[] } = await client.sendRequest(
1040+
"experimental/gotoRelevantFile",
1041+
{
1042+
textDocument: {
1043+
uri: implUri.toString(),
1044+
},
1045+
},
1046+
);
1047+
1048+
assert.ok(response.locations.length === 1);
1049+
assert.match(
1050+
response.locations[0],
1051+
/test\/requests\/goto_relevant_file_test\.rb$/,
1052+
);
1053+
}).timeout(20000);
1054+
1055+
test("returns empty array for invalid file", async () => {
1056+
const uri = vscode.Uri.joinPath(workspaceUri, "nonexistent", "file.rb");
1057+
1058+
const response: { locations: string[] } = await client.sendRequest(
1059+
"experimental/gotoRelevantFile",
1060+
{
1061+
textDocument: {
1062+
uri: uri.toString(),
1063+
},
1064+
},
1065+
);
1066+
1067+
assert.deepStrictEqual(response, { locations: [] });
1068+
}).timeout(20000);
1069+
});
10001070
});

0 commit comments

Comments
 (0)