Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions lib/ruby_indexer/lib/ruby_indexer/entry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,31 @@ def private?
@visibility == :private
end

#: -> bool?
def in_dependencies?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can invert the logic here since we almost always want to check if something is defined in the workspace and end up negating the result everywhere.

How about we make this into in_workspace? and then we can use it more directly?

@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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the file name have significant impact on performance? I can see Uri#full_path being slow, but I'm surprised that File.basename introduces significant overhead.

@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
Expand Down
7 changes: 3 additions & 4 deletions lib/ruby_lsp/listeners/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions lib/ruby_lsp/requests/support/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/ruby_lsp/requests/workspace_symbol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
11 changes: 11 additions & 0 deletions lib/ruby_lsp/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading