-
-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_typeDefinition All the necessary pieces were in place, nothing fancy changed, mostly just exposing the functionality for LanguageServer. The only "functionality" added is `ComplexType#namespaces` which also utilizes existing implementation.
- Loading branch information
Showing
15 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
lib/solargraph/language_server/message/text_document/type_definition.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
|
||
module Solargraph::LanguageServer::Message::TextDocument | ||
class TypeDefinition < Base | ||
def process | ||
@line = params['position']['line'] | ||
@column = params['position']['character'] | ||
set_result(code_location || []) | ||
end | ||
|
||
private | ||
|
||
def code_location | ||
suggestions = host.type_definitions_at(params['textDocument']['uri'], @line, @column) | ||
return nil if suggestions.empty? | ||
suggestions.reject { |pin| pin.location.nil? || pin.location.filename.nil? }.map do |pin| | ||
{ | ||
uri: file_to_uri(pin.location.filename), | ||
range: pin.location.range.to_hash | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Something | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
class Thing | ||
def do_thing | ||
end | ||
# @return [Something] | ||
def do_thing; end | ||
end |
23 changes: 23 additions & 0 deletions
23
spec/language_server/message/text_document/type_definition_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
describe Solargraph::LanguageServer::Message::TextDocument::TypeDefinition do | ||
it 'finds definitions of methods' do | ||
host = Solargraph::LanguageServer::Host.new | ||
host.prepare('spec/fixtures/workspace') | ||
sleep 0.1 until host.libraries.all?(&:mapped?) | ||
host.catalog | ||
file_uri = Solargraph::LanguageServer::UriHelpers.file_to_uri(File.absolute_path('spec/fixtures/workspace/lib/other.rb')) | ||
something_uri = Solargraph::LanguageServer::UriHelpers.file_to_uri(File.absolute_path('spec/fixtures/workspace/lib/something.rb')) | ||
message = Solargraph::LanguageServer::Message::TextDocument::TypeDefinition.new(host, { | ||
'params' => { | ||
'textDocument' => { | ||
'uri' => file_uri | ||
}, | ||
'position' => { | ||
'line' => 4, | ||
'character' => 10 | ||
} | ||
} | ||
}) | ||
message.process | ||
expect(message.result.first[:uri]).to eq(something_uri) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters