Skip to content

Commit d3fa68d

Browse files
committed
Start indexing and resolving Rubydex graph
1 parent 6df9542 commit d3fa68d

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

lib/ruby_lsp/global_state.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class GlobalState
3030
#: RubyIndexer::Index
3131
attr_reader :index
3232

33+
#: Rubydex::Graph
34+
attr_reader :graph
35+
3336
#: Encoding
3437
attr_reader :encoding
3538

@@ -58,6 +61,7 @@ def initialize
5861
@test_library = "minitest" #: String
5962
@has_type_checker = true #: bool
6063
@index = RubyIndexer::Index.new #: RubyIndexer::Index
64+
@graph = Rubydex::Graph.new #: Rubydex::Graph
6165
@supported_formatters = {} #: Hash[String, Requests::Support::Formatter]
6266
@type_inferrer = TypeInferrer.new(@index) #: TypeInferrer
6367
@addon_settings = {} #: Hash[String, untyped]
@@ -117,6 +121,7 @@ def apply_options(options)
117121
all_dependencies = gather_direct_and_indirect_dependencies
118122
workspace_uri = options.dig(:workspaceFolders, 0, :uri)
119123
@workspace_uri = URI(workspace_uri) if workspace_uri
124+
@graph.workspace_path = workspace_path
120125

121126
specified_formatter = options.dig(:initializationOptions, :formatter)
122127
rubocop_has_addon = defined?(::RuboCop::Version::STRING) &&
@@ -189,12 +194,16 @@ def apply_options(options)
189194

190195
encodings = options.dig(:capabilities, :general, :positionEncodings)
191196
@encoding = if !encodings || encodings.empty?
197+
@graph.encoding = "utf16"
192198
Encoding::UTF_16LE
193199
elsif encodings.include?(Constant::PositionEncodingKind::UTF8)
200+
@graph.encoding = "utf8"
194201
Encoding::UTF_8
195202
elsif encodings.include?(Constant::PositionEncodingKind::UTF16)
203+
@graph.encoding = "utf16"
196204
Encoding::UTF_16LE
197205
else
206+
@graph.encoding = "utf32"
198207
Encoding::UTF_32
199208
end
200209
@index.configuration.encoding = @encoding

lib/ruby_lsp/server.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,12 +1226,18 @@ def shutdown
12261226

12271227
#: -> void
12281228
def perform_initial_indexing
1229+
progress("indexing-progress", message: "Indexing workspace...")
1230+
@global_state.graph.index_workspace
1231+
1232+
progress("indexing-progress", message: "Resolving graph...")
1233+
@global_state.graph.resolve
1234+
12291235
# The begin progress invocation happens during `initialize`, so that the notification is sent before we are
12301236
# stuck indexing files
12311237
Thread.new do
12321238
begin
12331239
@global_state.index.index_all do |percentage|
1234-
progress("indexing-progress", percentage)
1240+
progress("indexing-progress", percentage: percentage)
12351241
true
12361242
rescue ClosedQueueError
12371243
# Since we run indexing on a separate thread, it's possible to kill the server before indexing is complete.
@@ -1285,11 +1291,13 @@ def begin_progress(id, title, percentage: 0)
12851291
send_message(Notification.progress_begin(id, title, percentage: percentage, message: "#{percentage}% completed"))
12861292
end
12871293

1288-
#: (String id, Integer percentage) -> void
1289-
def progress(id, percentage)
1294+
#: (String, ?message: String?, ?percentage: Integer?) -> void
1295+
def progress(id, message: nil, percentage: nil)
12901296
return unless @global_state.client_capabilities.supports_progress
12911297

1292-
send_message(Notification.progress_report(id, percentage: percentage, message: "#{percentage}% completed"))
1298+
message ||= "#{percentage}% completed" if percentage
1299+
1300+
send_message(Notification.progress_report(id, percentage: percentage, message: message))
12931301
end
12941302

12951303
#: (String id) -> void

lib/ruby_lsp/test_helper.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typec
3030
})
3131

3232
server.global_state.index.index_single(uri, source)
33+
graph = server.global_state.graph
34+
graph.index_source(uri.to_s, source, "ruby")
35+
graph.resolve
3336
end
3437

3538
server.load_addons(include_project_addons: false) if load_addons

0 commit comments

Comments
 (0)