Class: Browsable::LSP::Server
- Inherits:
-
Object
- Object
- Browsable::LSP::Server
- Defined in:
- lib/browsable/lsp/server.rb
Overview
The JSON-RPC server loop.
Reads LSP messages from stdin, dispatches them to handlers, and writes responses and diagnostics back to stdout — the standard stdio LSP convention. All compatibility analysis is delegated to the browsable gem; this class only speaks the protocol.
Instance Method Summary collapse
-
#initialize(input: $stdin, output: $stdout) ⇒ Server
constructor
A new instance of Server.
-
#publish_diagnostics(uri, content) ⇒ Object
Audit ‘content` and push its diagnostics to the client.
-
#start ⇒ Object
Block reading messages until the client disconnects or sends ‘exit`.
-
#store(uri, content) ⇒ Object
Cache the latest known contents of a document.
Constructor Details
#initialize(input: $stdin, output: $stdout) ⇒ Server
Returns a new instance of Server.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/browsable/lsp/server.rb', line 12 def initialize(input: $stdin, output: $stdout) # Io::Reader/Writer take an explicit IO (the Stdio:: subclasses hard-code # STDIN/STDOUT); passing $stdin/$stdout keeps the default behaviour while # letting tests drive the server over StringIO pipes. @reader = ::LanguageServer::Protocol::Transport::Io::Reader.new(input) @writer = ::LanguageServer::Protocol::Transport::Io::Writer.new(output) @documents = {} @workspace_root = Dir.pwd @shutdown_requested = false end |
Instance Method Details
#publish_diagnostics(uri, content) ⇒ Object
Audit ‘content` and push its diagnostics to the client.
34 35 36 37 |
# File 'lib/browsable/lsp/server.rb', line 34 def publish_diagnostics(uri, content) diagnostics = Diagnostics.for(uri: uri, content: content, root: @workspace_root) notify("textDocument/publishDiagnostics", { uri: uri, diagnostics: diagnostics }) end |
#start ⇒ Object
Block reading messages until the client disconnects or sends ‘exit`.
24 25 26 |
# File 'lib/browsable/lsp/server.rb', line 24 def start @reader.read { || dispatch(normalize()) } end |
#store(uri, content) ⇒ Object
Cache the latest known contents of a document.
29 30 31 |
# File 'lib/browsable/lsp/server.rb', line 29 def store(uri, content) @documents[uri] = content end |