Nvim-lspconfig: Function from README throws errors

Created on 20 Apr 2020  Â·  6Comments  Â·  Source: neovim/nvim-lspconfig

NVIM v0.5.0-445-gca02db1f9
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-5 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wmissing-prototypes -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=auto -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/home/travis/build/neovim/bot-ci/build/neovim/build/config -I/home/travis/build/neovim/bot-ci/build/neovim/src -I/home/travis/build/neovim/bot-ci/build/neovim/.deps/usr/include -I/usr/include -I/home/travis/build/neovim/bot-ci/build/neovim/build/src/nvim/auto -I/home/travis/build/neovim/bot-ci/build/neovim/build/include
Compiled by travis@travis-job-41e98c7d-18cc-46e0-90e2-721b8f0d476a

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/share/nvim"

Run :checkhealth for more info
  • nvim-lsp version(commit hash): b6dc2ae6a95051e93486224481b80cb5b446dcc3

  • :checkhealth result

health#targets#check
========================================================================
  - WARNING: Conflicting mapping found:
    ab → <Plug>(textobj-sandwich-auto-a)
    b → {'pair': [{'c': ')', 'o': '('}, {'c': ']', 'o': '['}, {'c': '}', 'o': '{'}]}
  - WARNING: Conflicting mapping found:
    ib → <Plug>(textobj-sandwich-auto-i)
    b → {'pair': [{'c': ')', 'o': '('}, {'c': ']', 'o': '['}, {'c': '}', 'o': '{'}]}

health#nvim_lsp#check
========================================================================
## Checking language server protocol configuration
  - INFO: dhall: configuration checked.
  - INFO: gopls: configuration checked.

health#nvim#check
========================================================================
## Configuration
  - OK: no issues found

## Performance
  - OK: Build type: RelWithDebInfo

## Remote Plugins
  - OK: Up to date

## terminal
  - INFO: key_backspace (kbs) terminfo entry: key_backspace=^H
  - INFO: key_dc (kdch1) terminfo entry: key_dc=\E[3~
  - INFO: $COLORTERM='truecolor'

health#provider#check
========================================================================
## Clipboard (optional)
  - OK: Clipboard tool found: xclip

## Python 2 provider (optional)
  - WARNING: No Python executable found that can `import neovim`. Using the first available executable for diagnostics.
  - ERROR: Python provider error:
    - ADVICE:
      - provider/pythonx: Could not load Python 2:
          python2 not found in search path or not executable.
          python2.7 not found in search path or not executable.
          python2.6 not found in search path or not executable.
          /usr/bin/python is Python 3.8 and cannot provide Python 2.
  - INFO: Executable: Not found

## Python 3 provider (optional)
  - INFO: `g:python3_host_prog` is not set.  Searching for python3 in the environment.
  - INFO: Executable: /usr/bin/python3
  - INFO: Python version: 3.8.2
  - INFO: pynvim version: 0.4.1
  - OK: Latest pynvim is installed.

## Python virtualenv
  - OK: no $VIRTUAL_ENV

## Ruby provider (optional)
  - WARNING: `ruby` and `gem` must be in $PATH.
    - ADVICE:
      - Install Ruby and verify that `ruby` and `gem` commands work.

## Node.js provider (optional)
  - INFO: Node.js: v12.16.2
  - WARNING: Missing "neovim" npm (or yarn) package.
    - ADVICE:
      - Run in shell: npm install -g neovim
      - Run in shell (if you use yarn): yarn global add neovim

## Perl provider (optional)
  - WARNING: `perl` and `cpanm` must be in $PATH.
    - ADVICE:
      - Install Perl and cpanminus and verify that `perl` and `cpanm` commands work.

  • What language server(If the problem is related to a specific language server): custom
  • Operating system/version: Manjaro
  • Terminal name/version: Alacritty
  • $TERM: xterm-256color

How to reproduce the problem from neovim startup

Paste this into init.vim, taken from the Example: Custom Config https://github.com/neovim/nvim-lsp#example-custom-config.

lua << EOF
    local nvim_lsp = require'nvim_lsp'
    if not nvim_lsp.foo_lsp then
        print('foo')
    end
EOF

Some additional info, I'm using minpac, but generally nvim_lsp works just fine. Here's a bit more snippet info with context. This is what I have in my config right now. And it does work and the dhall LSP works. I was just wondering why the if not ... then from the README breaks.

" code above
call minpac#add('neovim/nvim-lsp', {'type': 'opt'})
" code below

packadd nvim-lsp
lua << EOF
    require'nvim_lsp'.gopls.setup{}
    require'dhall_lsp'
    require'nvim_lsp'.dhall.setup{}

    local nvim_lsp = require'nvim_lsp'
    if not nvim_lsp.foo_lsp then
        print('foo')
    end
EOF

Actual behaviour

Error executing lua ...a/.config/nvim/pack/minpac/opt/nvim-lsp/lua/nvim_lsp.lua:77: module 'nvim_lsp/foo_lsp' not found:

Expected behaviour

No error

bug documentation

Most helpful comment

i think the sample code is mistaken. referencing nvim_lsp.foo_lsp when foo_lsp doesn't exist will cause this code to require a non-existent module:
https://github.com/neovim/nvim-lsp/blob/269169cb11a1491ba398638776bb471e5dfd0c8c/lua/nvim_lsp.lua#L76-L78

my guess is the sample code should be if not configs.foo_lsp then

All 6 comments

@cideM Does #192 fix this?

It does not @h-michael still seeing the same error. Only thing that works is wrapping the if nvim_lsp.foo_lsp in pcall. Which is a bit strange but I know exactly 0 about Lua. But from my complete noob & outsider perspective it looks like the mt:__index(k) is being called but Lua somehow does a separate (?) check for the module. No amount of pcall in function mt:__index(k) seemed to catch this error

you are missing the first step from the readme:

local configs = require'nvim_lsp/configs'
configs.foo_lsp = { … }

actually https://github.com/neovim/nvim-lsp#example-custom-config is not really clear, it needs to be improved.

Still fails with the same error message with this code

lua << EOF
local nvim_lsp = require'nvim_lsp'
local configs = require'nvim_lsp/configs'
-- Check if it's already defined for when I reload this file.
if not nvim_lsp.foo_lsp then
  configs.foo_lsp = {
    default_config = {
      cmd = {'/home/ashkan/works/3rd/lua-language-server/run.sh'};
      filetypes = {'lua'};
      root_dir = function(fname)
        return nvim_lsp.util.find_git_ancestor(fname) or vim.loop.os_homedir()
      end;
      settings = {};
    };
  }
end
nvim_lsp.foo_lsp.setup{}
EOF

Also why would I need to require /configs when the statement that causes the error is the nvim_lsp.foo_lsp part? :thinking:

i think the sample code is mistaken. referencing nvim_lsp.foo_lsp when foo_lsp doesn't exist will cause this code to require a non-existent module:
https://github.com/neovim/nvim-lsp/blob/269169cb11a1491ba398638776bb471e5dfd0c8c/lua/nvim_lsp.lua#L76-L78

my guess is the sample code should be if not configs.foo_lsp then

@cideM Does https://github.com/neovim/nvim-lspconfig/pull/475 address your concerns?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

justinmk picture justinmk  Â·  8Comments

teto picture teto  Â·  10Comments

K1DV5 picture K1DV5  Â·  10Comments

jacksonludwig picture jacksonludwig  Â·  11Comments

ChrisAmelia picture ChrisAmelia  Â·  3Comments