diff --git a/lib/ruby_indexer/lib/ruby_indexer/entry.rb b/lib/ruby_indexer/lib/ruby_indexer/entry.rb index bc595a042..800456aaa 100644 --- a/lib/ruby_indexer/lib/ruby_indexer/entry.rb +++ b/lib/ruby_indexer/lib/ruby_indexer/entry.rb @@ -41,20 +41,31 @@ def private? @visibility == :private end + #: -> bool? + def in_dependencies? + @in_dependencies ||= if file_path + !RubyLsp.not_in_dependencies?( + file_path, #: as String + ) + else + false + end #: bool? + end + #: -> String def file_name - if @uri.scheme == "untitled" + @file_name ||= if @uri.scheme == "untitled" @uri.opaque #: as !nil else File.basename( file_path, #: as !nil ) - end + end #: String? end #: -> String? def file_path - @uri.full_path + @file_path ||= @uri.full_path #: String? end #: -> String diff --git a/lib/ruby_lsp/listeners/definition.rb b/lib/ruby_lsp/listeners/definition.rb index c0c3198d0..526517306 100644 --- a/lib/ruby_lsp/listeners/definition.rb +++ b/lib/ruby_lsp/listeners/definition.rb @@ -316,8 +316,8 @@ def handle_method_definition(message, receiver_type, inherited_only: false) methods.each do |target_method| uri = target_method.uri - full_path = uri.full_path - next if @sorbet_level.true_or_higher? && (!full_path || not_in_dependencies?(full_path)) + + next if @sorbet_level.true_or_higher? && !target_method.in_dependencies? @response_builder << Interface::LocationLink.new( target_uri: uri.to_s, @@ -390,9 +390,8 @@ def find_in_index(value) # additional behavior on top of jumping to RBIs. The only sigil where Sorbet cannot handle constants is typed # ignore uri = entry.uri - full_path = uri.full_path - if !@sorbet_level.ignore? && (!full_path || not_in_dependencies?(full_path)) + if !@sorbet_level.ignore? && !entry.in_dependencies? next end diff --git a/lib/ruby_lsp/requests/support/common.rb b/lib/ruby_lsp/requests/support/common.rb index 010dd3850..b20c17613 100644 --- a/lib/ruby_lsp/requests/support/common.rb +++ b/lib/ruby_lsp/requests/support/common.rb @@ -49,15 +49,6 @@ def create_code_lens(node, title:, command_name:, arguments:, data:) ) end - #: (String file_path) -> bool? - def not_in_dependencies?(file_path) - BUNDLE_PATH && - !file_path.start_with?( - BUNDLE_PATH, #: as !nil - ) && - !file_path.start_with?(RbConfig::CONFIG["rubylibdir"]) - end - #: (Prism::CallNode node) -> bool def self_receiver?(node) receiver = node.receiver diff --git a/lib/ruby_lsp/requests/workspace_symbol.rb b/lib/ruby_lsp/requests/workspace_symbol.rb index 1abde2337..7c6186e4c 100644 --- a/lib/ruby_lsp/requests/workspace_symbol.rb +++ b/lib/ruby_lsp/requests/workspace_symbol.rb @@ -22,11 +22,9 @@ def initialize(global_state, query) def perform @index.fuzzy_search(@query).filter_map do |entry| uri = entry.uri - file_path = uri.full_path # We only show symbols declared in the workspace - in_dependencies = file_path && !not_in_dependencies?(file_path) - next if in_dependencies + next if entry.in_dependencies? # We should never show private symbols when searching the entire workspace next if entry.private? diff --git a/lib/ruby_lsp/utils.rb b/lib/ruby_lsp/utils.rb index 9e78d0db4..e1fd3f7c6 100644 --- a/lib/ruby_lsp/utils.rb +++ b/lib/ruby_lsp/utils.rb @@ -21,6 +21,17 @@ module RubyLsp GUESSED_TYPES_URL = "https://shopify.github.io/ruby-lsp/#guessed-types" TEST_PATH_PATTERN = "**/{test,spec,features}/**/{*_test.rb,test_*.rb,*_spec.rb,*.feature}" + class << self + #: (String file_path) -> bool? + def not_in_dependencies?(file_path) + BUNDLE_PATH && + !file_path.start_with?( + BUNDLE_PATH, #: as !nil + ) && + !file_path.start_with?(RbConfig::CONFIG["rubylibdir"]) + end + end + # Request delegation for embedded languages is not yet standardized into the language server specification. Here we # use this custom error class as a way to return a signal to the client that the request should be delegated to the # language server for the host language. The support for delegation is custom built on the client side, so each editor