Class: RubyLsp::Server
- Inherits:
-
BaseServer
- Object
- BaseServer
- RubyLsp::Server
- Defined in:
- lib/ruby_lsp/server.rb
Instance Attribute Summary collapse
-
#global_state ⇒ Object
readonly
Only for testing : GlobalState.
Instance Method Summary collapse
-
#load_addons(include_project_addons: true) ⇒ Object
: (?include_project_addons: bool) -> void.
-
#process_message(message) ⇒ Object
: (Hash[Symbol, untyped] message) -> void.
-
#process_response(message) ⇒ Object
Process responses to requests that were sent to the client : (Hash[Symbol, untyped] message) -> void.
Methods inherited from BaseServer
#initialize, #pop_response, #push_message, #run_shutdown, #start, #test_mode?
Constructor Details
This class inherits a constructor from RubyLsp::BaseServer
Instance Attribute Details
#global_state ⇒ Object (readonly)
Only for testing : GlobalState
8 9 10 |
# File 'lib/ruby_lsp/server.rb', line 8 def global_state @global_state end |
Instance Method Details
#load_addons(include_project_addons: true) ⇒ Object
: (?include_project_addons: bool) -> void
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ruby_lsp/server.rb', line 167 def load_addons(include_project_addons: true) # If invoking Bundler.setup failed, then the load path will not be configured properly and trying to load add-ons # with Gem.find_files will find every single version installed of an add-on, leading to requiring several # different versions of the same files. We cannot load add-ons if Bundler.setup failed return if @setup_error errors = Addon.load_addons(@global_state, @outgoing_queue, include_project_addons: include_project_addons) return if test_mode? 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.( "Error loading add-ons:\n\n#{errored_addons.map(&:formatted_errors).join("\n\n")}", type: Constant::MessageType::WARNING, ), ) (errored_addons.map(&:errors_details).join("\n\n"), type: Constant::MessageType::WARNING) end end |
#process_message(message) ⇒ Object
: (Hash[Symbol, untyped] message) -> void
12 13 14 15 16 17 18 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 126 127 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 |
# File 'lib/ruby_lsp/server.rb', line 12 def () case [:method] when "initialize" ("Initializing Ruby LSP v#{VERSION} https://github.com/Shopify/ruby-lsp/releases/tag/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 "codeLens/resolve" code_lens_resolve() when "textDocument/semanticTokens/full" text_document_semantic_tokens_full() when "textDocument/semanticTokens/full/delta" text_document_semantic_tokens_delta() when "textDocument/foldingRange" text_document_folding_range() when "textDocument/semanticTokens/range" text_document_semantic_tokens_range() when "textDocument/formatting" text_document_formatting() when "textDocument/rangeFormatting" text_document_range_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 "textDocument/rename" text_document_rename() when "textDocument/prepareRename" text_document_prepare_rename() when "textDocument/references" text_document_references() 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| version = begin addon.version rescue AbstractMethodInvokedError nil end { name: addon.name, version: version, errored: addon.error? } end, ), ) when "rubyLsp/composeBundle" compose_bundle() when "rubyLsp/diagnoseState" diagnose_state() when "rubyLsp/discoverTests" discover_tests() when "rubyLsp/resolveTestCommands" resolve_test_commands() when "experimental/goToRelevantFile" experimental_go_to_relevant_file() when "$/cancelRequest" @global_state.synchronize { @cancelled_requests << [:params][:id] } when nil process_response() if [:result] end rescue DelegateRequestError (Error.new(id: [:id], code: DelegateRequestError::CODE, message: "DELEGATE_REQUEST")) rescue StandardError, LoadError, SystemExit => 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. # # Similarly, if we receive a location for an invalid position in the # document, we don't report it to telemetry case e when Store::NonExistingDocumentError, Document::InvalidLocationError (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 |
#process_response(message) ⇒ Object
Process responses to requests that were sent to the client : (Hash[Symbol, untyped] message) -> void
159 160 161 162 163 164 |
# File 'lib/ruby_lsp/server.rb', line 159 def process_response() case .dig(:result, :method) when "window/showMessageRequest" () end end |