|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require_relative 'spec/test_helper' |
| 4 | +require 'minitest/autorun' |
| 5 | + |
| 6 | +describe 'Fallback behavior' do |
| 7 | + let(:project_manager) { RubyLanguageServer::ProjectManager.new('/proj', 'file:///foo/') } |
| 8 | + |
| 9 | + it 'should test current behavior when nothing found in scope' do |
| 10 | + # Define a class in one file |
| 11 | + other_file = <<~CODE |
| 12 | + class MyExternalClass |
| 13 | + def external_method |
| 14 | + end |
| 15 | + end |
| 16 | + CODE |
| 17 | + |
| 18 | + # Reference it from another file where it's not in scope |
| 19 | + file_text = <<~CODE |
| 20 | + module SomeModule |
| 21 | + class SomeClass |
| 22 | + def some_method |
| 23 | + MyExternalClass # Exists elsewhere but not in local scope |
| 24 | + end |
| 25 | + end |
| 26 | + end |
| 27 | + CODE |
| 28 | + |
| 29 | + project_manager.update_document_content('other_uri', other_file) |
| 30 | + project_manager.tags_for_uri('other_uri') # Force load |
| 31 | + |
| 32 | + project_manager.update_document_content('test_uri', file_text) |
| 33 | + project_manager.tags_for_uri('test_uri') # Force load |
| 34 | + |
| 35 | + # Try to find MyExternalClass from test_uri |
| 36 | + position = OpenStruct.new(line: 3, character: 6) |
| 37 | + results = project_manager.possible_definitions('test_uri', position) |
| 38 | + puts "Results for MyExternalClass (should find it globally): #{results.inspect}" |
| 39 | + puts "Expected to find definition in other_uri" |
| 40 | + end |
| 41 | + |
| 42 | + it 'should test when constant truly does not exist' do |
| 43 | + file_text = <<~CODE |
| 44 | + module SomeModule |
| 45 | + class SomeClass |
| 46 | + def some_method |
| 47 | + TotallyNonExistentClass # This truly doesn't exist anywhere |
| 48 | + end |
| 49 | + end |
| 50 | + end |
| 51 | + CODE |
| 52 | + |
| 53 | + project_manager.update_document_content('test_uri', file_text) |
| 54 | + project_manager.tags_for_uri('test_uri') # Force load |
| 55 | + |
| 56 | + # Try to find non-existent constant |
| 57 | + position = OpenStruct.new(line: 3, character: 6) |
| 58 | + results = project_manager.possible_definitions('test_uri', position) |
| 59 | + puts "Results for TotallyNonExistentClass (shouldn't find anything): #{results.inspect}" |
| 60 | + end |
| 61 | +end |
0 commit comments