Class: RubyLsp::Server
- Inherits:
-
BaseServer
- Object
- BaseServer
- RubyLsp::Server
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/server.rb
Instance Attribute Summary collapse
-
#global_state ⇒ Object
readonly
Returns the value of attribute global_state.
Instance Method Summary collapse
-
#initialize(test_mode: false) ⇒ Server
constructor
A new instance of Server.
- #load_addons ⇒ Object
- #process_message(message) ⇒ Object
Methods inherited from BaseServer
#new_worker, #pop_response, #run_shutdown, #send_empty_response, #send_log_message, #send_message, #start
Constructor Details
#initialize(test_mode: false) ⇒ Server
13 14 15 16 |
# File 'lib/ruby_lsp/server.rb', line 13 def initialize(test_mode: false) super @global_state = T.let(GlobalState.new, GlobalState) end |
Instance Attribute Details
#global_state ⇒ Object (readonly)
Returns the value of attribute global_state.
10 11 12 |
# File 'lib/ruby_lsp/server.rb', line 10 def global_state @global_state end |
Instance Method Details
#load_addons ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ruby_lsp/server.rb', line 128 def load_addons errors = Addon.load_addons(@global_state, @outgoing_queue) if errors.any? ( "Error loading addons:\n\n#{errors.map(&:full_message).join("\n\n")}", type: Constant::MessageType::WARNING, ) end errored_addons = Addon.addons.select(&:error?) if errored_addons.any? ( Notification.new( method: "window/showMessage", params: Interface::ShowMessageParams.new( type: Constant::MessageType::WARNING, message: "Error loading addons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}", ), ), ) unless @test_mode ( errored_addons.map(&:errors_details).join("\n\n"), type: Constant::MessageType::WARNING, ) end end end |
#process_message(message) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/ruby_lsp/server.rb', line 19 def () case [:method] when "initialize" ("Initializing Ruby LSP v#{VERSION}...") run_initialize() when "initialized" ("Finished initializing Ruby LSP!") unless @test_mode run_initialized when "textDocument/didOpen" text_document_did_open() when "textDocument/didClose" text_document_did_close() when "textDocument/didChange" text_document_did_change() when "textDocument/selectionRange" text_document_selection_range() when "textDocument/documentSymbol" text_document_document_symbol() when "textDocument/documentLink" text_document_document_link() when "textDocument/codeLens" text_document_code_lens() when "textDocument/semanticTokens/full" text_document_semantic_tokens_full() when "textDocument/foldingRange" text_document_folding_range() when "textDocument/semanticTokens/range" text_document_semantic_tokens_range() when "textDocument/formatting" text_document_formatting() when "textDocument/documentHighlight" text_document_document_highlight() when "textDocument/onTypeFormatting" text_document_on_type_formatting() when "textDocument/hover" text_document_hover() when "textDocument/inlayHint" text_document_inlay_hint() when "textDocument/codeAction" text_document_code_action() when "codeAction/resolve" code_action_resolve() when "textDocument/diagnostic" text_document_diagnostic() when "textDocument/completion" text_document_completion() when "completionItem/resolve" text_document_completion_item_resolve() when "textDocument/signatureHelp" text_document_signature_help() when "textDocument/definition" text_document_definition() when "textDocument/prepareTypeHierarchy" text_document_prepare_type_hierarchy() when "typeHierarchy/supertypes" type_hierarchy_supertypes() when "typeHierarchy/subtypes" type_hierarchy_subtypes() when "workspace/didChangeWatchedFiles" workspace_did_change_watched_files() when "workspace/symbol" workspace_symbol() when "rubyLsp/textDocument/showSyntaxTree" text_document_show_syntax_tree() when "rubyLsp/workspace/dependencies" workspace_dependencies() when "rubyLsp/workspace/addons" ( Result.new( id: [:id], response: Addon.addons.map do |addon| { name: addon.name, errored: addon.error? } end, ), ) when "$/cancelRequest" @mutex.synchronize { @cancelled_requests << [:params][:id] } end rescue StandardError, LoadError => e # If an error occurred in a request, we have to return an error response or else the editor will hang if [:id] # If a document is deleted before we are able to process all of its enqueued requests, we will try to read it # from disk and it raise this error. This is expected, so we don't include the `data` attribute to avoid # reporting these to our telemetry if e.is_a?(Store::NonExistingDocumentError) (Error.new( id: [:id], code: Constant::ErrorCodes::INVALID_PARAMS, message: e., )) else (Error.new( id: [:id], code: Constant::ErrorCodes::INTERNAL_ERROR, message: e., data: { errorClass: e.class.name, errorMessage: e., backtrace: e.backtrace&.join("\n"), }, )) end end ("Error processing #{message[:method]}: #{e.full_message}", type: Constant::MessageType::ERROR) end |