Skip to content

Commit

Permalink
Rename from goto to go_to
Browse files Browse the repository at this point in the history
  • Loading branch information
jenny-codes committed Mar 10, 2025
1 parent 8a39f82 commit 06e5b89
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 46 deletions.
2 changes: 1 addition & 1 deletion lib/ruby_lsp/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
require "ruby_lsp/requests/document_symbol"
require "ruby_lsp/requests/folding_ranges"
require "ruby_lsp/requests/formatting"
require "ruby_lsp/requests/goto_relevant_file"
require "ruby_lsp/requests/go_to_relevant_file"
require "ruby_lsp/requests/hover"
require "ruby_lsp/requests/inlay_hints"
require "ruby_lsp/requests/on_type_formatting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

module RubyLsp
module Requests
# Goto Relevant File is a custom [LSP
# GoTo Relevant File is a custom [LSP
# request](https://microsoft.github.io/language-server-protocol/specification#requestMessage)
# that navigates to the relevant file for the current document.
# Currently, it supports source code file <> test file navigation.
class GotoRelevantFile < Request
class GoToRelevantFile < Request
extend T::Sig

TEST_KEYWORDS = ["test", "spec", "integration_test"]
Expand Down
10 changes: 5 additions & 5 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ def process_message(message)
discover_tests(message)
when "rubyLsp/resolveTestCommands"
resolve_test_commands(message)
when "experimental/gotoRelevantFile"
experimental_goto_relevant_file(message)
when "experimental/goToRelevantFile"
experimental_go_to_relevant_file(message)
when "$/cancelRequest"
@global_state.synchronize { @cancelled_requests << message[:params][:id] }
when nil
Expand Down Expand Up @@ -293,7 +293,7 @@ def run_initialize(message)
experimental: {
addon_detection: true,
compose_bundle: true,
goto_relevant_file: true,
go_to_relevant_file: true,
},
),
serverInfo: {
Expand Down Expand Up @@ -1145,7 +1145,7 @@ def text_document_show_syntax_tree(message)
end

#: (Hash[Symbol, untyped] message) -> void
def experimental_goto_relevant_file(message)
def experimental_go_to_relevant_file(message)
path = message.dig(:params, :textDocument, :uri).to_standardized_path
unless path.nil? || path.start_with?(@global_state.workspace_path)
send_empty_response(message[:id])
Expand All @@ -1158,7 +1158,7 @@ def experimental_goto_relevant_file(message)
end

response = {
locations: Requests::GotoRelevantFile.new(path, @global_state.workspace_path).perform,
locations: Requests::GoToRelevantFile.new(path, @global_state.workspace_path).perform,
}
send_message(Result.new(id: message[:id], response: response))
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@

require "test_helper"

class GotoRelevantFileTest < Minitest::Test
class GoToRelevantFileTest < Minitest::Test
def test_when_input_is_test_file_returns_array_of_implementation_file_locations
stub_glob_pattern("**/goto_relevant_file.rb", ["lib/ruby_lsp/requests/goto_relevant_file.rb"])
stub_glob_pattern("**/go_to_relevant_file.rb", ["lib/ruby_lsp/requests/go_to_relevant_file.rb"])

test_file_path = "/workspace/test/requests/goto_relevant_file_test.rb"
expected = ["/workspace/lib/ruby_lsp/requests/goto_relevant_file.rb"]
test_file_path = "/workspace/test/requests/go_to_relevant_file_test.rb"
expected = ["/workspace/lib/ruby_lsp/requests/go_to_relevant_file.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_file_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_file_path, "/workspace").perform
assert_equal(expected, result)
end

def test_when_input_is_implementation_file_returns_array_of_test_file_locations
pattern =
"**/{{test_,spec_,integration_test_}goto_relevant_file,goto_relevant_file{_test,_spec,_integration_test}}.rb"
stub_glob_pattern(pattern, ["test/requests/goto_relevant_file_test.rb"])
"**/{{test_,spec_,integration_test_}go_to_relevant_file,go_to_relevant_file{_test,_spec,_integration_test}}.rb"
stub_glob_pattern(pattern, ["test/requests/go_to_relevant_file_test.rb"])

impl_path = "/workspace/lib/ruby_lsp/requests/goto_relevant_file.rb"
expected = ["/workspace/test/requests/goto_relevant_file_test.rb"]
impl_path = "/workspace/lib/ruby_lsp/requests/go_to_relevant_file.rb"
expected = ["/workspace/test/requests/go_to_relevant_file_test.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(impl_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(impl_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -40,7 +40,7 @@ def test_return_all_file_locations_that_have_the_same_highest_coefficient
"/workspace/test/integration/some_feature_test.rb",
]

result = RubyLsp::Requests::GotoRelevantFile.new(impl_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(impl_path, "/workspace").perform
assert_equal(expected.sort, result.sort)
end

Expand All @@ -49,7 +49,7 @@ def test_return_empty_array_when_no_filename_matches
stub_glob_pattern(pattern, [])

file_path = "/workspace/lib/ruby_lsp/requests/nonexistent_file.rb"
result = RubyLsp::Requests::GotoRelevantFile.new(file_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(file_path, "/workspace").perform
assert_empty(result)
end

Expand All @@ -59,7 +59,7 @@ def test_it_finds_implementation_when_file_has_test_suffix
test_path = "/workspace/test/feature_test.rb"
expected = ["/workspace/lib/feature.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -69,7 +69,7 @@ def test_it_finds_implementation_when_file_has_spec_suffix
test_path = "/workspace/spec/feature_spec.rb"
expected = ["/workspace/lib/feature.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -79,7 +79,7 @@ def test_it_finds_implementation_when_file_has_integration_test_suffix
test_path = "/workspace/test/feature_integration_test.rb"
expected = ["/workspace/lib/feature.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -89,7 +89,7 @@ def test_it_finds_implementation_when_file_has_test_prefix
test_path = "/workspace/test/test_feature.rb"
expected = ["/workspace/lib/feature.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -99,7 +99,7 @@ def test_it_finds_implementation_when_file_has_spec_prefix
test_path = "/workspace/test/spec_feature.rb"
expected = ["/workspace/lib/feature.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -109,7 +109,7 @@ def test_it_finds_implementation_when_file_has_integration_test_prefix
test_path = "/workspace/test/integration_test_feature.rb"
expected = ["/workspace/lib/feature.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(test_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(test_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -120,7 +120,7 @@ def test_it_finds_tests_for_implementation
impl_path = "/workspace/lib/feature.rb"
expected = ["/workspace/test/feature_test.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(impl_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(impl_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -131,7 +131,7 @@ def test_it_finds_specs_for_implementation
impl_path = "/workspace/lib/feature.rb"
expected = ["/workspace/spec/feature_spec.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(impl_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(impl_path, "/workspace").perform
assert_equal(expected, result)
end

Expand All @@ -142,7 +142,7 @@ def test_it_finds_integration_tests_for_implementation
impl_path = "/workspace/lib/feature.rb"
expected = ["/workspace/test/feature_integration_test.rb"]

result = RubyLsp::Requests::GotoRelevantFile.new(impl_path, "/workspace").perform
result = RubyLsp::Requests::GoToRelevantFile.new(impl_path, "/workspace").perform
assert_equal(expected, result)
end

Expand Down
10 changes: 5 additions & 5 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"group": "navigation"
},
{
"command": "rubyLsp.gotoRelevantFile",
"command": "rubyLsp.goToRelevantFile",
"when": "rubyLsp.activated && view == 'workbench.explorer.fileView'",
"group": "navigation"
}
Expand All @@ -73,7 +73,7 @@
"group": "2_workspace"
},
{
"command": "rubyLsp.gotoRelevantFile",
"command": "rubyLsp.goToRelevantFile",
"when": "rubyLsp.activated",
"group": "2_workspace"
}
Expand Down Expand Up @@ -170,8 +170,8 @@
"icon": "$(ruby)"
},
{
"command": "rubyLsp.gotoRelevantFile",
"title": "Goto relevant file (test <> source code)",
"command": "rubyLsp.goToRelevantFile",
"title": "GoTo relevant file (test <> source code)",
"category": "Ruby LSP"
},
{
Expand Down Expand Up @@ -816,4 +816,4 @@
"dependencies": {
"vscode-languageclient": "^9.0.1"
}
}
}
4 changes: 2 additions & 2 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,10 @@ export default class Client extends LanguageClient implements ClientInterface {
return super.dispose(timeout);
}

async sendGotoRelevantFileRequest(
async sendGoToRelevantFileRequest(
uri: vscode.Uri,
): Promise<{ locations: string[] } | null> {
return this.sendRequest("experimental/gotoRelevantFile", {
return this.sendRequest("experimental/goToRelevantFile", {
textDocument: { uri: uri.toString() },
});
}
Expand Down
2 changes: 1 addition & 1 deletion vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export enum Command {
StartServerInDebugMode = "rubyLsp.startServerInDebugMode",
ShowOutput = "rubyLsp.showOutput",
MigrateLaunchConfiguration = "rubyLsp.migrateLaunchConfiguration",
GotoRelevantFile = "rubyLsp.gotoRelevantFile",
GoToRelevantFile = "rubyLsp.goToRelevantFile",
}

export interface RubyInterface {
Expand Down
4 changes: 2 additions & 2 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -705,13 +705,13 @@ export class RubyLsp {
);
},
),
vscode.commands.registerCommand(Command.GotoRelevantFile, async () => {
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(
await this.currentActiveWorkspace()?.lspClient?.sendGoToRelevantFileRequest(
uri,
);

Expand Down
14 changes: 7 additions & 7 deletions vscode/src/test/suite/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -994,20 +994,20 @@ suite("Client", () => {
workspaceUri,
"test",
"requests",
"goto_relevant_file_test.rb",
"go_to_relevant_file_test.rb",
);
implUri = vscode.Uri.joinPath(
workspaceUri,
"lib",
"ruby_lsp",
"requests",
"goto_relevant_file.rb",
"go_to_relevant_file.rb",
);
});

test("for test file", async () => {
const response: { locations: string[] } = await client.sendRequest(
"experimental/gotoRelevantFile",
"experimental/goToRelevantFile",
{
textDocument: {
uri: testUri.toString(),
Expand All @@ -1018,13 +1018,13 @@ suite("Client", () => {
assert.ok(response.locations.length === 1);
assert.match(
response.locations[0],
/lib\/ruby_lsp\/requests\/goto_relevant_file\.rb$/,
/lib\/ruby_lsp\/requests\/go_to_relevant_file\.rb$/,
);
}).timeout(20000);

test("for implementation file", async () => {
const response: { locations: string[] } = await client.sendRequest(
"experimental/gotoRelevantFile",
"experimental/goToRelevantFile",
{
textDocument: {
uri: implUri.toString(),
Expand All @@ -1035,15 +1035,15 @@ suite("Client", () => {
assert.ok(response.locations.length === 1);
assert.match(
response.locations[0],
/test\/requests\/goto_relevant_file_test\.rb$/,
/test\/requests\/go_to_relevant_file_test\.rb$/,
);
}).timeout(20000);

test("returns empty array for invalid file", async () => {
const uri = vscode.Uri.joinPath(workspaceUri, "nonexistent", "file.rb");

const response: { locations: string[] } = await client.sendRequest(
"experimental/gotoRelevantFile",
"experimental/goToRelevantFile",
{
textDocument: {
uri: uri.toString(),
Expand Down

0 comments on commit 06e5b89

Please sign in to comment.