From 4d4147ae42b12a6b4e855dd27e93e8f2fd4bf2af Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 15 Jul 2024 16:29:23 -0400 Subject: [PATCH] Accept multiple URIs for the open file command --- vscode/src/{openFile.ts => commands.ts} | 27 +++++++++++++++++++++++++ vscode/src/rubyLsp.ts | 10 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) rename vscode/src/{openFile.ts => commands.ts} (59%) diff --git a/vscode/src/openFile.ts b/vscode/src/commands.ts similarity index 59% rename from vscode/src/openFile.ts rename to vscode/src/commands.ts index 800798827..5f8bf1fb2 100644 --- a/vscode/src/openFile.ts +++ b/vscode/src/commands.ts @@ -38,3 +38,30 @@ export async function openFile( }); } } + +// Open the given URIs in the editor, which should follow this format: +// `file:///path/to/file.rb#Lstart_line,start_column-end_line,end_column` +export async function openUris(uris: string[]) { + if (uris.length === 1) { + await vscode.commands.executeCommand( + "vscode.open", + vscode.Uri.parse(uris[0]), + ); + return; + } + + const items: ({ uri: vscode.Uri } & vscode.QuickPickItem)[] = uris.map( + (uri) => ({ + label: uri, + uri: vscode.Uri.parse(uri), + }), + ); + + const pickedFile = await vscode.window.showQuickPick(items); + + if (!pickedFile) { + return; + } + + await vscode.commands.executeCommand("vscode.open", pickedFile.label); +} diff --git a/vscode/src/rubyLsp.ts b/vscode/src/rubyLsp.ts index c53d3fa28..e2bb8fd5f 100644 --- a/vscode/src/rubyLsp.ts +++ b/vscode/src/rubyLsp.ts @@ -12,7 +12,7 @@ import { import { ManagerIdentifier, ManagerConfiguration } from "./ruby"; import { StatusItems } from "./status"; import { TestController } from "./testController"; -import { openFile } from "./openFile"; +import { openFile, openUris } from "./commands"; import { Debugger } from "./debugger"; import { DependenciesTree } from "./dependenciesTree"; @@ -444,7 +444,13 @@ export class RubyLsp { ), vscode.commands.registerCommand( Command.OpenFile, - (rubySourceLocation: [string, string]) => { + (rubySourceLocation: [string, string] | string[]) => { + // New command format: accepts an array of URIs + if (typeof rubySourceLocation[0] === "string") { + return openUris(rubySourceLocation); + } + + // Old format: we can remove after the Rails addon has been using the new format for a while const [file, line] = rubySourceLocation; const workspace = this.currentActiveWorkspace(); return openFile(this.telemetry, workspace, {