Class: RubyLsp::Store
- Inherits:
-
Object
- Object
- RubyLsp::Store
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/store.rb
Instance Method Summary collapse
- #cache_fetch(uri, request_name, &block) ⇒ Object
- #clear ⇒ Object
- #delete(uri) ⇒ Object
- #get(uri) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #push_edits(uri, edits) ⇒ Object
- #set(uri, content) ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
13 14 15 |
# File 'lib/ruby_lsp/store.rb', line 13 def initialize @state = T.let({}, T::Hash[String, Document]) end |
Instance Method Details
#cache_fetch(uri, request_name, &block) ⇒ Object
56 57 58 |
# File 'lib/ruby_lsp/store.rb', line 56 def cache_fetch(uri, request_name, &block) get(uri).cache_fetch(request_name, &block) end |
#clear ⇒ Object
39 40 41 |
# File 'lib/ruby_lsp/store.rb', line 39 def clear @state.clear end |
#delete(uri) ⇒ Object
44 45 46 |
# File 'lib/ruby_lsp/store.rb', line 44 def delete(uri) @state.delete(uri) end |
#get(uri) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/ruby_lsp/store.rb', line 18 def get(uri) document = @state[uri] return document unless document.nil? set(uri, File.binread(CGI.unescape(URI.parse(uri).path))) T.must(@state[uri]) end |
#push_edits(uri, edits) ⇒ Object
34 35 36 |
# File 'lib/ruby_lsp/store.rb', line 34 def push_edits(uri, edits) T.must(@state[uri]).push_edits(edits) end |
#set(uri, content) ⇒ Object
27 28 29 30 31 |
# File 'lib/ruby_lsp/store.rb', line 27 def set(uri, content) @state[uri] = Document.new(content) rescue SyntaxTree::Parser::ParseError # Do not update the store if there are syntax errors end |