Class: RubyLsp::Requests::WorkspaceSymbol
- Includes:
- Support::Common
- Defined in:
- lib/ruby_lsp/requests/workspace_symbol.rb
Overview
The [workspace symbol](microsoft.github.io/language-server-protocol/specification#workspace_symbol) request allows fuzzy searching declarations in the entire project. On VS Code, use CTRL/CMD + T to search for symbols.
Instance Method Summary collapse
-
#initialize(global_state, query) ⇒ WorkspaceSymbol
constructor
: (GlobalState global_state, String? query) -> void.
-
#perform ⇒ Object
: -> Array.
Methods included from Support::Common
#categorized_markdown_from_index_entries, #constant_name, #create_code_lens, #each_constant_path_part, #kind_for_entry, #markdown_from_index_entries, #namespace_constant_name, #not_in_dependencies?, #range_from_location, #range_from_node, #self_receiver?
Constructor Details
#initialize(global_state, query) ⇒ WorkspaceSymbol
: (GlobalState global_state, String? query) -> void
13 14 15 16 17 18 |
# File 'lib/ruby_lsp/requests/workspace_symbol.rb', line 13 def initialize(global_state, query) super() @global_state = global_state @query = query @index = global_state.index #: RubyIndexer::Index end |
Instance Method Details
#perform ⇒ Object
: -> Array
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ruby_lsp/requests/workspace_symbol.rb', line 22 def perform fuzzy_search.filter_map do |entry| kind = kind_for_entry(entry) loc = entry.location # We use the namespace as the container name, but we also use the full name as the regular name. The reason we # do this is to allow people to search for fully qualified names (e.g.: `Foo::Bar`). If we only included the # short name `Bar`, then searching for `Foo::Bar` would not return any results *container, _short_name = entry.name.split("::") Interface::WorkspaceSymbol.new( name: entry.name, container_name: container.join("::"), kind: kind, location: Interface::Location.new( uri: entry.uri.to_s, range: Interface::Range.new( start: Interface::Position.new(line: loc.start_line - 1, character: loc.start_column), end: Interface::Position.new(line: loc.end_line - 1, character: loc.end_column), ), ), ) end end |