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 22, 2025
1 parent 4bf4ae4 commit da1a48d
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 13 deletions.
19 changes: 17 additions & 2 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@
"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"
},
]
},
"commands": [
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 { }

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

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

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[]) {
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: [],
},
];
{
label: "Minitest test",
description: "Create a new Minitest test",
iconPath: new vscode.ThemeIcon("new-file"),
command: Command.NewMinitestFile,
args: [],
},
];

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 da1a48d

Please sign in to comment.