From 694b80ae0b42cbab21dc078ccd5225c50e1f2200 Mon Sep 17 00:00:00 2001 From: Kurt Werle Date: Tue, 13 Jan 2026 22:21:23 -0800 Subject: [PATCH] Fix constant location calculation in CodeFile and add corresponding test --- lib/ruby_language_server/code_file.rb | 2 +- spec/lib/ruby_language_server/code_file_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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