Skip to content

Commit

Permalink
Accept multiple URIs for the open file command (#2312)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock authored Jul 15, 2024
1 parent cbb0f01 commit c36e1d5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
27 changes: 27 additions & 0 deletions vscode/src/openFile.ts → vscode/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
10 changes: 8 additions & 2 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit c36e1d5

Please sign in to comment.