6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/puppet-languageserver/manifest/definition_provider.rb', line 6
def self.find_definition(session_state, content, line_num, char_num, options = {})
options = {
tasks_mode: false
}.merge(options)
result = PuppetLanguageServer::PuppetParserHelper.object_under_cursor(content, line_num, char_num,
disallowed_classes: [Puppet::Pops::Model::BlockExpression],
tasks_mode: options[:tasks_mode])
return nil if result.nil?
path = result[:path]
item = result[:model]
response = []
case item.class.to_s
when 'Puppet::Pops::Model::CallNamedFunctionExpression'
func_name = item.functor_expr.value
response << function_name(session_state, func_name)
when 'Puppet::Pops::Model::LiteralString'
parent = path.last
if !parent.nil? &&
parent.instance_of?(::Puppet::Pops::Model::ResourceBody) &&
parent.title.value == item.value
resource_name = item.value
response << type_or_class(session_state, resource_name)
end
when 'Puppet::Pops::Model::QualifiedName'
parent = path.last
if !parent.nil? &&
parent.instance_of?(::Puppet::Pops::Model::CallNamedFunctionExpression) &&
parent.functor_expr.value == item.value
func_name = item.value
response << function_name(session_state, func_name)
end
if !parent.nil? && parent.instance_of?(::Puppet::Pops::Model::CallNamedFunctionExpression) && parent.functor_expr.value == 'include'
resource_name = item.value
response << type_or_class(session_state, resource_name)
end
if !parent.nil? && parent.instance_of?(::Puppet::Pops::Model::ResourceExpression)
resource_name = item.value
response << type_or_class(session_state, resource_name)
end
when 'Puppet::Pops::Model::ResourceExpression'
resource_name = item.type_name.value
response << type_or_class(session_state, resource_name)
else
raise "Unable to generate Defintion information for object of type #{item.class}"
end
response.compact
end
|