diff --git a/lib/puppet-languageserver-sidecar/puppet_helper.rb b/lib/puppet-languageserver-sidecar/puppet_helper.rb index edd62df4..df11bcd0 100644 --- a/lib/puppet-languageserver-sidecar/puppet_helper.rb +++ b/lib/puppet-languageserver-sidecar/puppet_helper.rb @@ -107,7 +107,16 @@ def self.retrieve_via_puppet_strings(cache, options = {}) next unless object_types.include?(:type) file_doc.types.each do |item| - result.append!(item) unless name == 'whit' || name == 'component' + if item.key == 'file' + search_root = File.expand_path(finder.puppet_path) + path = File.join(search_root, 'lib/puppet/type') + # Manually set the source and calling_source for the file type + item.source = "#{path}/#{item.key}.rb" + item.calling_source = item.source + # Remove the temp_file.rb if it exists + File.delete(finder.temp_file) if File.exist?(finder.temp_file) + end + result.append!(item) unless %w[whit component].include?(item.key) end end @@ -153,6 +162,7 @@ def self.current_environment # DataType ruby files or manifests. class PuppetPathFinder attr_reader :object_types + attr_accessor :puppet_path, :temp_file # @param puppet_env [Puppet::Node::Environment] The environment to search within # @param object_types [Symbol] The types of objects that will be searched for. See available_documentation_types for the complete list @@ -212,12 +222,25 @@ def find(from_root_path = nil) PuppetLanguageServerSidecar.log_message(:debug, "[PuppetPathFinder] Searching glob '#{glob}''") Dir.glob(glob) do |filename| - paths << filename + # if filename matches file.rb or file/ then we need to loop through each file type definition + if filename.match?(%r{/file/|file.rb}) + # Create a temp file to store the file type definitions + @temp_file = 'temp_file.rb' + # Open the temp file and write the file type definitions to it + File.open(@temp_file, 'a') do |f| + # Read each file type definition and write it to the temp file + PuppetLanguageServerSidecar.log_message(:debug, "[PuppetPathFinder] Found file type definition at '#{filename}'.") + f.puts(File.read(filename)) + end + else + paths << filename + end end end end end - + # Add the temp_file.rb to the paths array for searching (if exists) + paths << @temp_file if @temp_file && File.exist?(@temp_file) paths end @@ -258,7 +281,7 @@ def all_object_info { relative_dir: 'lib/puppet/parser/functions', glob: '/**/*.rb' } # Contains functions written in Ruby for the legacy Puppet::Parser::Functions API ], type: [ - { relative_dir: 'lib/puppet/type', glob: '/*.rb' } # Contains Puppet resource types. We don't care about providers. Types cannot exist in subdirs + { relative_dir: 'lib/puppet/type', glob: '/{,*/}*.rb' }, # Contains Puppet resource types. Resource types like `file` can live in subdirs, hence the glob ] } end