@@ -34,7 +34,7 @@ def initialize
34
34
@files_to_entries = T . let ( { } , T ::Hash [ String , T ::Array [ Entry ] ] )
35
35
36
36
# Holds all require paths for every indexed item so that we can provide autocomplete for requires
37
- @require_paths_tree = T . let ( PrefixTree [ IndexablePath ] . new , PrefixTree [ IndexablePath ] )
37
+ @require_paths_tree = T . let ( PrefixTree [ Uri ] . new , PrefixTree [ Uri ] )
38
38
39
39
# Holds the linearized ancestors list for every namespace
40
40
@ancestors = T . let ( { } , T ::Hash [ String , T ::Array [ String ] ] )
@@ -63,31 +63,35 @@ def register_included_hook(module_name, &hook)
63
63
( @included_hooks [ module_name ] ||= [ ] ) << hook
64
64
end
65
65
66
- sig { params ( indexable : IndexablePath ) . void }
67
- def delete ( indexable )
68
- # For each constant discovered in `path`, delete the associated entry from the index. If there are no entries
69
- # left, delete the constant from the index.
70
- @files_to_entries [ indexable . full_path ] &.each do |entry |
71
- name = entry . name
72
- entries = @entries [ name ]
73
- next unless entries
74
-
75
- # Delete the specific entry from the list for this name
76
- entries . delete ( entry )
77
-
78
- # If all entries were deleted, then remove the name from the hash and from the prefix tree. Otherwise, update
79
- # the prefix tree with the current entries
80
- if entries . empty?
81
- @entries . delete ( name )
82
- @entries_tree . delete ( name )
83
- else
84
- @entries_tree . insert ( name , entries )
66
+ sig { params ( uri : Uri ) . void }
67
+ def delete ( uri )
68
+ path = uri . to_standardized_path
69
+
70
+ if path
71
+ # For each constant discovered in `path`, delete the associated entry from the index. If there are no entries
72
+ # left, delete the constant from the index.
73
+ @files_to_entries [ path ] &.each do |entry |
74
+ name = entry . name
75
+ entries = @entries [ name ]
76
+ next unless entries
77
+
78
+ # Delete the specific entry from the list for this name
79
+ entries . delete ( entry )
80
+
81
+ # If all entries were deleted, then remove the name from the hash and from the prefix tree. Otherwise, update
82
+ # the prefix tree with the current entries
83
+ if entries . empty?
84
+ @entries . delete ( name )
85
+ @entries_tree . delete ( name )
86
+ else
87
+ @entries_tree . insert ( name , entries )
88
+ end
85
89
end
86
- end
87
90
88
- @files_to_entries . delete ( indexable . full_path )
91
+ @files_to_entries . delete ( path )
92
+ end
89
93
90
- require_path = indexable . require_path
94
+ require_path = uri . require_path
91
95
@require_paths_tree . delete ( require_path ) if require_path
92
96
end
93
97
@@ -105,7 +109,7 @@ def [](fully_qualified_name)
105
109
@entries [ fully_qualified_name . delete_prefix ( "::" ) ]
106
110
end
107
111
108
- sig { params ( query : String ) . returns ( T ::Array [ IndexablePath ] ) }
112
+ sig { params ( query : String ) . returns ( T ::Array [ Uri ] ) }
109
113
def search_require_paths ( query )
110
114
@require_paths_tree . search ( query )
111
115
end
@@ -292,49 +296,53 @@ def resolve(name, nesting, seen_names = [])
292
296
nil
293
297
end
294
298
295
- # Index all files for the given indexable paths , which defaults to what is configured. A block can be used to track
296
- # and control indexing progress. That block is invoked with the current progress percentage and should return `true`
297
- # to continue indexing or `false` to stop indexing.
299
+ # Index all files for the given uris , which defaults to what is configured. A block can be used to track and control
300
+ # indexing progress. That block is invoked with the current progress percentage and should return `true` to continue
301
+ # indexing or `false` to stop indexing.
298
302
sig do
299
303
params (
300
- indexable_paths : T ::Array [ IndexablePath ] ,
304
+ uris : T ::Array [ Uri ] ,
301
305
block : T . nilable ( T . proc . params ( progress : Integer ) . returns ( T ::Boolean ) ) ,
302
306
) . void
303
307
end
304
- def index_all ( indexable_paths : @configuration . indexables , &block )
308
+ def index_all ( uris : @configuration . indexables , &block )
305
309
RBSIndexer . new ( self ) . index_ruby_core
306
310
# Calculate how many paths are worth 1% of progress
307
- progress_step = ( indexable_paths . length / 100.0 ) . ceil
311
+ progress_step = ( uris . length / 100.0 ) . ceil
308
312
309
- indexable_paths . each_with_index do |path , index |
313
+ uris . each_with_index do |uri , index |
310
314
if block && index % progress_step == 0
311
315
progress = ( index / progress_step ) + 1
312
316
break unless block . call ( progress )
313
317
end
314
318
315
- index_single ( path )
319
+ index_single ( uri )
316
320
end
317
321
end
318
322
319
- sig { params ( indexable_path : IndexablePath , source : T . nilable ( String ) ) . void }
320
- def index_single ( indexable_path , source = nil )
321
- content = source || File . read ( indexable_path . full_path )
323
+ sig { params ( uri : Uri , source : T . nilable ( String ) ) . void }
324
+ def index_single ( uri , source = nil )
325
+ path = uri . to_standardized_path
326
+ # Remove once we support indexing non file URIs
327
+ return unless path
328
+
329
+ content = source || File . read ( path )
322
330
dispatcher = Prism ::Dispatcher . new
323
331
324
332
result = Prism . parse ( content )
325
333
listener = DeclarationListener . new (
326
334
self ,
327
335
dispatcher ,
328
336
result ,
329
- indexable_path . full_path ,
337
+ path ,
330
338
enhancements : @enhancements ,
331
339
)
332
340
dispatcher . dispatch ( result . value )
333
341
334
342
indexing_errors = listener . indexing_errors . uniq
335
343
336
- require_path = indexable_path . require_path
337
- @require_paths_tree . insert ( require_path , indexable_path ) if require_path
344
+ require_path = uri . require_path
345
+ @require_paths_tree . insert ( require_path , uri ) if require_path
338
346
339
347
if indexing_errors . any?
340
348
indexing_errors . each do |error |
@@ -346,7 +354,7 @@ def index_single(indexable_path, source = nil)
346
354
# it
347
355
rescue SystemStackError => e
348
356
if e . backtrace &.first &.include? ( "prism" )
349
- $stderr. puts "Prism error indexing #{ indexable_path . full_path } : #{ e . message } "
357
+ $stderr. puts "Prism error indexing #{ uri } : #{ e . message } "
350
358
else
351
359
raise
352
360
end
@@ -541,16 +549,17 @@ def instance_variable_completion_candidates(name, owner_name)
541
549
variables
542
550
end
543
551
544
- # Synchronizes a change made to the given indexable path. This method will ensure that new declarations are indexed,
545
- # removed declarations removed and that the ancestor linearization cache is cleared if necessary
546
- sig { params ( indexable : IndexablePath ) . void }
547
- def handle_change ( indexable )
548
- original_entries = @files_to_entries [ indexable . full_path ]
552
+ # Synchronizes a change made to the given uri. This method will ensure that new declarations are indexed, removed
553
+ # declarations removed and that the ancestor linearization cache is cleared if necessary
554
+ sig { params ( uri : Uri ) . void }
555
+ def handle_change ( uri )
556
+ path = T . must ( uri . to_standardized_path )
557
+ original_entries = @files_to_entries [ path ]
549
558
550
- delete ( indexable )
551
- index_single ( indexable )
559
+ delete ( uri )
560
+ index_single ( uri )
552
561
553
- updated_entries = @files_to_entries [ indexable . full_path ]
562
+ updated_entries = @files_to_entries [ path ]
554
563
555
564
return unless original_entries && updated_entries
556
565
0 commit comments