puppetlabs / puppet-editor-services

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

Nvim: completion fail with Unable to parse content. #285

Closed lidorzakum closed 3 years ago

lidorzakum commented 3 years ago

Describe the Bug

I configured nvim to run lspconfig with the puppet-language-server for auto-completion but it seems to not work. Errors detection works fine but no suggestions are coming up. (bash autocomplete works as usual)

 group { 'whatever':                                                                                                      
   ensure => present,      ■ trailing whitespace found                                                                 
   mode;     ■ Could not parse for environment *root*: Syntax error at ';' (line: 20, column: 9)                       
 }    

Expected Behavior

nvim auto-complete and/or suggest when working with puppet manifests.

Steps to Reproduce

Steps to reproduce the behavior:

  1. git clone https://github.com/lingua-pupuli/puppet-editor-services.git
  2. cd puppet-editor-services
  3. git checkout tags/1.0.1
  4. bundle install
  5. bundle exec rake gem_revendor
  6. Setting up nvim with the following config:
    
    call plug#begin('~/.vim/plugged')
    Plug 'neovim/nvim-lspconfig'                                                                                            
    Plug 'nvim-lua/completion-nvim'                                                                                         
    Plug 'tjdevries/nlua.nvim'                                                                                              
    Plug 'tjdevries/lsp_extensions.nvim'
    Plug 'rodjek/vim-puppet'
    call plug#end()

lua require'lspconfig'.bashls.setup{ on_attach=require'completion'.on_attach } lua <<EOF local lspconfig = require'lspconfig' local configs = require'lspconfig/configs'

configs.puppet = { default_config = { cmd = {'/home/my_username/.config/nvim/puppet-editor-services/puppet-languageserver', '--debug=/tmp/nvim.log', '--stdio', '--puppet-settings=--moduledir,/home/my_username/puppet-modules'}; filetypes = {'puppet'}; root_dir = function(fname) return lspconfig.util.find_git_ancestor(fname) or vim.loop.os_homedir() end; }; } lspconfig.puppet.setup{ on_attach=require'completion'.on_attach } EOF

7. nvim /home/my_username/puppet-modules/local_modules/random/manifest/init.pp
8. Try to type anything that should trigger recommendation

## Environment
 - Version: 1.0.1
 - Platform: Ubuntu 20.04
 - nvim v0.5.0-ef3230f

## Additional Context
This is the only error I could find in the logs:

