Skip to content

Commit a1b70cf

Browse files
committed
Add Entry#in_dependencies? and refactor dependency checks
1 parent 159e8c9 commit a1b70cf

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

lib/ruby_indexer/lib/ruby_indexer/entry.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,31 @@ def private?
4141
@visibility == :private
4242
end
4343

44-
#: -> String
44+
#: -> bool?
45+
def in_dependencies?
46+
@in_dependencies ||= if file_path
47+
!RubyLsp.not_in_dependencies?(
48+
file_path, #: as String
49+
)
50+
else
51+
false
52+
end #: bool?
53+
end
54+
55+
#: -> String?
4556
def file_name
46-
if @uri.scheme == "untitled"
47-
@uri.opaque #: as !nil
57+
@file_name ||= if @uri.scheme == "untitled"
58+
@uri.opaque
4859
else
4960
File.basename(
5061
file_path, #: as !nil
5162
)
52-
end
63+
end #: String?
5364
end
5465

5566
#: -> String?
5667
def file_path
57-
@uri.full_path
68+
@file_path ||= @uri.full_path #: String?
5869
end
5970

6071
#: -> String

lib/ruby_lsp/listeners/definition.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ def handle_method_definition(message, receiver_type, inherited_only: false)
316316

317317
methods.each do |target_method|
318318
uri = target_method.uri
319-
full_path = uri.full_path
320-
next if @sorbet_level.true_or_higher? && (!full_path || not_in_dependencies?(full_path))
319+
320+
next if @sorbet_level.true_or_higher? && !target_method.in_dependencies?
321321

322322
@response_builder << Interface::LocationLink.new(
323323
target_uri: uri.to_s,
@@ -390,9 +390,8 @@ def find_in_index(value)
390390
# additional behavior on top of jumping to RBIs. The only sigil where Sorbet cannot handle constants is typed
391391
# ignore
392392
uri = entry.uri
393-
full_path = uri.full_path
394393

395-
if !@sorbet_level.ignore? && (!full_path || not_in_dependencies?(full_path))
394+
if !@sorbet_level.ignore? && !entry.in_dependencies?
396395
next
397396
end
398397

lib/ruby_lsp/requests/support/common.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ def create_code_lens(node, title:, command_name:, arguments:, data:)
4949
)
5050
end
5151

52-
#: (String file_path) -> bool?
53-
def not_in_dependencies?(file_path)
54-
BUNDLE_PATH &&
55-
!file_path.start_with?(
56-
BUNDLE_PATH, #: as !nil
57-
) &&
58-
!file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
59-
end
60-
6152
#: (Prism::CallNode node) -> bool
6253
def self_receiver?(node)
6354
receiver = node.receiver

lib/ruby_lsp/requests/workspace_symbol.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ def initialize(global_state, query)
2222
def perform
2323
@index.fuzzy_search(@query).filter_map do |entry|
2424
uri = entry.uri
25-
file_path = uri.full_path
2625

2726
# We only show symbols declared in the workspace
28-
in_dependencies = file_path && !not_in_dependencies?(file_path)
29-
next if in_dependencies
27+
next if entry.in_dependencies?
3028

3129
# We should never show private symbols when searching the entire workspace
3230
next if entry.private?

lib/ruby_lsp/utils.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ module RubyLsp
2121
GUESSED_TYPES_URL = "https://shopify.github.io/ruby-lsp/#guessed-types"
2222
TEST_PATH_PATTERN = "**/{test,spec,features}/**/{*_test.rb,test_*.rb,*_spec.rb,*.feature}"
2323

24+
class << self
25+
#: (String file_path) -> bool?
26+
def not_in_dependencies?(file_path)
27+
BUNDLE_PATH &&
28+
!file_path.start_with?(
29+
BUNDLE_PATH, #: as !nil
30+
) &&
31+
!file_path.start_with?(RbConfig::CONFIG["rubylibdir"])
32+
end
33+
end
34+
2435
# Request delegation for embedded languages is not yet standardized into the language server specification. Here we
2536
# use this custom error class as a way to return a signal to the client that the request should be delegated to the
2637
# language server for the host language. The support for delegation is custom built on the client side, so each editor

0 commit comments

Comments
 (0)