Skip to content

Commit 1159866

Browse files
authored
replaced occurrences of node.slice with node.full_name (#1287)
* node.slice replaced with node.full_name * type errors resolved
1 parent ef77ed6 commit 1159866

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

lib/ruby_lsp/listeners/completion.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def on_string_node_enter(node)
4343
def on_constant_read_node_enter(node)
4444
return if DependencyDetector.instance.typechecker
4545

46-
name = node.slice
46+
name = constant_name(node)
47+
return if name.nil?
48+
4749
candidates = @index.prefix_search(name, @nesting)
4850
candidates.each do |entries|
4951
complete_name = T.must(entries.first).name
@@ -62,7 +64,8 @@ def on_constant_read_node_enter(node)
6264
def on_constant_path_node_enter(node)
6365
return if DependencyDetector.instance.typechecker
6466

65-
name = node.slice
67+
name = constant_name(node)
68+
return if name.nil?
6669

6770
top_level_reference = if name.start_with?("::")
6871
name = name.delete_prefix("::")

lib/ruby_lsp/listeners/definition.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,18 @@ def on_call_node_enter(node)
4545

4646
sig { params(node: Prism::ConstantPathNode).void }
4747
def on_constant_path_node_enter(node)
48-
find_in_index(node.slice)
48+
name = constant_name(node)
49+
return if name.nil?
50+
51+
find_in_index(name)
4952
end
5053

5154
sig { params(node: Prism::ConstantReadNode).void }
5255
def on_constant_read_node_enter(node)
53-
find_in_index(node.slice)
56+
name = constant_name(node)
57+
return if name.nil?
58+
59+
find_in_index(name)
5460
end
5561

5662
private

lib/ruby_lsp/listeners/hover.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ def initialize(response_builder, uri, nesting, index, dispatcher, typechecker_en
5555
def on_constant_read_node_enter(node)
5656
return if @typechecker_enabled
5757

58-
generate_hover(node.slice, node.location)
58+
name = constant_name(node)
59+
return if name.nil?
60+
61+
generate_hover(name, node.location)
5962
end
6063

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

72-
generate_hover(node.slice, node.location)
75+
name = constant_name(node)
76+
return if name.nil?
77+
78+
generate_hover(name, node.location)
7379
end
7480

7581
sig { params(node: Prism::CallNode).void }

lib/ruby_lsp/requests/support/common.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,21 @@ def markdown_from_index_entries(title, entries)
132132
#{categorized_markdown[:documentation]}
133133
MARKDOWN
134134
end
135+
136+
sig do
137+
params(
138+
node: T.any(
139+
Prism::ConstantPathNode,
140+
Prism::ConstantReadNode,
141+
Prism::ConstantPathTargetNode,
142+
),
143+
).returns(T.nilable(String))
144+
end
145+
def constant_name(node)
146+
node.full_name
147+
rescue Prism::ConstantPathNode::DynamicPartsInConstantPathError
148+
nil
149+
end
135150
end
136151
end
137152
end

0 commit comments

Comments
 (0)