diff --git a/lib/ruby_language_server/code_file.rb b/lib/ruby_language_server/code_file.rb index 1df5c0c..97126a5 100644 --- a/lib/ruby_language_server/code_file.rb +++ b/lib/ruby_language_server/code_file.rb @@ -82,7 +82,7 @@ def tags { name:, kind: SYMBOL_KIND[:constant], - location: Location.hash(uri, variable.line - 1, variable.column), + location: Location.hash(uri, variable.line, variable.column), containerName: variable.scope.name } end diff --git a/spec/lib/ruby_language_server/code_file_spec.rb b/spec/lib/ruby_language_server/code_file_spec.rb index 6da023d..169f052 100644 --- a/spec/lib/ruby_language_server/code_file_spec.rb +++ b/spec/lib/ruby_language_server/code_file_spec.rb @@ -125,6 +125,18 @@ def code_file(text) assert_equal(expected_initialize_range, initialize_tag[:location][:range]) assert_equal(expected_foo_method_range, foo_method_tag[:location][:range]) end + + it 'should have correct start and end lines for constants' do + tag = cf.tags.detect { |t| t[:name] == 'FOO_CONSTANT' } + + # The constant is on line 9 (1-indexed), which should be line 8 (0-indexed) in LSP + # FOO_CONSTANT = 1 is on line 9 of the source + expected_range = { + start: { line: 8, character: 2 }, + end: { line: 8, character: 2 } + } + assert_equal(expected_range, tag[:location][:range]) + end end end end