-
Notifications
You must be signed in to change notification settings - Fork 223
Description
Description
Ruby LSP Information
Ruby LSP WorkspaceSymbol Responses are not generated according to spec if index contains unresolved alias methods, unresolved constant aliases or class variables. Additionally resolvable methods and constants are not being processed either in resolved method or alias form.
The spec for SymbolInformation stands that kind should be represented by one of SybolKind enum variants while RubyLSP. If we are going to look into how these are encoded by Ruby-LSP we can notice that neither RubyIndexer::Entry::ConstantAlias, RubyIndexer::Entry::MethodAlias nor RubyIndexer::Entry::ClassVariable have their when branch on the case. This leads to nil results. Additionally due to lazy nature of unresolved entries fuzzy_search is not able to work on RubyIndexer::Entry::ConstantAlias nor RubyIndexer::Entry::MethodAlias from index.
Reproduction steps
- Start the Ruby LSP using a Zed Eeditor
- Open a Ruby file with following content
OK = 'OK'
class Foo
BOK = OK
BAD = AD
def test
end
alias whatever test
alias_method :bar, :to_a
alias_method "baz", "to_a"
@@test = '123'
end- Go to New Agent Thread and try to open type
@symbol - Observer nothing shows up and You have
data did not match any variant of untagged enum WorkspaceSymbolResponseexception in the logs
Alternatively you can run this following code in IRB
Code snippet or error message
require 'ruby-lsp'
require "ruby_lsp/internal"
@global_state = RubyLsp::GlobalState.new
# @global_state.stubs(:has_type_checker).returns(false)
@index = @global_state.index
@index.index_single(URI::Generic.from_path(path: "/fake.rb"), <<~RUBY)
OK = 'OK'
class Foo
BOK = OK
BAD = AD
def test
end
alias whatever test
alias_method :bar, :to_a
alias_method "baz", "to_a"
@@test = '123'
end
RUBY
RubyLsp::Requests::WorkspaceSymbol.new(@global_state, nil).performWhich should result in following response:
[...,
#<LanguageServer::Protocol::Interface::WorkspaceSymbol:0x000000010646ee50
@attributes=
{:name=>"@@test",
:kind=>nil,
:containerName=>"",
:location=>
#<LanguageServer::Protocol::Interface::Location:0x000000010646ef40
@attributes=
{:uri=>"file:///fake.rb",
:range=>
#<LanguageServer::Protocol::Interface::Range:0x000000010646f058
@attributes=
{:start=>#<LanguageServer::Protocol::Interface::Position:0x000000010646f530 @attributes={:line=>9, :character=>2}>,
:end=>#<LanguageServer::Protocol::Interface::Position:0x000000010646f0f8 @attributes={:line=>9, :character=>8}>}>}>}>]
You can notice that kind for class variable, constant alias and resolvable method alias is nil, additionally method aliases which are not resolvable are also included in the result.