Class: PuppetLanguageServer::SessionState::DocumentStore
- Inherits:
-
Object
- Object
- PuppetLanguageServer::SessionState::DocumentStore
- Defined in:
- lib/puppet-languageserver/session_state/document_store.rb
Instance Method Summary collapse
- #clear ⇒ Object
- #document(uri, doc_version = nil) ⇒ Object
- #document_content(uri, doc_version = nil) ⇒ Object
- #document_tokens(uri, doc_version = nil) ⇒ Object
- #document_type(uri) ⇒ Object
- #document_uris ⇒ Object
- #document_version(uri) ⇒ Object
- #expire_store_information ⇒ Object
- #get_document(uri) ⇒ Object
-
#initialize(_options = {}) ⇒ DocumentStore
constructor
A new instance of DocumentStore.
- #initialize_store(options = {}) ⇒ Object
-
#plan_file?(uri) ⇒ Boolean
Plan files puppet.com/docs/bolt/1.x/writing_plans.html#concept-4485 can exist in many places The current best detection method is as follows: “Given the full path to the .pp file, if it contains a directory called plans, AND that plans is not a sub-directory of manifests, then it is a plan file”.
- #remove_document(uri) ⇒ Object
- #set_document(uri, content, doc_version) ⇒ Object
- #store_has_environmentconf? ⇒ Boolean
- #store_has_module_metadata? ⇒ Boolean
- #store_root_path ⇒ Object
Constructor Details
#initialize(_options = {}) ⇒ DocumentStore
Returns a new instance of DocumentStore.
49 50 51 52 53 54 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 49 def initialize( = {}) @documents = {} @doc_mutex = Mutex.new initialize_store end |
Instance Method Details
#clear ⇒ Object
71 72 73 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 71 def clear @doc_mutex.synchronize { @documents.clear } end |
#document(uri, doc_version = nil) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 75 def document(uri, doc_version = nil) @doc_mutex.synchronize do return nil if @documents[uri].nil? return nil unless doc_version.nil? || @documents[uri].version == doc_version @documents[uri] end end |
#document_content(uri, doc_version = nil) ⇒ Object
84 85 86 87 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 84 def document_content(uri, doc_version = nil) doc = document(uri, doc_version) doc.nil? ? nil : doc.content.clone end |
#document_tokens(uri, doc_version = nil) ⇒ Object
94 95 96 97 98 99 100 101 102 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 94 def document_tokens(uri, doc_version = nil) @doc_mutex.synchronize do return nil if @documents[uri].nil? return nil unless doc_version.nil? || @documents[uri].version == doc_version return @documents[uri].tokens unless @documents[uri].tokens.nil? return @documents[uri].calculate_tokens! end end |
#document_type(uri) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 113 def document_type(uri) case uri when %r{/Puppetfile$}i :puppetfile when /\.pp$/i :manifest when /\.epp$/i :epp else :unknown end end |
#document_uris ⇒ Object
109 110 111 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 109 def document_uris @doc_mutex.synchronize { @documents.keys.dup } end |
#document_version(uri) ⇒ Object
104 105 106 107 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 104 def document_version(uri) doc = document(uri) doc.nil? ? nil : doc.version end |
#expire_store_information ⇒ Object
160 161 162 163 164 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 160 def expire_store_information @doc_mutex.synchronize do @workspace_info_cache[:expires] = Time.new - 120 end end |
#get_document(uri) ⇒ Object
89 90 91 92 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 89 def get_document(uri) doc = @documents[uri] doc.nil? ? nil : doc.content.clone end |
#initialize_store(options = {}) ⇒ Object
153 154 155 156 157 158 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 153 def initialize_store( = {}) @workspace_path = [:workspace] @workspace_info_cache = { expires: Time.new - 120 } end |
#plan_file?(uri) ⇒ Boolean
Plan files puppet.com/docs/bolt/1.x/writing_plans.html#concept-4485 can exist in many places The current best detection method is as follows: “Given the full path to the .pp file, if it contains a directory called plans, AND that plans is not a sub-directory of manifests, then it is a plan file”
See github.com/lingua-pupuli/puppet-editor-services/issues/129 for the full discussion
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 131 def plan_file?(uri) uri_path = PuppetLanguageServer::UriHelper.uri_path(uri) return false if uri_path.nil? # For the text searching below we need a leading slash. That way # we don't need to use regexes which is slower uri_path = "/#{uri_path}" unless uri_path.start_with?('/') if windows? plans_index = uri_path.upcase.index('/PLANS/') manifests_index = uri_path.upcase.index('/MANIFESTS/') else plans_index = uri_path.index('/plans/') manifests_index = uri_path.index('/manifests/') end return false if plans_index.nil? return true if manifests_index.nil? plans_index < manifests_index end |
#remove_document(uri) ⇒ Object
66 67 68 69 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 66 def remove_document(uri) @doc_mutex.synchronize { @documents.delete(uri) } nil end |
#set_document(uri, content, doc_version) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 56 def set_document(uri, content, doc_version) @doc_mutex.synchronize do if @documents[uri].nil? @documents[uri] = create_document(uri, content, doc_version) else @documents[uri].update(content, doc_version) end end end |
#store_has_environmentconf? ⇒ Boolean
174 175 176 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 174 def store_has_environmentconf? store_details[:has_environmentconf] end |
#store_has_module_metadata? ⇒ Boolean
170 171 172 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 170 def store_details[:has_metadatajson] end |
#store_root_path ⇒ Object
166 167 168 |
# File 'lib/puppet-languageserver/session_state/document_store.rb', line 166 def store_root_path store_details[:root_path] end |