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

Add file open support for route lookup #2232

Merged
merged 1 commit into from
Jul 8, 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
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export enum Command {
DisplayAddons = "rubyLsp.displayAddons",
RunTask = "rubyLsp.runTask",
BundleInstall = "rubyLsp.bundleInstall",
OpenFile = "rubyLsp.openFile",
}

export interface RubyInterface {
Expand Down
38 changes: 38 additions & 0 deletions vscode/src/openFile.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import * as vscode from "vscode";

import { Telemetry } from "./telemetry";
import { Workspace } from "./workspace";

interface SourceLocation {
file: string;
line: number;
character?: number;
endLine?: number;
endCharacter?: number;
}

export async function openFile(
telemetry: Telemetry,
workspace: Workspace | undefined,
sourceLocation: SourceLocation,
) {
const { file, ...location } = sourceLocation;
const {
line,
character = 0,
endLine = line,
endCharacter = character,
} = location;
const selection = new vscode.Range(line, character, endLine, endCharacter);
const uri = vscode.Uri.parse(`file://${file}`);
const doc = await vscode.workspace.openTextDocument(uri);

await vscode.window.showTextDocument(doc, { selection });

if (workspace?.lspClient?.serverVersion) {
await telemetry.sendCodeLensEvent(
"open_file",
workspace.lspClient.serverVersion,
);
}
}
12 changes: 12 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Command, STATUS_EMITTER } from "./common";
import { ManagerIdentifier, ManagerConfiguration } from "./ruby";
import { StatusItems } from "./status";
import { TestController } from "./testController";
import { openFile } from "./openFile";
import { Debugger } from "./debugger";
import { DependenciesTree } from "./dependenciesTree";

Expand Down Expand Up @@ -413,6 +414,17 @@ export class RubyLsp {
terminal.sendText("bundle install");
},
),
vscode.commands.registerCommand(
Command.OpenFile,
(rubySourceLocation: [string, string]) => {
const [file, line] = rubySourceLocation;
const workspace = this.currentActiveWorkspace();
return openFile(this.telemetry, workspace, {
file,
line: parseInt(line, 10) - 1,
});
},
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion vscode/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export interface ConfigurationEvent {
}

export interface CodeLensEvent {
type: "test" | "debug" | "test_in_terminal";
type: "test" | "debug" | "test_in_terminal" | "open_file";
lspVersion: string;
}

Expand Down
Loading