Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced occurrences of node.slice with node.full_name #1287

Merged
Merged
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
7 changes: 5 additions & 2 deletions lib/ruby_lsp/listeners/completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def on_string_node_enter(node)
def on_constant_read_node_enter(node)
return if DependencyDetector.instance.typechecker

name = node.slice
name = constant_name(node)
return if name.nil?

candidates = @index.prefix_search(name, @nesting)
candidates.each do |entries|
complete_name = T.must(entries.first).name
Expand All @@ -62,7 +64,8 @@ def on_constant_read_node_enter(node)
def on_constant_path_node_enter(node)
return if DependencyDetector.instance.typechecker

name = node.slice
name = constant_name(node)
return if name.nil?

top_level_reference = if name.start_with?("::")
name = name.delete_prefix("::")
Expand Down
10 changes: 8 additions & 2 deletions lib/ruby_lsp/listeners/definition.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ def on_call_node_enter(node)

sig { params(node: Prism::ConstantPathNode).void }
def on_constant_path_node_enter(node)
find_in_index(node.slice)
name = constant_name(node)
return if name.nil?

find_in_index(name)
end

sig { params(node: Prism::ConstantReadNode).void }
def on_constant_read_node_enter(node)
find_in_index(node.slice)
name = constant_name(node)
return if name.nil?

find_in_index(name)
end

private
Expand Down
10 changes: 8 additions & 2 deletions lib/ruby_lsp/listeners/hover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def initialize(response_builder, uri, nesting, index, dispatcher, typechecker_en
def on_constant_read_node_enter(node)
return if @typechecker_enabled

generate_hover(node.slice, node.location)
name = constant_name(node)
return if name.nil?

generate_hover(name, node.location)
end

sig { params(node: Prism::ConstantWriteNode).void }
Expand All @@ -69,7 +72,10 @@ def on_constant_write_node_enter(node)
def on_constant_path_node_enter(node)
return if DependencyDetector.instance.typechecker

generate_hover(node.slice, node.location)
name = constant_name(node)
return if name.nil?

generate_hover(name, node.location)
end

sig { params(node: Prism::CallNode).void }
Expand Down
15 changes: 15 additions & 0 deletions lib/ruby_lsp/requests/support/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ def markdown_from_index_entries(title, entries)
#{content}
MARKDOWN
end

sig do
params(
node: T.any(
Prism::ConstantPathNode,
Prism::ConstantReadNode,
Prism::ConstantPathTargetNode,
),
).returns(T.nilable(String))
end
def constant_name(node)
node.full_name
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
nil
end
end
end
end
Expand Down
Loading