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 30962b6 commit 9b39633
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 18 deletions.
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
12 changes: 10 additions & 2 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ class ExperimentalCapabilities implements StaticFeature {
initialize(
_capabilities: ServerCapabilities,
_documentSelector: DocumentSelector | undefined,
): void {}
): void { }

Check failure on line 328 in vscode/src/client.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `·`

Check failure on line 328 in vscode/src/client.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `·`

getState(): FeatureState {
return { kind: "static" };
}

clear(): void {}
clear(): void { }

Check failure on line 334 in vscode/src/client.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `·`

Check failure on line 334 in vscode/src/client.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `·`
}

export default class Client extends LanguageClient implements ClientInterface {
Expand Down 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
44 changes: 29 additions & 15 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,14 @@ export class RubyLsp {
command: string;
args: any[];
} & vscode.QuickPickItem)[] = [
{
label: "Minitest test",
description: "Create a new Minitest test",
iconPath: new vscode.ThemeIcon("new-file"),
command: Command.NewMinitestFile,
args: [],
},
];
{

Check failure on line 577 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 577 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
label: "Minitest test",

Check failure on line 578 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 578 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
description: "Create a new Minitest test",

Check failure on line 579 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 579 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
iconPath: new vscode.ThemeIcon("new-file"),

Check failure on line 580 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 580 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
command: Command.NewMinitestFile,

Check failure on line 581 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 581 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
args: [],

Check failure on line 582 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 582 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
},

Check failure on line 583 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 583 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
];

Check failure on line 584 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

Check failure on line 584 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`

if (
workspace.lspClient?.addons?.some(
Expand Down 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 Expand Up @@ -788,15 +802,15 @@ export class RubyLsp {

const response:
| {
workerAlive: boolean;
backtrace: string[];
documents: { uri: string; source: string };
incomingQueueSize: number;
}
workerAlive: boolean;
backtrace: string[];
documents: { uri: string; source: string };
incomingQueueSize: number;
}
| null
| undefined = await workspace?.lspClient?.sendRequest(
"rubyLsp/diagnoseState",
);
"rubyLsp/diagnoseState",
);

if (response) {
const documentData = Object.entries(response.documents);
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$/);
});

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$/);
});

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 9b39633

Please sign in to comment.