Skip to content

Commit

Permalink
Add vscode support for gotoRelevantFile
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-codes committed Feb 19, 2025
1 parent e0acffc commit 02e94b1
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
15 changes: 15 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,23 @@
"command": "rubyLsp.fileOperation",
"when": "rubyLsp.activated && view == 'workbench.explorer.fileView'",
"group": "navigation"
},
{
"command": "rubyLsp.gotoRelevantFile",
"when": "rubyLsp.activated && view == 'workbench.explorer.fileView'",
"group": "navigation"
}
],
"explorer/context": [
{
"command": "rubyLsp.fileOperation",
"when": "rubyLsp.activated",
"group": "2_workspace"
},
{
"command": "rubyLsp.gotoRelevantFile",
"when": "rubyLsp.activated",
"group": "2_workspace"
}
]
},
Expand Down Expand Up @@ -159,6 +169,11 @@
"category": "Ruby LSP",
"icon": "$(ruby)"
},
{
"command": "rubyLsp.gotoRelevantFile",
"title": "Goto relevant file (test <> source code)",
"category": "Ruby LSP"
},
{
"command": "rubyLsp.collectRubyLspInfo",
"title": "Collect Ruby LSP information for issue reporting",
Expand Down
8 changes: 8 additions & 0 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,14 @@ export default class Client extends LanguageClient implements ClientInterface {
return super.dispose(timeout);
}

async sendGotoRelevantFileRequest(
uri: vscode.Uri,
): Promise<{ locations: string[] } | null> {
return this.sendRequest("experimental/gotoRelevantFile", {
textDocument: { uri: uri.toString() },
});
}

private async benchmarkMiddleware<T>(
type: string | MessageSignature,
params: any,
Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export enum Command {
StartServerInDebugMode = "rubyLsp.startServerInDebugMode",
ShowOutput = "rubyLsp.showOutput",
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
GotoRelevantFile = "rubyLsp.gotoRelevantFile",
}

export interface RubyInterface {
Expand Down
14 changes: 14 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,20 @@ export class RubyLsp {
);
},
),
vscode.commands.registerCommand(Command.GotoRelevantFile, async () => {
const uri = vscode.window.activeTextEditor?.document.uri;
if (!uri) {
return;
}
const response: { locations: string[] } | null | undefined =
await this.currentActiveWorkspace()?.lspClient?.sendGotoRelevantFileRequest(
uri,
);

if (response) {
return openUris(response.locations);
}
}),
];
}

Expand Down
66 changes: 65 additions & 1 deletion vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
ShowMessageParams,
MessageType,
} from "vscode-languageclient/node";
import { after, afterEach, before } from "mocha";
import { after, afterEach, before, setup } from "mocha";

import { Ruby, ManagerIdentifier } from "../../ruby";
import Client from "../../client";
Expand Down Expand Up @@ -997,4 +997,68 @@ suite("Client", () => {

assert.ok(response.length > 0);
}).timeout(20000);

suite("goto relevant file", () => {
let testUri: vscode.Uri;
let implUri: vscode.Uri;

setup(() => {
testUri = vscode.Uri.joinPath(
workspaceUri,
"test",
"requests",
"goto_relevant_file_test.rb",
);
implUri = vscode.Uri.joinPath(
workspaceUri,
"lib",
"ruby_lsp",
"requests",
"goto_relevant_file.rb",
);
});

test("for test file", async () => {
const response: { locations: string[] } = await client.sendRequest(
"experimental/gotoRelevantFile",
{
textDocument: {
uri: testUri.toString(),
},
},
);

assert.ok(response.locations.length === 1);
assert.match(response.locations[0], /lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/);

Check failure on line 1032 in vscode/src/test/suite/client.test.ts

View workflow job for this annotation

GitHub Actions / lint_node

Replace `response.locations[0],·/lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/` with `⏎········response.locations[0],⏎········/lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/,⏎······`

Check failure on line 1032 in vscode/src/test/suite/client.test.ts

View workflow job for this annotation

GitHub Actions / lint_node

Replace `response.locations[0],·/lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/` with `⏎········response.locations[0],⏎········/lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/,⏎······`
});

test("for implementation file", async () => {
const response: { locations: string[] } = await client.sendRequest(
"experimental/gotoRelevantFile",
{
textDocument: {
uri: implUri.toString(),
},
},
);

assert.ok(response.locations.length === 1);
assert.match(response.locations[0], /test\/requests\/goto_relevant_file_test\.rb$/);

Check failure on line 1046 in vscode/src/test/suite/client.test.ts

View workflow job for this annotation

GitHub Actions / lint_node

Replace `response.locations[0],·/test\/requests\/goto_relevant_file_test\.rb$/` with `⏎········response.locations[0],⏎········/test\/requests\/goto_relevant_file_test\.rb$/,⏎······`

Check failure on line 1046 in vscode/src/test/suite/client.test.ts

View workflow job for this annotation

GitHub Actions / lint_node

Replace `response.locations[0],·/test\/requests\/goto_relevant_file_test\.rb$/` with `⏎········response.locations[0],⏎········/test\/requests\/goto_relevant_file_test\.rb$/,⏎······`
});

test("returns empty array for invalid file", async () => {
const uri = vscode.Uri.joinPath(workspaceUri, "nonexistent", "file.rb");

const response: { locations: string[] } = await client.sendRequest(
"experimental/gotoRelevantFile",
{
textDocument: {
uri: uri.toString(),
},
},
);

assert.deepStrictEqual(response, { locations: [] });
});
});
});

0 comments on commit 02e94b1

Please sign in to comment.