Skip to content

Commit

Permalink
TMP
Browse files Browse the repository at this point in the history
Co-authored-by: Ufuk Kayserilioglu <[email protected]>
  • Loading branch information
Morriar and paracycle committed Jul 26, 2023
1 parent 22d2935 commit 2f518f8
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/ruby_lsp/executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def run(request)
request.dig(:params, :contentChanges),
request.dig(:params, :textDocument, :version),
)
when "textDocument/didSave"
text_document_did_save(uri)
when "textDocument/foldingRange"
folding_range(uri)
when "textDocument/selectionRange"
Expand Down Expand Up @@ -169,6 +171,8 @@ def run(request)
completion(uri, request.dig(:params, :position))
when "textDocument/definition"
definition(uri, request.dig(:params, :position))
# when "workspace/diagnostic"
# workspace_diagnostic(uri)
when "rubyLsp/textDocument/showSyntaxTree"
{ ast: Requests::ShowSyntaxTree.new(@store.get(uri)).run }
end
Expand Down Expand Up @@ -240,6 +244,15 @@ def text_document_did_close(uri)
VOID
end

sig { params(uri: String).returns(Object) }
def text_document_did_save(uri)
Requests::DocumentSave.listeners.each do |listener|
instance = listener.new(EventEmitter.new, @message_queue)
instance.response
end
VOID
end

sig do
params(
uri: String,
Expand Down Expand Up @@ -428,6 +441,16 @@ def completion(uri, position)
listener.response
end

# sig { params(previous_result_ids: T::Array[T::Hash[Symbol, String]]).returns(Interface::WorkspaceDiagnosticReport) }
# def workspace_diagnostic(previous_result_ids)
# Requests::WorkspaceDiagnostic.listeners.each do |listener|
# instance = listener.new(EventEmitter.new, @message_queue)
# return instance.response
# end

# T.unsafe(nil)
# end

sig { params(options: T::Hash[Symbol, T.untyped]).returns(Interface::InitializeResult) }
def initialize_request(options)
@store.clear
Expand Down Expand Up @@ -507,7 +530,7 @@ def initialize_request(options)
diagnostics_provider = if enabled_features["diagnostics"]
{
interFileDependencies: false,
workspaceDiagnostics: false,
workspaceDiagnostics: true,
}
end

Expand Down Expand Up @@ -538,6 +561,7 @@ def initialize_request(options)
text_document_sync: Interface::TextDocumentSyncOptions.new(
change: Constant::TextDocumentSyncKind::INCREMENTAL,
open_close: true,
save: true,
),
position_encoding: @store.encoding,
selection_range_provider: enabled_features["selectionRanges"],
Expand Down
1 change: 1 addition & 0 deletions lib/ruby_lsp/requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Requests
autoload :BaseRequest, "ruby_lsp/requests/base_request"
autoload :DocumentSymbol, "ruby_lsp/requests/document_symbol"
autoload :DocumentLink, "ruby_lsp/requests/document_link"
autoload :DocumentSave, "ruby_lsp/requests/document_save"
autoload :Hover, "ruby_lsp/requests/hover"
autoload :FoldingRanges, "ruby_lsp/requests/folding_ranges"
autoload :SelectionRanges, "ruby_lsp/requests/selection_ranges"
Expand Down
27 changes: 27 additions & 0 deletions lib/ruby_lsp/requests/document_save.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# typed: strict
# frozen_string_literal: true

module RubyLsp
module Requests
class DocumentSave < Listener
extend T::Sig

ResponseType = type_member { { fixed: T.untyped } }

sig { override.returns(ResponseType) }
attr_reader :response

sig do
params(
emitter: EventEmitter,
message_queue: Thread::Queue,
).void
end
def initialize(emitter, message_queue)
super(emitter, message_queue)

@response = T.let(VOID, Object)
end
end
end
end

0 comments on commit 2f518f8

Please sign in to comment.