puppetlabs / puppet-editor-services

Puppet Language Server for editors
Apache License 2.0
45 stars 21 forks source link

Go to definition only works with include statements #292

Open jiji606 opened 4 years ago

jiji606 commented 4 years ago

What Versions are you running?

OS Version: vscode is running on Windows 10 with a remote environment on archlinux vm VSCode Version: 1.39.2 Puppet Extension Version: 0.21.0 PDK Version: 1.14.0

Using extension with puppet agent. Version: 5.5.16

What You Are Seeing?

Go to definition works when used with include statements but only then. for example: When I click on docker::compose in this line include foo::bar it will take me to my foo module and bar class/defined resource. This will not work when line begins with contain or any other keyword.

What is Expected?

When the line is for example like this: contain foo::bar I can still go to definition. It should also work from create_resource function like create_resource('foo::bar', hiera('foobars')

How Did You Get This To Happen? (Steps to Reproduce)

I clicked on foo::bar in a contain foo::bar line and nothing happened. Same for any other module.

Output Log

Log after I clicked a working definition:

D, [2019-10-13T00:52:18.750844 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":37,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":14,"character":23}}}
---
D, [2019-10-13T00:52:18.788065 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":37,"result":{"contents":"**include** Function\n\nThis uses the legacy Ruby function API\n\nDeclares one or more classes, causing the resources in them to be\nevaluated and added to the catalog. Accepts a class name, an array of class\nnames, or a comma-separated list of class names.\n\nThe `include` function can be used multiple times on the same class and will\nonly declare a given class once. If a class declared with `include` has any\nparameters, Puppet will automatically look up values for them in Hiera, using\n`<class name>::<parameter name>` as the lookup key.\n\nContrast this behavior with resource-like class declarations\n(`class {'name': parameter => 'value',}`), which must be used in only one place\nper class and can directly set parameters. You should avoid using both `include`\nand resource-like declarations with the same class.\n\nThe `include` function does not cause classes to be contained in the class\nwhere they are declared. For that, see the `contain` function. It also\ndoes not create a dependency relationship between the declared class and the\nsurrounding class; for that, see the `require` function.\n\nYou must use the class's full name;\nrelative names are not allowed. In addition to names in string form,\nyou may also directly use Class and Resource Type values that are produced by\nthe future parser's resource and relationship expressions.\n\n- Since < 3.0.0\n- Since 4.0.0 support for class and resource type values, absolute names\n- Since 4.7.0 returns an Array[Type[Class]] of all included classes \n"}}
---
D, [2019-10-13T00:52:24.534883 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":38,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":16,"character":24}}}
---
D, [2019-10-13T00:52:24.550953 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":38,"result":[{"uri":"file:///home/path/to/project/puppet/modules/docker/manifests/compose.pp","range":{"start":{"line":1,"character":0},"end":{"line":1,"character":1024}}}]}
---
D, [2019-10-13T00:52:24.787501 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":39,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":16,"character":22}}}
---
D, [2019-10-13T00:52:24.836863 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":39,"result":{"contents":"**include** Function\n\nThis uses the legacy Ruby function API\n\nDeclares one or more classes, causing the resources in them to be\nevaluated and added to the catalog. Accepts a class name, an array of class\nnames, or a comma-separated list of class names.\n\nThe `include` function can be used multiple times on the same class and will\nonly declare a given class once. If a class declared with `include` has any\nparameters, Puppet will automatically look up values for them in Hiera, using\n`<class name>::<parameter name>` as the lookup key.\n\nContrast this behavior with resource-like class declarations\n(`class {'name': parameter => 'value',}`), which must be used in only one place\nper class and can directly set parameters. You should avoid using both `include`\nand resource-like declarations with the same class.\n\nThe `include` function does not cause classes to be contained in the class\nwhere they are declared. For that, see the `contain` function. It also\ndoes not create a dependency relationship between the declared class and the\nsurrounding class; for that, see the `require` function.\n\nYou must use the class's full name;\nrelative names are not allowed. In addition to names in string form,\nyou may also directly use Class and Resource Type values that are produced by\nthe future parser's resource and relationship expressions.\n\n- Since < 3.0.0\n- Since 4.0.0 support for class and resource type values, absolute names\n- Since 4.7.0 returns an Array[Type[Class]] of all included classes \n"}}
---
D, [2019-10-13T00:52:25.086643 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":40,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":16,"character":22}}}
---
D, [2019-10-13T00:52:25.124401 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":40,"result":[{"uri":"file:///home/path/to/project/puppet/modules/docker/manifests/compose.pp","range":{"start":{"line":1,"character":0},"end":{"line":1,"character":1024}}}]}
---

Log after I clicked a not working one

D, [2019-10-13T00:52:45.172489 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":41,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":19,"character":31}}}
---
D, [2019-10-13T00:52:45.208958 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":41,"result":[]}
---
D, [2019-10-13T00:52:45.323108 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":42,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":19,"character":31}}}
---
D, [2019-10-13T00:52:45.332153 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":42,"result":{"contents":null}}
---
D, [2019-10-13T00:52:45.629667 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":43,"method":"textDocument/hover","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":19,"character":31}}}
---
D, [2019-10-13T00:52:45.666415 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":43,"result":{"contents":null}}
---
D, [2019-10-13T00:52:45.810146 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":44,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":19,"character":31}}}
---
D, [2019-10-13T00:52:45.818835 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":44,"result":[]}
---
D, [2019-10-13T00:52:46.798235 #257263] DEBUG -- : --- INBOUND
{"jsonrpc":"2.0","id":45,"method":"textDocument/definition","params":{"textDocument":{"uri":"file:///home/path/to/project/puppet/manifests/host1.pp"},"position":{"line":19,"character":31}}}
---
D, [2019-10-13T00:52:46.809101 #257263] DEBUG -- : --- OUTBOUND
{"jsonrpc":"2.0","id":45,"result":[]}
---

Node defintion for reference

node 'host1.local' {
  include docker::compose # This works
  create_resources('docker::user', hiera('docker_user')) # This doesn't
}

Module class for reference

class docker {
  contain docker::compose # This also won't work
  include docker::compose # But this is fine
}
jpogran commented 4 years ago

Hi @jiji606 , apologies for the delay in response. You are correct go to definition currently only works for include statements. We did not have an explicit issue to point you at that documents that, so I will create one today. It's a feature are we will be working on for the next couple months

glennsarti commented 4 years ago

Looks like we'll need to add some more edgecases to here : https://github.com/lingua-pupuli/puppet-editor-services/blob/master/lib/puppet-languageserver/manifest/definition_provider.rb#L50-L54

glennsarti commented 4 years ago

create_resources could be trickier

github-actions[bot] commented 4 years ago

This issue has been marked stale because it has been open for more than 30 days with no activity. If this issue is still important to you, please comment to keep this issue open. If not, this will be closed in 5 days

glennsarti commented 4 years ago

ping. Keep it open.

glennsarti commented 4 years ago

Naughty bot. Keep this open.

knorx commented 4 years ago

I am missing this functionality also for the requirekeyword.