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 Jan 27, 2025
1 parent 4172593 commit ce2a926
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 11 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 @@ -149,6 +159,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 @@ -296,13 +296,13 @@ class ExperimentalCapabilities implements StaticFeature {
initialize(
_capabilities: ServerCapabilities,
_documentSelector: DocumentSelector | undefined,
): void {}
): void { }

Check failure on line 299 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 305 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 @@ -433,6 +433,14 @@ export default class Client extends LanguageClient implements ClientInterface {
});
}

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
3 changes: 2 additions & 1 deletion vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export enum Command {
StartServerInDebugMode = "rubyLsp.startServerInDebugMode",
ShowOutput = "rubyLsp.showOutput",
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
GotoRelevantFile = "rubyLsp.gotoRelevantFile",
}

export interface RubyInterface {
Expand Down Expand Up @@ -98,7 +99,7 @@ type FeatureFlagConfigurationKey = keyof typeof FEATURE_FLAGS | "all";
export function debounce(fn: (...args: any[]) => Promise<void>, delay: number) {
let timeoutID: NodeJS.Timeout | null = null;

return function (...args: any[]) {
return function(...args: any[]) {

Check failure on line 102 in vscode/src/common.ts

View workflow job for this annotation

GitHub Actions / lint_node

Insert `·`
if (timeoutID) {
clearTimeout(timeoutID);
}
Expand Down
30 changes: 22 additions & 8 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -547,14 +547,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 550 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

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

Check failure on line 551 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 552 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 553 in vscode/src/rubyLsp.ts

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
command: Command.NewMinitestFile,

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

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
args: [],

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

View workflow job for this annotation

GitHub Actions / lint_node

Delete `··`
},

Check failure on line 556 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 @@ -601,6 +601,20 @@ export class RubyLsp {
await workspace?.start(true);
},
),
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);
}
}),
);
vscode.commands.registerCommand(Command.ShowOutput, async () => {
LOG_CHANNEL.show();
Expand Down

0 comments on commit ce2a926

Please sign in to comment.