Skip to content

Commit b8fa3fd

Browse files
authored
Merge pull request #225 from glennsarti/gh207
(GH-207) Allow Qualified Resource Names in hover provider
2 parents 9b41dcf + 01af3cb commit b8fa3fd

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

lib/puppet-languageserver/manifest/hover_provider.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ def self.resolve(content, line_num, char_num, options = {})
88
:tasks_mode => false
99
}.merge(options)
1010
result = PuppetLanguageServer::PuppetParserHelper.object_under_cursor(content, line_num, char_num,
11-
:disallowed_classes => [Puppet::Pops::Model::QualifiedName, Puppet::Pops::Model::BlockExpression],
11+
:disallowed_classes => [Puppet::Pops::Model::BlockExpression],
1212
:tasks_mode => options[:tasks_mode])
1313
return LSP::Hover.new if result.nil?
1414

1515
path = result[:path]
1616
item = result[:model]
1717

18+
# Munge the item
19+
# We're not really interested in the Name of thing yet, we want the "thing" it's a name of
20+
item = path.pop if item.instance_of?(Puppet::Pops::Model::QualifiedName) && !path.empty?
21+
1822
content = nil
1923
case item.class.to_s
2024
when 'Puppet::Pops::Model::ResourceExpression'
@@ -157,12 +161,15 @@ def self.get_call_named_function_expression_content(item, tasks_mode)
157161
end
158162

159163
def self.get_resource_expression_content(item)
164+
name = item.type_name.value
165+
# Strip top scope colons if found
166+
name = name[2..-1] if name.start_with?('::')
160167
# Get an instance of the type
161-
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.type_name.value)
168+
item_object = PuppetLanguageServer::PuppetHelper.get_type(name)
162169
return get_puppet_type_content(item_object) unless item_object.nil?
163-
item_object = PuppetLanguageServer::PuppetHelper.get_class(item.type_name.value)
170+
item_object = PuppetLanguageServer::PuppetHelper.get_class(name)
164171
return get_puppet_class_content(item_object) unless item_object.nil?
165-
raise "#{item.type_name.value} is not a valid puppet type"
172+
raise "#{name} is not a valid puppet type"
166173
end
167174

168175
def self.get_puppet_type_content(item_type)

spec/languageserver/integration/puppet-languageserver/manifest/hover_provider_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ class Test::WithParams (String $version = 'Bob') {
299299
attr_name1 => 'string1',
300300
attr_name2 => 'string1',
301301
}
302+
303+
::mock_workspace_class { 'Dah': }
302304
EOT
303305
}
304306

@@ -313,6 +315,17 @@ class Test::WithParams (String $version = 'Bob') {
313315
end
314316
end
315317

318+
describe 'when cursor is on the top-scoped resource type name' do
319+
let(:line_num) { 5 }
320+
let(:char_num) { 5 }
321+
322+
it 'should return resource description' do
323+
result = subject.resolve(content, line_num, char_num)
324+
325+
expect(result.contents).to start_with("**mock_workspace_class** Resource\n")
326+
end
327+
end
328+
316329
describe 'when cursor is on the name of the resource' do
317330
let(:line_num) { 0 }
318331
let(:char_num) { 26 }

0 commit comments

Comments
 (0)