Class: RubyLsp::Store
- Inherits:
-
Object
- Object
- RubyLsp::Store
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/store.rb
Instance Attribute Summary collapse
-
#encoding ⇒ Object
Returns the value of attribute encoding.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
Instance Method Summary collapse
- #cache_fetch(uri, request_name, &block) ⇒ Object
- #clear ⇒ Object
- #delete(uri) ⇒ Object
- #empty? ⇒ Boolean
- #get(uri) ⇒ Object
-
#initialize ⇒ Store
constructor
A new instance of Store.
- #push_edits(uri:, edits:, version:) ⇒ Object
- #set(uri:, source:, version:) ⇒ Object
Constructor Details
#initialize ⇒ Store
Returns a new instance of Store.
17 18 19 20 21 |
# File 'lib/ruby_lsp/store.rb', line 17 def initialize @state = T.let({}, T::Hash[String, Document]) @encoding = T.let(Constant::PositionEncodingKind::UTF8, String) @formatter = T.let("auto", String) end |
Instance Attribute Details
#encoding ⇒ Object
Returns the value of attribute encoding.
11 12 13 |
# File 'lib/ruby_lsp/store.rb', line 11 def encoding @encoding end |
#formatter ⇒ Object
Returns the value of attribute formatter.
14 15 16 |
# File 'lib/ruby_lsp/store.rb', line 14 def formatter @formatter end |
Instance Method Details
#cache_fetch(uri, request_name, &block) ⇒ Object
69 70 71 |
# File 'lib/ruby_lsp/store.rb', line 69 def cache_fetch(uri, request_name, &block) get(uri).cache_fetch(request_name, &block) end |
#clear ⇒ Object
47 48 49 |
# File 'lib/ruby_lsp/store.rb', line 47 def clear @state.clear end |
#delete(uri) ⇒ Object
57 58 59 |
# File 'lib/ruby_lsp/store.rb', line 57 def delete(uri) @state.delete(uri.storage_key) end |
#empty? ⇒ Boolean
52 53 54 |
# File 'lib/ruby_lsp/store.rb', line 52 def empty? @state.empty? end |
#get(uri) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ruby_lsp/store.rb', line 24 def get(uri) path = uri.to_standardized_path return T.must(@state[T.must(uri.opaque)]) unless path document = @state[path] return document unless document.nil? set(uri: uri, source: File.binread(CGI.unescape(path)), version: 0) T.must(@state[path]) end |
#push_edits(uri:, edits:, version:) ⇒ Object
42 43 44 |
# File 'lib/ruby_lsp/store.rb', line 42 def push_edits(uri:, edits:, version:) T.must(@state[uri.storage_key]).push_edits(edits, version: version) end |
#set(uri:, source:, version:) ⇒ Object
36 37 38 39 |
# File 'lib/ruby_lsp/store.rb', line 36 def set(uri:, source:, version:) document = Document.new(source: source, version: version, uri: uri, encoding: @encoding) @state[uri.storage_key] = document end |