Class: PuppetLanguageServerSidecar::FileDocumentationCache

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-languageserver-sidecar/puppet_strings_helper.rb

Instance Method Summary collapse

Constructor Details

#initializeFileDocumentationCache

Returns a new instance of FileDocumentationCache.



88
89
90
91
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 88

def initialize
  # Hash of <[String] path, FileDocumentation> objects
  @cache = {}
end

Instance Method Details

#document(path) ⇒ Object



97
98
99
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 97

def document(path)
  @cache[path]
end

#path_exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 93

def path_exists?(path)
  @cache.key?(path)
end

#populate_from_sidecar_cache!(path, cache) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 110

def populate_from_sidecar_cache!(path, cache)
  cached_result = cache.load(path, PuppetLanguageServerSidecar::Cache::PUPPETSTRINGS_SECTION)
  unless cached_result.nil? # rubocop:disable Style/GuardClause    Reads better this way
    begin
      obj = FileDocumentation.new.from_json!(cached_result)
      @cache[path] = obj
    rescue StandardError => e
      PuppetLanguageServerSidecar.log_message(:warn, "[FileDocumentationCache::populate_from_sidecar_cache!] Error while deserializing #{path} from cache: #{e}")
    end
  end
end

#populate_from_yard_registry!(puppet_path) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 101

def populate_from_yard_registry!(puppet_path)
  # Extract all of the information
  # Ref - https://github.com/puppetlabs/puppet-strings/blob/87a8e10f45bfeb7b6b8e766324bfb126de59f791/lib/puppet-strings/json.rb#L10-L16
  populate_classes_from_yard_registry!
  populate_data_types_from_yard_registry!
  populate_functions_from_yard_registry!
  populate_types_from_yard_registry!(puppet_path)
end

#save_to_sidecar_cache(path, cache) ⇒ Object



122
123
124
# File 'lib/puppet-languageserver-sidecar/puppet_strings_helper.rb', line 122

def save_to_sidecar_cache(path, cache)
  cache.save(path, PuppetLanguageServerSidecar::Cache::PUPPETSTRINGS_SECTION, document(path).to_json) if cache.active?
end