I, [2020-12-14T05:36:34.125993 #89469] INFO -- : Received textDocument/didChange notification. D, [2020-12-14T05:36:34.128065 #89469] DEBUG -- : --- INBOUND {"method": "textDocument/completion", "jsonrpc": "2.0", "id": 6, "params": {"textDocument": {"uri": "file:///home/my_username/puppet-modules/local-modules/whatever/manifests/init.pp"}, "position": {"character": 5, "line": 6}}}

E, [2020-12-14T05:36:34.149904 #89469] ERROR -- : (textDocument/completion) Unable to parse content D, [2020-12-14T05:36:34.209190 #89469] DEBUG -- : --- OUTBOUND



I also receive a similar error when trying to set up the language server with coc, so I assume something went wrong with my installation of puppet-language-server or with puppet itself.
jpogran commented 3 years ago

Thanks for the report @lidorzakum, I'm glad to see others using the puppet-editor-services with editors other than vscode. Before we get too far into troubleshooting, I do want to mention that you should be using the latest tag if you encounter any problems, 0.26.1 is from June and we're at 1.0.1 now.

If that doesn't resolve things, I need to know a little more information (thanks for the detailed report btw). What ruby version are you using and what version Puppet did you install? Since you are running puppet-editor-services directly, you have to ensure that the version of ruby being used matches the version of puppet being installed, which has to match the version your project is expecting. In VSCode, we use the PDK or Puppet Agent to resolve these gems and use the correct ruby version automatically, but when using neovim you're going to have to ensure that yourself. The other reason I ask is that puppet-editor-services hasn't released a tag yet that supports puppet-7.

lidorzakum commented 3 years ago

Thanks for the super fast response @jpogran. Changing ruby's version seems to partially solve the issue. I'm getting now completions for resources and for blocks ('class' for example) but no attributes. Logs contain these 3 different errors (the first one occured once, the other two occured multiple times):

E, [2020-12-16T03:24:24.110428 #279256] ERROR -- : (textDocument/completion) 'class' keyword not allowed at this location (line: 4, column: 1)
{"jsonrpc":"2.0","method":"textDocument/publishDiagnostics","params":{"uri":"file:///home/my_username/puppet-modules/local-modules/whatever/manifests/init.pp","diagnostics":[{"message":"Could not parse for environment *root*: Syntax error at ':' (line: 4, column: 23)","source":"Puppet","range":{"end":{"line":3,"character":24},"start":{"line":3,"character":23}},"severity":1}]}}
E, [2020-12-16T03:24:45.693978 #279256] ERROR -- : (textDocument/completion) Unable to parse content

I also saw this call. Are the different attributes in the "completion" section should be true? Couldn't find out how to define them.

{"method": "initialize", "jsonrpc": "2.0", "id": 1, "params": {"rootUri": "file:///home/my_username", "initializationOptions": {}, "workspaceFolders": [{"uri": "file:///home/my_username", "name": "/home/my_username"}], "rootPath": "/home/my_username", "processId": 279248, "trace": "off", "capabilities": {"workspace": {"workspaceFolders": true, "applyEdit": true, "symbol": {"symbolKind": {"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, "dynamicRegistration": false, "hierarchicalWorkspaceSymbolSupport": true}, "configuration": true}, "callHierarchy": {"dynamicRegistration": false}, "textDocument": {"codeAction": {"codeActionLiteralSupport": {"codeActionKind": {"valueSet": ["", "RefactorInline", "source.organizeImports", "quickfix", "QuickFix", "Refactor", "Source", "RefactorRewrite", "refactor.inline", "RefactorExtract", "source", "SourceOrganizeImports", "refactor", "Empty", "refactor.rewrite", "refactor.extract"]}}, "dynamicRegistration": false}, "documentSymbol": {"symbolKind": {"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26]}, "dynamicRegistration": false, "hierarchicalDocumentSymbolSupport": true}, "signatureHelp": {"signatureInformation": {"documentationFormat": ["markdown", "plaintext"]}, "dynamicRegistration": false}, "rename": {"prepareSupport": true, "dynamicRegistration": false}, "synchronization": {"didSave": true, "willSaveWaitUntil": false, "willSave": false, "dynamicRegistration": false}, "references": {"dynamicRegistration": false}, "definition": {"linkSupport": true}, "completion": {"completionItem": {"snippetSupport": false, "commitCharactersSupport": false, "preselectSupport": false, "deprecatedSupport": false, "documentationFormat": ["markdown", "plaintext"]}, "contextSupport": false, "dynamicRegistration": false, "completionItemKind": {"valueSet": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]}}, "typeDefinition": {"linkSupport": true}, "documentHighlight": {"dynamicRegistration": false}, "hover": {"dynamicRegistration": false, "contentFormat": ["markdown", "plaintext"]}, "declaration": {"linkSupport": true}, "implementation": {"linkSupport": true}}}}}

My project is currently running on puppet 5.5.20 so I now run the language server using ruby-2.4.10 and the same puppet version (5.5.20) The 0.26.1 was my mistake, I have looked up an old ticket from this repo so I can see how to fill a bug report. I copied the steps from there since they were nearly identical to mine but forgot to change the version, I used 1.0.1 when trying to integrate the language server.

Please let me know if you need any more info from me and thank you once again!

lidorzakum commented 3 years ago

Turns out that the parameters also works fine. The issue was that I didn't close the curly braces for the resource declaration and the error prevented the suggestion from happening. I would probably be able to solve installing puppet snippets. @jpogran thx again for the assistance!