Class: Rigor::LanguageServer::BufferTable
- Inherits:
-
Object
- Object
- Rigor::LanguageServer::BufferTable
- Defined in:
- lib/rigor/language_server/buffer_table.rb
Overview
Per-session virtual file table. The LSP server maintains the canonical view of every open buffer here; analysis (slice 4+) reads from this table instead of disk so in-flight edits are reflected immediately.
Keyed by ‘DocumentUri` (LSP `file://…` URIs). v1 ships FULL text sync (LSP `TextDocumentSyncKind::Full = 1`) so each `didChange` carries the entire buffer text — there’s no incremental edit application yet. Incremental sync is slice 10 (deferred per the design doc).
Defined Under Namespace
Classes: Entry
Instance Attribute Summary collapse
-
#bytes ⇒ Object
readonly
the current full text of the buffer.
-
#uri ⇒ Object
readonly
the LSP DocumentUri (e.g. ‘file:///abs/path/lib/foo.rb`).
-
#version ⇒ Object
readonly
the monotonically increasing LSP version number.
Instance Method Summary collapse
- #[](uri) ⇒ Object
-
#change(uri:, bytes:, version:) ⇒ Object
Records a ‘textDocument/didChange` event under FULL sync.
-
#close(uri:) ⇒ Object
Records a ‘textDocument/didClose` event.
-
#initialize ⇒ BufferTable
constructor
A new instance of BufferTable.
-
#open(uri:, bytes:, version:) ⇒ Object
Records a ‘textDocument/didOpen` event.
- #open?(uri) ⇒ Boolean
- #size ⇒ Object
- #uris ⇒ Object
Constructor Details
#initialize ⇒ BufferTable
Returns a new instance of BufferTable.
21 22 23 |
# File 'lib/rigor/language_server/buffer_table.rb', line 21 def initialize @entries = {} end |
Instance Attribute Details
#bytes ⇒ Object (readonly)
the current full text of the buffer.
19 |
# File 'lib/rigor/language_server/buffer_table.rb', line 19 Entry = Data.define(:uri, :bytes, :version) |
#uri ⇒ Object (readonly)
the LSP DocumentUri (e.g. ‘file:///abs/path/lib/foo.rb`).
19 |
# File 'lib/rigor/language_server/buffer_table.rb', line 19 Entry = Data.define(:uri, :bytes, :version) |
#version ⇒ Object (readonly)
the monotonically increasing LSP version number.
19 |
# File 'lib/rigor/language_server/buffer_table.rb', line 19 Entry = Data.define(:uri, :bytes, :version) |
Instance Method Details
#[](uri) ⇒ Object
46 47 48 |
# File 'lib/rigor/language_server/buffer_table.rb', line 46 def [](uri) @entries[uri] end |
#change(uri:, bytes:, version:) ⇒ Object
Records a ‘textDocument/didChange` event under FULL sync. The full new buffer text replaces the entry. If the client sends a `didChange` for a URI that was never opened (spec violation), the entry is still created — defensive.
36 37 38 |
# File 'lib/rigor/language_server/buffer_table.rb', line 36 def change(uri:, bytes:, version:) @entries[uri] = Entry.new(uri: uri, bytes: bytes, version: version) end |
#close(uri:) ⇒ Object
Records a ‘textDocument/didClose` event. The entry is removed. Subsequent reads via `#[]` return nil.
42 43 44 |
# File 'lib/rigor/language_server/buffer_table.rb', line 42 def close(uri:) @entries.delete(uri) end |
#open(uri:, bytes:, version:) ⇒ Object
Records a ‘textDocument/didOpen` event. Replaces any existing entry (LSP clients may re-open a previously closed URI; the new version is authoritative).
28 29 30 |
# File 'lib/rigor/language_server/buffer_table.rb', line 28 def open(uri:, bytes:, version:) @entries[uri] = Entry.new(uri: uri, bytes: bytes, version: version) end |
#open?(uri) ⇒ Boolean
50 51 52 |
# File 'lib/rigor/language_server/buffer_table.rb', line 50 def open?(uri) @entries.key?(uri) end |
#size ⇒ Object
54 55 56 |
# File 'lib/rigor/language_server/buffer_table.rb', line 54 def size @entries.size end |
#uris ⇒ Object
58 59 60 |
# File 'lib/rigor/language_server/buffer_table.rb', line 58 def uris @entries.keys end |