Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/ruby_lsp/global_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class GlobalState
#: RubyIndexer::Index
attr_reader :index

#: Rubydex::Graph
attr_reader :graph

#: Encoding
attr_reader :encoding

Expand Down Expand Up @@ -58,6 +61,7 @@ def initialize
@test_library = "minitest" #: String
@has_type_checker = true #: bool
@index = RubyIndexer::Index.new #: RubyIndexer::Index
@graph = Rubydex::Graph.new #: Rubydex::Graph
@supported_formatters = {} #: Hash[String, Requests::Support::Formatter]
@type_inferrer = TypeInferrer.new(@index) #: TypeInferrer
@addon_settings = {} #: Hash[String, untyped]
Expand Down Expand Up @@ -117,6 +121,7 @@ def apply_options(options)
all_dependencies = gather_direct_and_indirect_dependencies
workspace_uri = options.dig(:workspaceFolders, 0, :uri)
@workspace_uri = URI(workspace_uri) if workspace_uri
@graph.workspace_path = workspace_path

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

encodings = options.dig(:capabilities, :general, :positionEncodings)
@encoding = if !encodings || encodings.empty?
@graph.encoding = "utf16"
Encoding::UTF_16LE
elsif encodings.include?(Constant::PositionEncodingKind::UTF8)
@graph.encoding = "utf8"
Encoding::UTF_8
elsif encodings.include?(Constant::PositionEncodingKind::UTF16)
@graph.encoding = "utf16"
Encoding::UTF_16LE
else
@graph.encoding = "utf32"
Encoding::UTF_32
end
@index.configuration.encoding = @encoding
Expand Down
16 changes: 12 additions & 4 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1226,12 +1226,18 @@ def shutdown

#: -> void
def perform_initial_indexing
progress("indexing-progress", message: "Indexing workspace...")
@global_state.graph.index_workspace

progress("indexing-progress", message: "Resolving graph...")
@global_state.graph.resolve

# The begin progress invocation happens during `initialize`, so that the notification is sent before we are
# stuck indexing files
Thread.new do
begin
@global_state.index.index_all do |percentage|
progress("indexing-progress", percentage)
progress("indexing-progress", percentage: percentage)
true
rescue ClosedQueueError
# Since we run indexing on a separate thread, it's possible to kill the server before indexing is complete.
Expand Down Expand Up @@ -1285,11 +1291,13 @@ def begin_progress(id, title, percentage: 0)
send_message(Notification.progress_begin(id, title, percentage: percentage, message: "#{percentage}% completed"))
end

#: (String id, Integer percentage) -> void
def progress(id, percentage)
#: (String, ?message: String?, ?percentage: Integer?) -> void
def progress(id, message: nil, percentage: nil)
return unless @global_state.client_capabilities.supports_progress

send_message(Notification.progress_report(id, percentage: percentage, message: "#{percentage}% completed"))
message ||= "#{percentage}% completed" if percentage

send_message(Notification.progress_report(id, percentage: percentage, message: message))
end

#: (String id) -> void
Expand Down
3 changes: 3 additions & 0 deletions lib/ruby_lsp/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def with_server(source = nil, uri = Kernel.URI("file:///fake.rb"), stub_no_typec
})

server.global_state.index.index_single(uri, source)
graph = server.global_state.graph
graph.index_source(uri.to_s, source, "ruby")
graph.resolve
end

server.load_addons(include_project_addons: false) if load_addons
Expand Down
Loading