Class: RubyLsp::Store
- Inherits:
-
Object
- Object
- RubyLsp::Store
- Extended by:
- T::Sig
- Defined in:
- lib/ruby_lsp/store.rb
Defined Under Namespace
Classes: NonExistingDocumentError
Instance Attribute Summary collapse
-
#client_name ⇒ Object
Returns the value of attribute client_name.
-
#features_configuration ⇒ Object
Returns the value of attribute features_configuration.
-
#supports_progress ⇒ Object
Returns the value of attribute supports_progress.
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:, language_id:, encoding: Encoding::UTF_8) ⇒ Object
Constructor Details
#initialize ⇒ Store
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_lsp/store.rb', line 20 def initialize @state = T.let({}, T::Hash[String, Document[T.untyped]]) @supports_progress = T.let(true, T::Boolean) @features_configuration = T.let( { inlayHint: RequestConfig.new({ enableAll: false, implicitRescue: false, implicitHashValue: false, }), }, T::Hash[Symbol, RequestConfig], ) @client_name = T.let("Unknown", String) end |
Instance Attribute Details
#client_name ⇒ Object
Returns the value of attribute client_name.
17 18 19 |
# File 'lib/ruby_lsp/store.rb', line 17 def client_name @client_name end |
#features_configuration ⇒ Object
Returns the value of attribute features_configuration.
14 15 16 |
# File 'lib/ruby_lsp/store.rb', line 14 def features_configuration @features_configuration end |
#supports_progress ⇒ Object
Returns the value of attribute supports_progress.
11 12 13 |
# File 'lib/ruby_lsp/store.rb', line 11 def supports_progress @supports_progress end |
Instance Method Details
#cache_fetch(uri, request_name, &block) ⇒ Object
110 111 112 |
# File 'lib/ruby_lsp/store.rb', line 110 def cache_fetch(uri, request_name, &block) get(uri).cache_fetch(request_name, &block) end |
#clear ⇒ Object
88 89 90 |
# File 'lib/ruby_lsp/store.rb', line 88 def clear @state.clear end |
#delete(uri) ⇒ Object
98 99 100 |
# File 'lib/ruby_lsp/store.rb', line 98 def delete(uri) @state.delete(uri.to_s) end |
#empty? ⇒ Boolean
93 94 95 |
# File 'lib/ruby_lsp/store.rb', line 93 def empty? @state.empty? end |
#get(uri) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ruby_lsp/store.rb', line 37 def get(uri) document = @state[uri.to_s] return document unless document.nil? # For unsaved files (`untitled:Untitled-1` uris), there's no path to read from. If we don't have the untitled file # already present in the store, then we have to raise non existing document error path = uri.to_standardized_path raise NonExistingDocumentError, uri.to_s unless path ext = File.extname(path) language_id = case ext when ".erb", ".rhtml" Document::LanguageId::ERB when ".rbs" Document::LanguageId::RBS else Document::LanguageId::Ruby end set(uri: uri, source: File.binread(path), version: 0, language_id: language_id) T.must(@state[uri.to_s]) rescue Errno::ENOENT raise NonExistingDocumentError, uri.to_s end |
#push_edits(uri:, edits:, version:) ⇒ Object
83 84 85 |
# File 'lib/ruby_lsp/store.rb', line 83 def push_edits(uri:, edits:, version:) T.must(@state[uri.to_s]).push_edits(edits, version: version) end |
#set(uri:, source:, version:, language_id:, encoding: Encoding::UTF_8) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/ruby_lsp/store.rb', line 71 def set(uri:, source:, version:, language_id:, encoding: Encoding::UTF_8) @state[uri.to_s] = case language_id when Document::LanguageId::ERB ERBDocument.new(source: source, version: version, uri: uri, encoding: encoding) when Document::LanguageId::RBS RBSDocument.new(source: source, version: version, uri: uri, encoding: encoding) else RubyDocument.new(source: source, version: version, uri: uri, encoding: encoding) end end |