Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/puppet-languageserver/manifest/hover_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@ def self.resolve(content, line_num, char_num, options = {})
:tasks_mode => false
}.merge(options)
result = PuppetLanguageServer::PuppetParserHelper.object_under_cursor(content, line_num, char_num,
:disallowed_classes => [Puppet::Pops::Model::QualifiedName, Puppet::Pops::Model::BlockExpression],
:disallowed_classes => [Puppet::Pops::Model::BlockExpression],
:tasks_mode => options[:tasks_mode])
return LSP::Hover.new if result.nil?

path = result[:path]
item = result[:model]

# Munge the item
# We're not really interested in the Name of thing yet, we want the "thing" it's a name of
item = path.pop if item.instance_of?(Puppet::Pops::Model::QualifiedName) && !path.empty?

content = nil
case item.class.to_s
when 'Puppet::Pops::Model::ResourceExpression'
Expand Down Expand Up @@ -157,12 +161,15 @@ def self.get_call_named_function_expression_content(item, tasks_mode)
end

def self.get_resource_expression_content(item)
name = item.type_name.value
# Strip top scope colons if found
name = name[2..-1] if name.start_with?('::')
# Get an instance of the type
item_object = PuppetLanguageServer::PuppetHelper.get_type(item.type_name.value)
item_object = PuppetLanguageServer::PuppetHelper.get_type(name)
return get_puppet_type_content(item_object) unless item_object.nil?
item_object = PuppetLanguageServer::PuppetHelper.get_class(item.type_name.value)
item_object = PuppetLanguageServer::PuppetHelper.get_class(name)
return get_puppet_class_content(item_object) unless item_object.nil?
raise "#{item.type_name.value} is not a valid puppet type"
raise "#{name} is not a valid puppet type"
end

def self.get_puppet_type_content(item_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ class Test::WithParams (String $version = 'Bob') {
attr_name1 => 'string1',
attr_name2 => 'string1',
}

::mock_workspace_class { 'Dah': }
EOT
}

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

describe 'when cursor is on the top-scoped resource type name' do
let(:line_num) { 5 }
let(:char_num) { 5 }

it 'should return resource description' do
result = subject.resolve(content, line_num, char_num)

expect(result.contents).to start_with("**mock_workspace_class** Resource\n")
end
end

describe 'when cursor is on the name of the resource' do
let(:line_num) { 0 }
let(:char_num) { 26 }
Expand Down