@@ -6,8 +6,8 @@ def self.instance
66 @instance ||= Helper . new
77 end
88
9- def self . file_documentation ( path , cache = nil )
10- instance . file_documentation ( path , cache )
9+ def self . file_documentation ( path , puppet_path , cache = nil )
10+ instance . file_documentation ( path , puppet_path , cache )
1111 end
1212
1313 def self . require_puppet_strings
@@ -40,7 +40,7 @@ class Helper
4040 # @param [String] path The absolute path to the file that will be documented
4141 # @param [PuppetLanguageServerSidecar::Cache] cache A Sidecar cache which stores already parsed documents as serialised FileDocumentation objects
4242 # @return [FileDocumentation, nil] Returns the documentation for the path, or nil if it cannot be extracted
43- def file_documentation ( path , cache = nil )
43+ def file_documentation ( path , puppet_path , cache = nil )
4444 return nil unless PuppetLanguageServerSidecar ::PuppetStringsHelper . require_puppet_strings
4545
4646 @helper_cache = FileDocumentationCache . new if @helper_cache . nil?
@@ -73,7 +73,7 @@ def file_documentation(path, cache = nil)
7373 ::YARD ::CLI ::Yardoc . run ( *args )
7474
7575 # Populate the documentation cache from the YARD information
76- @helper_cache . populate_from_yard_registry!
76+ @helper_cache . populate_from_yard_registry! ( puppet_path )
7777
7878 # Save to the permanent cache
7979 @helper_cache . save_to_sidecar_cache ( path , cache ) unless cache . nil? || !cache . active?
@@ -98,13 +98,13 @@ def document(path)
9898 @cache [ path ]
9999 end
100100
101- def populate_from_yard_registry!
101+ def populate_from_yard_registry! ( puppet_path )
102102 # Extract all of the information
103103 # Ref - https://github.com/puppetlabs/puppet-strings/blob/87a8e10f45bfeb7b6b8e766324bfb126de59f791/lib/puppet-strings/json.rb#L10-L16
104104 populate_classes_from_yard_registry!
105105 populate_data_types_from_yard_registry!
106106 populate_functions_from_yard_registry!
107- populate_types_from_yard_registry!
107+ populate_types_from_yard_registry! ( puppet_path )
108108 end
109109
110110 def populate_from_sidecar_cache! ( path , cache )
@@ -263,10 +263,10 @@ def populate_functions_from_yard_registry!
263263 end
264264 end
265265
266- def populate_types_from_yard_registry!
266+ def populate_types_from_yard_registry! ( puppet_path )
267267 ::YARD ::Registry . all ( :puppet_type ) . map ( &:to_hash ) . each do |item |
268- source_path = item [ :file ]
269268 type_name = item [ :name ] . to_s
269+ source_path = item [ :file ]
270270 @cache [ source_path ] = FileDocumentation . new ( source_path ) if @cache [ source_path ] . nil?
271271
272272 obj = PuppetLanguageServer ::Sidecar ::Protocol ::PuppetType . new
@@ -295,6 +295,13 @@ def populate_types_from_yard_registry!
295295 end
296296 end
297297
298+ if obj . key == 'file'
299+ # Special case for file type
300+ # we need to set the source and calling_source to the correct file definition
301+ path = File . join ( puppet_path , 'lib/puppet/type' )
302+ obj . source = "#{ path } /#{ obj . key } .rb"
303+ obj . calling_source = obj . source
304+ end
298305 @cache [ source_path ] . types << obj
299306 end
300307 end
0 commit comments