Skip to content

Commit d09b7ab

Browse files
authored
Fix constant location calculation in CodeFile and add corresponding test (#133)
1 parent 0f8c72e commit d09b7ab

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lib/ruby_language_server/code_file.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def tags
8282
{
8383
name:,
8484
kind: SYMBOL_KIND[:constant],
85-
location: Location.hash(uri, variable.line - 1, variable.column),
85+
location: Location.hash(uri, variable.line, variable.column),
8686
containerName: variable.scope.name
8787
}
8888
end

spec/lib/ruby_language_server/code_file_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,18 @@ def code_file(text)
125125
assert_equal(expected_initialize_range, initialize_tag[:location][:range])
126126
assert_equal(expected_foo_method_range, foo_method_tag[:location][:range])
127127
end
128+
129+
it 'should have correct start and end lines for constants' do
130+
tag = cf.tags.detect { |t| t[:name] == 'FOO_CONSTANT' }
131+
132+
# The constant is on line 9 (1-indexed), which should be line 8 (0-indexed) in LSP
133+
# FOO_CONSTANT = 1 is on line 9 of the source
134+
expected_range = {
135+
start: { line: 8, character: 2 },
136+
end: { line: 8, character: 2 }
137+
}
138+
assert_equal(expected_range, tag[:location][:range])
139+
end
128140
end
129141
end
130142
end

0 commit comments

Comments
 (0)