ray-x / navigator.lua

Code analysis & navigation plugin for Neovim. Navigate codes like a breeze🎐 Exploring LSP and 🌲Treesitter symbols a piece of 🍰 Take control like a boss 🦍
MIT License
1.31k stars 58 forks source link

Other than gd, all other shortcut keys aren't working for me #130

Closed tonyma closed 2 years ago

tonyma commented 2 years ago

Environment detail:

System: macOS Monterey version 12.1 Chip Apple M1 Max NVIM v0.6.0 (via brew install) Build type: Release LuaJIT 2.1.0-beta3 Compiled by brew@HMBRW-A-001-M1-004.local

gd worked for me but all other shortcut keys aren't working for me.

Here are my configures: init.lua: https://github.com/tonyma/dotfiles/blob/main/nvim/.config/nvim/init.lua plugin: https://github.com/tonyma/dotfiles/blob/main/nvim/.config/nvim/lua/plugins.lua navigator config (mostly default configure copied from this repo): https://github.com/tonyma/dotfiles/blob/main/nvim/.config/nvim/lua/config/navigator.lua

I also tried with the minimal sample configuration in the playground folder but got the same result. When I press gr, it triggers the native vim replace character command. Let me know if more details I can provide.

ray-x commented 2 years ago

I downloaded your config. One issue I saw is require("config.impatient") It through lots of errors even without navigator. After I disable impatient, every thing looks fine.

If you still failed to map. Please run LspKeymaps and check if navigator loaded or not

ray-x commented 2 years ago

Also check your output of LspInfo and make sure your lsp is installed and loaded. If you using sumneko_lua, make sure lua-language-server is installed in $PATH

tonyma commented 2 years ago

Here is the LspInfo output, I am testing with typescript:


 Language client log: /Users/tony/.cache/nvim/lsp.log
 Detected filetype:   typescript

 4 client(s) attached to this buffer: 

 Client: null-ls (id: 1, pid: 5001, bufnr: [16])
    filetypes:       javascript, markdown, typescriptreact, html, solidity, javascriptreact, graphql, css, json, yaml, less, typescript, scss, python, lua
    autostart:       false
    root directory:  /Users/tony/Desktop/Development/quadpay-merchant-portal
    cmd:             nvim

 Client: cssmodules_ls (id: 2, pid: 70250, bufnr: [16])
    filetypes:       javascript, javascriptreact, typescript, typescriptreact
    autostart:       true
    root directory:  /Users/tony/Desktop/Development/quadpay-merchant-portal
    cmd:             cssmodules-language-server

 Client: eslint (id: 3, pid: 70251, bufnr: [16])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx, vue
    autostart:       true
    root directory:  /Users/tony/Desktop/Development/quadpay-merchant-portal
    cmd:             vscode-eslint-language-server --stdio

 Client: tsserver (id: 4, pid: 70252, bufnr: [16])
    filetypes:       javascript, javascriptreact, javascript.jsx, typescript, typescriptreact, typescript.tsx
    autostart:       true
    root directory:  /Users/tony/Desktop/Development/quadpay-merchant-portal
    cmd:             typescript-language-server --stdio

 Configured servers list: pylsp, bashls, dockerls, eslint, gopls, flow, julials, cmake, sqlls, sqls, rust_analyzer, terraformls, texlab, volar, vuels, html, sumneko_lua, vimls, yamlls, angularls, ccls, clangd, clojure_lsp, csharp_ls, cssls, cssmodules_ls, dartls, denols, dotls, r_language_server, fsautocomplete, svelte, phpactor, jdtls, jedi_language_server, intelephense, solargraph, kotlin_language_server, nimls, jsonls, omnisharp, tsserver, graphql, pyright

Got this error when run LspKeymaps: image

ray-x commented 2 years ago

Please update your plugin. The issue you saw should have been fixed.

tonyma commented 2 years ago

After I updated the plugins, I got this screen when run LspKeymaps: image

tonyma commented 2 years ago

I also tested with your minimal lua configure, it also didn't work for me. should I clean the packer start folder when testing with your minimal configure?

ray-x commented 2 years ago

It seems the setup function did not run. What will happen if you run lua require'navigator.setup{}and re-runLspKeymaps`

tonyma commented 2 years ago

Got the same result after ran: lua require'navigator'.setup() LspKeymaps

tonyma commented 2 years ago

I added print message statement in to the navigator configure file. I can confirm the configure file is loaded and executed.

local status_ok, navigator = pcall(require, "navigator")
if not status_ok then
    print("navigator is not loaded")
    return
end
print("navigator loaded")

image

ray-x commented 2 years ago

I saw the deprecated messages, so setup should have been run. LspInfo looks fine as well. I feel it something related to the impatient.nvim could you remove the plugin and clean up cache?

tonyma commented 2 years ago

after removing impatient.nvim, I am still getting the same result. gd worked but not other shortcut keys.

ray-x commented 2 years ago

I forked your repo https://github.com/ray-x/dotfiles-1 and did some updates. It works fine in my environment Are you using window? which neovim version you are using?

tonyma commented 2 years ago

Environment detail:

System: macOS Monterey version 12.1
Chip Apple M1 Max
NVIM v0.6.0 (via brew install)
Build type: Release
LuaJIT 2.1.0-beta3
tonyma commented 2 years ago

I am getting a quick-fix pane for the reference list is at the bottom of the window. shouldn't be a floating window? is this expected behaviour for gr?

image

tonyma commented 2 years ago

I don't think it's working for me yet. I may re-visit it later and stick with my current configure for now. Thanks for your help. You may close this issue for now.

ray-x commented 2 years ago

I am using Mac as well, but not sure if M1 work out of box (with ffi). gr is a keymap to lua require('navigator.reference').reference() So you can simply run :lua require('navigator.reference').reference() when cursor stop on a symbol.

ray-x commented 2 years ago

It seems to relate to a particular setup. As I can not reproduce, close it for now.

magichan commented 2 years ago

@ray-x It seems that you don't set gd map in https://github.com/ray-x/navigator.lua/blob/master/lua/navigator/lspclient/mapping.lua#L15

I add gd into the custom keymap to solve the problem image

Suyashtnt commented 2 years ago

I am also having this issue

Config: https://github.com/Suyashtnt/nvim

ray-x commented 2 years ago

Is the lsp running in background?

Suyashtnt commented 2 years ago

Is the lsp running in background?

yes image

Suyashtnt commented 2 years ago

After some testing it does work, but the keybinds are not being registered

ray-x commented 2 years ago

I added codes to map gd in latest version. Hope it works for you

Suyashtnt commented 2 years ago

I added codes to map gd in latest version. Hope it works for you

That did not fix the issue

ray-x commented 2 years ago

What is the output of LspKeymaps Also if you run lua require('navigator.definition').definition() when your cursor is parking on a symble, is it works?

Suyashtnt commented 2 years ago

What is the output of LspKeymaps

thing

Also if you run lua require('navigator.definition').definition() when your cursor is parking on a symble, is it works?

yes

ray-x commented 2 years ago

There is no keymap bind for navigator. Seems navigator was not setup correctly. or you disable the keymaps by default_mapping=false Did you try minium vimrc init.lua in playground folder? nvim -u init.lua Or can you share your minium vimrc?

Suyashtnt commented 2 years ago

There is no keymap bind for navigator. Seems navigator was not setup correctly. or you disable the keymaps by default_mapping=false

Did you try minium vimrc init.lua in playground folder? nvim -u init.lua

Or can you share your minium vimrc?

My current vimrc has very little customization but I'll work on a minimal one mimicking most of my setup

Suyashtnt commented 2 years ago
-- general setup
vim.api.nvim_set_keymap("n", " ", "", {})
vim.g.mapleader = " "

vim.wo.number = true
vim.wo.relativenumber = true
vim.opt.termguicolors = true
vim.opt.clipboard = "unnamedplus"

vim.g.coq_settings = {
    ["auto_start"] = "shut-up",
}

-- packer
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
    packer_bootstrap = fn.system({
        "git",
        "clone",
        "--depth",
        "1",
        "https://github.com/wbthomason/packer.nvim",
        install_path,
    })
end

require("packer").startup(function(use)
    use("neovim/nvim-lspconfig")
    use("williamboman/nvim-lsp-installer")
    use("ray-x/navigator.lua")

    -- -- COQ (Autocompletion)
    use("ms-jpq/coq_nvim")
    use("ms-jpq/coq.artifacts")
    use("ms-jpq/coq.thirdparty")

    if packer_bootstrap then
        require("packer").sync()
    end
end)

-- null ls setup
local nullls = require("null-ls")
local builtins = nullls.builtins

nullls.setup({
    sources = {
        builtins.formatting.stylua,
    },
})

-- navigator/LSP setup
require("navigator").setup({
    lsp_installer = true,
})

local lsp_installer = require("nvim-lsp-installer")
local coq = require("coq")

local enhance_server_opts = {
    ["sumneko_lua"] = function(options)
        options.settings = {
            Lua = {
                diagnostics = {
                    globals = { "vim" },
                },
            },
        }
    end,
    ["tsserver"] = function(options)
        options.on_attach = function(client)
            client.resolved_capabilities.document_formatting = false
        end
    end,
}

lsp_installer.on_server_ready(function(server)
    local options = {}

    if enhance_server_opts[server.name] then
        enhance_server_opts[server.name](options)
    end

    server:setup(coq.lsp_ensure_capabilities(options))
end)

this should be the minimum init.lua file. Install an lsp via lsp installer n stuff

Suyashtnt commented 2 years ago

@ray-x

ray-x commented 2 years ago

Your init.lua does not work for me. It was updated:

vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])

local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
vim.g.coq_settings = {
  ['auto_start'] = 'shut-up',
}

local function load_plugins()
  require('packer').startup({
  function(use)
    use('wbthomason/packer.nvim')
    use('neovim/nvim-lspconfig')
    use('williamboman/nvim-lsp-installer')
    use('ray-x/navigator.lua')
    use('ray-x/guihua.lua')
    -- -- COQ (Autocompletion)
    use('ms-jpq/coq_nvim')
    use('ms-jpq/coq.artifacts')
    use('ms-jpq/coq.thirdparty')
  end,
  config = {
    package_root = package_root,
    compile_path = install_path .. '/plugin/packer_compiled.lua',
  },
  })
    -- navigator/LSP setup
  require('navigator').setup({
    lsp_installer = true,
  })

  local lsp_installer = require('nvim-lsp-installer')
  local coq = require('coq')

  local enhance_server_opts = {
    ['sumneko_lua'] = function(options)
      options.settings = {
        Lua = {
          diagnostics = {
            globals = { 'vim' },
          },
        },
      }
    end,
    ['tsserver'] = function(options)
      options.on_attach = function(client)
        client.resolved_capabilities.document_formatting = false
      end
    end,
  }

  lsp_installer.on_server_ready(function(server)
    local options = {}

    if enhance_server_opts[server.name] then
      enhance_server_opts[server.name](options)
    end

    server:setup(coq.lsp_ensure_capabilities(options))
  end)
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system({
    'git',
    'clone',
    'https://github.com/wbthomason/packer.nvim',
    install_path,
  })
  load_plugins()
  require('packer').sync()
else
  load_plugins()
end

Update to the lastest it should work.

Suyashtnt commented 2 years ago

@ray-x after running a packersync with my current setup it still did not fix the issues

Suyashtnt commented 2 years ago

check out my full config at https://github.com/Suyashtnt/nvim file with the lsp configuration stuff is lua/configs/lsp.lua

ray-x commented 2 years ago

Sorry. I can not use your setup as it will blow up mine. How about the init.lua

ray-x commented 2 years ago

@Suyashtnt looking into your setup

    ["sumneko_lua"] = function(options)
        options.settings = {
            Lua = {
                diagnostics = {
                    globals = { "vim" },
                },
            },
        }
    end,
    ["tsserver"] = function(options)
        options.on_attach = function(client)
            client.resolved_capabilities.document_formatting = false
        end
    end,

One different between lua server and tsserver is tsserver has an on_attach. That might be why the mapping not working. As lspinstaller will override the navigator on_attach depending on the sequence.

It would be good to do this:

    ["sumneko_lua"] = function(options)
                options.on_attach = function(client, bufnr)
                  require('navigator.lspclient.mapping').setup({
                    client = client,
                    bufnr = bufnr,
                    cap = capabilities,
                  })
        end
        options.settings = {
            Lua = {
                diagnostics = {
                    globals = { "vim" },
                },
            },
        }
    end,
    ["tsserver"] = function(options)
        options.on_attach = function(client, bufnr)
            client.resolved_capabilities.document_formatting = false
                        require('navigator.lspclient.mapping').setup({
                          client = client,
                          bufnr = bufnr,
                          cap = capabilities,
                        })
        end
    end,
Suyashtnt commented 2 years ago

@Suyashtnt looking into your setup


  ["sumneko_lua"] = function(options)

      options.settings = {

          Lua = {

              diagnostics = {

                  globals = { "vim" },

              },

          },

      }

  end,

  ["tsserver"] = function(options)

      options.on_attach = function(client)

          client.resolved_capabilities.document_formatting = false

      end

  end,

One different between lua server and tsserver is tsserver has an on_attach.

That might be why the mapping not working.

As lspinstaller will override the navigator on_attach depending on the sequence.

It would be good to do this:


  ["sumneko_lua"] = function(options)

                options.on_attach = function(client, bufnr)

                  require('navigator.lspclient.mapping').setup({

                    client = client,

                    bufnr = bufnr,

                    cap = capabilities,

                  })

      end

      options.settings = {

          Lua = {

              diagnostics = {

                  globals = { "vim" },

              },

          },

      }

  end,

  ["tsserver"] = function(options)

      options.on_attach = function(client, bufnr)

          client.resolved_capabilities.document_formatting = false

                        require('navigator.lspclient.mapping').setup({

                          client = client,

                          bufnr = bufnr,

                          cap = capabilities,

                        })

      end

  end,

I'll try this when I get home

Suyashtnt commented 2 years ago

@ray-x i forgot to say but it did indeed fix the issues. @tonyma check if this might be your issue