Class: Rigor::LanguageServer::Server
- Inherits:
-
Object
- Object
- Rigor::LanguageServer::Server
- Defined in:
- lib/rigor/language_server/server.rb
Overview
LSP server lifecycle state machine + JSON-RPC method dispatcher. State machine: :uninitialized →
:initialized → :shutdown → :exited. #dispatch routes (method, params) to the matching handler and
returns the response payload (nil for notifications); out-of-state requests return InvalidRequest
(-32002) / MethodNotFound (-32601). Full v1 capability surface (document sync, publishDiagnostics,
hover, completion, sig-help, folding, selection, and watched-file invalidation) is implemented.
Constant Summary collapse
- ERROR_PARSE_ERROR =
JSON-RPC error codes per LSP spec § "Response Message".
-32_700
- ERROR_INVALID_REQUEST =
-32_600
- ERROR_METHOD_NOT_FOUND =
-32_601
- ERROR_INVALID_PARAMS =
-32_602
- ERROR_INTERNAL_ERROR =
-32_603 # LSP-specific reserved codes.
- ERROR_SERVER_NOT_INITIALIZED =
LSP-specific reserved codes.
-32_002
- ERROR_INVALID_REQUEST_AFTER_SHUTDOWN =
-32_600
- TEXT_DOCUMENT_SYNC_INCREMENTAL =
TextDocumentSyncKind::Incremental = 2:didChangecarries range edits, whichIncrementalSyncsplices into the buffer the table already holds instead of re-sending — and re-parsing — the whole document on every keystroke. The full-text entry form (acontentChangesentry with norange) stays legal under this mode and is still handled. 2- POSITION_ENCODING_UTF16 =
LSP
PositionEncodingKind. UTF-16 is the protocol default and the encodingIncrementalSyncdoes its offset arithmetic in; advertising it explicitly states the contract rather than leaving it implied. "utf-16"- PRE_INITIALIZE_METHODS =
Methods callable BEFORE
initialize. Per LSP spec § 3 onlyinitializeandexitare allowed pre-initialization; every other request returnsServerNotInitialized. We also acceptshutdownso a sequence likeinitialize → shutdown → exit(the conformance harness) round-trips even when the client skips real work. %w[initialize shutdown exit].freeze
Instance Attribute Summary collapse
-
#buffer_table ⇒ Object
readonly
Returns the value of attribute buffer_table.
-
#completion_provider ⇒ Object
readonly
Returns the value of attribute completion_provider.
-
#document_symbol_provider ⇒ Object
readonly
Returns the value of attribute document_symbol_provider.
-
#exit_code ⇒ Object
readonly
Returns the value of attribute exit_code.
-
#folding_range_provider ⇒ Object
readonly
Returns the value of attribute folding_range_provider.
-
#hover_provider ⇒ Object
readonly
Returns the value of attribute hover_provider.
-
#project_context ⇒ Object
readonly
Returns the value of attribute project_context.
-
#publisher ⇒ Object
readonly
Returns the value of attribute publisher.
-
#selection_range_provider ⇒ Object
readonly
Returns the value of attribute selection_range_provider.
-
#signature_help_provider ⇒ Object
readonly
Returns the value of attribute signature_help_provider.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#dispatch(method, params = nil) ⇒ Hash?
Routes one LSP method call.
-
#exited? ⇒ Boolean
True once the client has called
exitand the server has set its terminal exit code. -
#initialize(buffer_table: BufferTable.new, publisher: nil, hover_provider: nil, document_symbol_provider: nil, completion_provider: nil, signature_help_provider: nil, folding_range_provider: nil, selection_range_provider: nil, project_context: nil) ⇒ Server
constructor
A new instance of Server.
Constructor Details
#initialize(buffer_table: BufferTable.new, publisher: nil, hover_provider: nil, document_symbol_provider: nil, completion_provider: nil, signature_help_provider: nil, folding_range_provider: nil, selection_range_provider: nil, project_context: nil) ⇒ Server
Returns a new instance of Server.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rigor/language_server/server.rb', line 54 def initialize(buffer_table: BufferTable.new, publisher: nil, # rubocop:disable Metrics/ParameterLists hover_provider: nil, document_symbol_provider: nil, completion_provider: nil, signature_help_provider: nil, folding_range_provider: nil, selection_range_provider: nil, project_context: nil) @state = :uninitialized @exit_code = nil @buffer_table = buffer_table @publisher = publisher @hover_provider = hover_provider @document_symbol_provider = document_symbol_provider @completion_provider = completion_provider @signature_help_provider = signature_help_provider @folding_range_provider = folding_range_provider @selection_range_provider = selection_range_provider @project_context = project_context end |
Instance Attribute Details
#buffer_table ⇒ Object (readonly)
Returns the value of attribute buffer_table.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def buffer_table @buffer_table end |
#completion_provider ⇒ Object (readonly)
Returns the value of attribute completion_provider.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def completion_provider @completion_provider end |
#document_symbol_provider ⇒ Object (readonly)
Returns the value of attribute document_symbol_provider.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def document_symbol_provider @document_symbol_provider end |
#exit_code ⇒ Object (readonly)
Returns the value of attribute exit_code.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def exit_code @exit_code end |
#folding_range_provider ⇒ Object (readonly)
Returns the value of attribute folding_range_provider.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def folding_range_provider @folding_range_provider end |
#hover_provider ⇒ Object (readonly)
Returns the value of attribute hover_provider.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def hover_provider @hover_provider end |
#project_context ⇒ Object (readonly)
Returns the value of attribute project_context.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def project_context @project_context end |
#publisher ⇒ Object (readonly)
Returns the value of attribute publisher.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def publisher @publisher end |
#selection_range_provider ⇒ Object (readonly)
Returns the value of attribute selection_range_provider.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def selection_range_provider @selection_range_provider end |
#signature_help_provider ⇒ Object (readonly)
Returns the value of attribute signature_help_provider.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def signature_help_provider @signature_help_provider end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
40 41 42 |
# File 'lib/rigor/language_server/server.rb', line 40 def state @state end |
Instance Method Details
#dispatch(method, params = nil) ⇒ Hash?
Routes one LSP method call.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rigor/language_server/server.rb', line 88 def dispatch(method, params = nil) # rubocop:disable Metrics/CyclomaticComplexity return state_violation_response(method) unless method_allowed_in_state?(method) case method when "initialize" then handle_initialize(params) when "initialized" then handle_initialized when "shutdown" then handle_shutdown when "exit" then handle_exit when "textDocument/didOpen" then handle_did_open(params) when "textDocument/didChange" then handle_did_change(params) when "textDocument/didClose" then handle_did_close(params) when "textDocument/hover" then handle_hover(params) when "textDocument/documentSymbol" then handle_document_symbol(params) when "textDocument/completion" then handle_completion(params) when "textDocument/signatureHelp" then handle_signature_help(params) when "textDocument/foldingRange" then handle_folding_range(params) when "textDocument/selectionRange" then handle_selection_range(params) when "workspace/didChangeWatchedFiles" then handle_did_change_watched_files(params) when "workspace/didChangeConfiguration" then handle_did_change_configuration(params) else method_not_found(method) end end |
#exited? ⇒ Boolean
Returns true once the client has called exit and
the server has set its terminal exit code. The CLI loop
reads this between dispatches to know when to stop.
75 76 77 |
# File 'lib/rigor/language_server/server.rb', line 75 def exited? @state == :exited end |