Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept multiple URIs for the open file command #2312

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading