2

Here is my nvim setup:

local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
  local lspconfig = require('lspconfig')
  local servers = { 'tsserver', 'eslint', 'bashls','jsonls','sumneko_lua' } 

  for _, lsp in ipairs(servers) do
      lspconfig[lsp].setup {
          capabilities = capabilities,
          flags = lsp_flags,
          on_attach = function(client, bufnr)
            vim.keymap.set('n', 'gd', vim.lsp.buf.definition, bufopts)
          end
      }
  end

I have two javascript projects. In one of them, when i put my cursor over a method and type gd, I simply jump to the file definition as expected.

In the other one, when I do the same as above, I jump instead to the import statement instead of the actual definition.

For example in this code

    if (!areAllKeysEmptyStrings(rootCompanyFilters)) {

doing the key binding makes me jump to this part in the same file

import {
  areAllKeysEmptyStrings <--
} from "utils/helpers"

Any idea why this is happening?

4
  • The behavior you describe is the original behavior of :help gd, which means that your custom mapping hasn't been defined. It may be caused by a logical error in your function, by your function not being executed, or by one of its dependencies to not be present at runtime. Without having the two projects at hand it will be hard for anyone to help you further.
    – romainl
    Commented Sep 3, 2023 at 6:21
  • What two projects are you referring to?
    – abbood
    Commented Sep 3, 2023 at 9:46
  • i changed the mapping to something different (ie gx) and indeed it didn't work at all (although it works on different projects). You mentioned something about runtime, but I'm not sure what this problem has to do with runtime? This is simply about jumping to the definition of a file, something like a static analyzer.
    – abbood
    Commented Sep 3, 2023 at 11:35
  • I was following the lsp quickstart guide here and I ran this command :lua =vim.lsp.get_active_clients(), in the project that is working the only server that is active is github copilot, but the others have eslint, tsserver etc attached to it. So I'm guessing I'm not successfully attaching said servers to the project..
    – abbood
    Commented Sep 3, 2023 at 12:01

1 Answer 1

1

running :lua =vim.lsp.get_active_clients() made me realize that the only language server attached was copilot! So after some online searching I installed the mason language server package manager, which helpfully pointed out to me that both these language servers

  • eslint-lsp
  • typescript-language-server

are both outdated. So I simply ran :MasonUpdate eslint-lsp and :MasonUpdate typescript-language-server and it works perfect now!

To verify, I ran

:lua =vim.lsp.get_active_clients()

and found tsserver and eslint included in the output

update

the server crashed again (i'm always messing with my vim settings so that's expected).. so I created this quick command

nnoremap <F5> :lua new = vim.api.nvim_create_buf(false, true); vim.api.nvim_open_win(new, true, {relative='editor', width=80, height=20, row=3, col=3}); vim.api.nvim_buf_set_lines(new, 0, -1, false, vim.split(vim.inspect(vim.lsp.get_active_clients()), '\n'))<CR>

which basically outputs the currently connected servers to a new buffer (so that i can scroll around).

then i logged the currently attached servers here

local capabilities = vim.lsp.protocol.make_client_capabilities()


  local lspconfig = require('lspconfig')
  local navbuddy = require('nvim-navbuddy')
  local servers = { 'tsserver', 'eslint', 'bashls','jsonls'} 

  for _, lsp in ipairs(servers) do
      lspconfig[lsp].setup {
          capabilities = capabilities,
          on_attach = function(client, bufnr)
            print("LSP started: " .. client.name) <---

it turns out that when attaching the servers to js files, i got this error

Client 2 quit with exit code 126 and signal 0
Client 3 quit with exit code 126 and signal 0

and so it turns out they weren't installed (some node version discrepancy).. installing them solved the problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.