1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
# typed: true
# frozen_string_literal: true
require "test_helper"
class ReferencesTest < Minitest::Test
def test_finds_constant_references
refs = find_references("test/fixtures/rename_me.rb", { line: 0, character: 6 }).map do |ref|
ref.range.start.line
end
assert_equal([0, 3], refs)
end
private
def find_references(fixture_path, position)
source = File.read(fixture_path)
path = File.expand_path(fixture_path)
global_state = RubyLsp::GlobalState.new
global_state.index.index_single(URI::Generic.from_path(path: path), source)
store = RubyLsp::Store.new(global_state)
document = RubyLsp::RubyDocument.new(
source: source,
version: 1,
uri: URI::Generic.from_path(path: path),
global_state: global_state,
)
# In addition to glob files from the workspace, we also want to test references collection from the store
store.set(uri: URI::Generic.from_path(path: path), source: source, version: 1, language_id: :ruby)
RubyLsp::Requests::References.new(
global_state,
store,
document,
{ position: position },
).perform
end
end
|