SmiteshP / nvim-navic

Simple winbar/statusline plugin that shows your current code context
Apache License 2.0
1.42k stars 51 forks source link

It seems it's not working for me... #18

Closed NEX-S closed 2 years ago

NEX-S commented 2 years ago

It seems it's not working for me... Im freshman for neovim, would you please take look at my config, I really dont know where is wrong :(, appreciate for that. my packer.lua

        use { 'SmiteshP/nvim-navic',
            after = 'nvim-lspconfig',
            config = function ()
                require 'LSP.nvim-navic'
            end
        }

my nvim-navic config

local navic_ok, navic = pcall(require, 'nvim-navic')

if not navic_ok then
    vim.notify_once(' [ NVIM-NAVIC ] NOT FOUND.')
    return
end

navic.setup {
    icons = {
        File          = " ",
        Module        = " ",
        Namespace     = " ",
        Package       = " ",
        Class         = " ",
        Method        = " ",
        Property      = " ",
        Field         = " ",
        Constructor   = " ",
        Enum          = "練",
        Interface     = "練",
        Function      = " ",
        Variable      = " ",
        Constant      = " ",
        String        = " ",
        Number        = " ",
        Boolean       = "◩ ",
        Array         = " ",
        Object        = " ",
        Key           = " ",
        Null          = "ﳠ ",
        EnumMember    = " ",
        Struct        = " ",
        Event         = " ",
        Operator      = " ",
        TypeParameter = " ",
    },
    highlight = false,
    separator = " > ",
    depth_limit = 0,
    depth_limit_indicator = "..",
}

my LSP-CONFIG

local present, lspconfig = pcall(require, "lspconfig")

    if not present then
        vim.notify_once(' [ LSP-CONFIG ] NOT FOUND.')
        return
    end

local navic_ok, navic = pcall(require, 'nvim-navic')

    if not navic_ok then
        vim.notify_once(' [ NVIM-NAVIC ] NOT FOUND')
        return
    end

local aerial_ok, aerial = pcall(require, 'aerial')

    if not aerial_ok then
        vim.notify_once(' [ AERIAL ] NOT FOUND.')
    end

require("lspconfig").clangd.setup {
    on_attach = function(client, bufnr)
        navic.attach(client, bufnr)
    end
}

    local M = {}

    M.on_attach = function(client, bufnr)
        client.resolved_capabilities.document_formatting = false
        client.resolved_capabilities.document_range_formatting = false

        if client.supports_method "textDocument/signatureHelp" then
            vim.api.nvim_create_autocmd({ "CursorHoldI" }, {
                pattern = "*",
                group = vim.api.nvim_create_augroup("LspSignature", {}),
                callback = function()
                    vim.lsp.buf.signature_help()
                end,
            })
        end
        aerial.on_attach(client, bufnr)
        navic.attach(client, bufnr)
    end

    -- Mappings.
    -- See `:help vim.diagnostic.*` for documentation on any of the below functions
    -- vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, { noremap = true, silent = true })
    vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { noremap = true, silent = true })
    vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { noremap = true, silent = true })
    -- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, { noremap = true, silent = true })

    -- Use an on_attach function to only map the following keys
    -- after the language server attaches to the current buffer
    local on_attach = function(bufnr)
        -- Enable completion triggered by <c-x><c-o>
        vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

        -- Mappings.
        -- See `:help vim.lsp.*` for documentation on any of the below functions
        vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gh', vim.lsp.buf.hover, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';wa', vim.lsp.buf.add_workspace_folder, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';wr', vim.lsp.buf.remove_workspace_folder, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';wl', function()
            -- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
            -- end, { noremap = true, silent = true, buffer = bufnr })
            vim.keymap.set('n', ';D', vim.lsp.buf.type_definition, { noremap = true, silent = true, buffer = bufnr })
            -- vim.keymap.set('n', ';rn', vim.lsp.buf.rename, { noremap = true, silent = true, buffer = bufnr })
            -- vim.keymap.set('n', ';ca', vim.lsp.buf.code_action, { noremap = true, silent = true, buffer = bufnr })
            vim.keymap.set('n', 'gr', vim.lsp.buf.references, { noremap = true, silent = true, buffer = bufnr })
            -- vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, { noremap = true, silent = true, buffer = bufnr })
        end

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

        capabilities.textDocument.completion.completionItem = {
            documentationFormat = { "markdown", "plaintext" },
            snippetSupport = true,
            preselectSupport = true,
            insertReplaceSupport = true,
            labelDetailsSupport = true,
            deprecatedSupport = true,
            commitCharactersSupport = true,
            tagSupport = { valueSet = { 1 } },
            resolveSupport = {
                properties = {
                    "documentation",
                    "detail",
                    "additionalTextEdits",
                },
            },
        }

        capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

        lspconfig.sumneko_lua.setup {
            on_attach = M.on_attach,
            capabilities = capabilities,

            settings = {
                Lua = {
                    diagnostics = {
                        globals = { "vim" },
                    },
                    workspace = {
                        library = {
                            [vim.fn.expand "$VIMRUNTIME/lua"] = true,
                            [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
                        },
                        maxPreload = 100000,
                        preloadFileSize = 10000,
                    },
                },
            },
        }

        require('lspconfig')['pyright'].setup {
            on_attach = M.on_attach,
            capabilities = capabilities,
        }

        require('lspconfig')['clangd'].setup {
            on_attach = M.on_attach,
            capabilities = capabilities,
        }

        require('lspconfig')['intelephense'].setup {
            on_attach = M.on_attach,
            capabilities = capabilities,
        }

return M
NEX-S commented 2 years ago

btw i use bufferline.lua and lualine

NEX-S commented 2 years ago

Okay.......... It seems like it's working now.... It's wired that i dont know why it is working now :D. Anyway, thank you.

NEX-S commented 2 years ago

SOMETHING STRANGE HAPPEND.... I Must INTO INSERT MODE TO LET NAVIC RUN, I DONT KNOW WHY THIS WOULD HAPPENED. I thought is lazy_loading cause this, but it seems not.

my packer.lua


local status, packer = pcall(require, 'packer')

if not status then
    return
end

packer.init {
    auto_clean = true,
    compile_on_sync = true,
    git = { clone_timeout = 6000 },
    -- compile_path = '~/.local/nvim/lua/plugins/packer_compiled.lua',
    display = {
        working_sym = "",
        error_sym = "✗",
        done_sym = "",
        removed_sym = "-",
        moved_sym = "",
        open_fn = function()
            return require("packer.util").float { border = "single" }
        end,
    },
}

packer.startup {
    function(use)
        -- COLORS --
        use 'folke/tokyonight.nvim'
        -- use 'atelierbram/Base2Tone-vim'
        use 'shaunsingh/nord.nvim'
        -- use 'EdenEast/nightfox.nvim'
        use 'drewtempelmeyer/palenight.vim'
        -- use 'atelierbram/vim-colors_duotones'
        -- use 'ful1e5/onedark.nvim'

        -- PLUGINS --
        use 'wbthomason/packer.nvim'
        use 'lewis6991/impatient.nvim'
        use 'dstein64/vim-startuptime'

        use { 'kyazdani42/nvim-web-devicons', event = { 'BufRead', 'BufWinEnter', 'BufNewFile' } }

        -- TOGGLETERM --
        use {"akinsho/toggleterm.nvim",
            tag = 'v1.*',
            cmd = { 'ToggleTerm' },
            config = function ()
                require('toggleterm').setup {
                    start_in_insert = true,
                    direction = 'float',
                    float_opts = { border = 'shadow', }
                }
            end
        }

        -- DASHBOARD --
        -- ~/.config/nvim/lua/plugins/dashboard.lua
        -- use { 'glepnir/dashboard-nvim',
        --     event = 'VimEnter',
        --     config = function()
        --         require "plugins.dashboard"
        --     end
        -- }

        -- NVIM-TREE --
        -- ~/.config/nvim/lua/plugins/nvim-tree.lua
        use { 'kyazdani42/nvim-tree.lua',
            after = 'nvim-web-devicons',
            cmd = { 'NvimTreeFindFileToggle' },
            config = function()
                require 'plugins.nvim-tree'
            end,
        }

        -- LUALINE --
        -- ~/.config/nvim/lua/plugins/lualine.lua
        use { 'nvim-lualine/lualine.nvim',
            after = 'nvim-web-devicons',
            config = function()
                require 'plugins.lualine'
            end
        }

        -- BUFFERLINE --
        -- ~/.config/nvim/lua/plugins/bufferline.lua
        use { 'akinsho/bufferline.nvim',
            tag = "v2.*",
            event = { 'BufAdd', 'BufCreate', 'BufNewFile', 'TabEnter' },
            config = function()
                require 'plugins.bufferline'
            end
        }

        -- TELESCOPE --
        -- ~/.config/nvim/lua/plugins/telescope.lua
        use 'nvim-lua/plenary.nvim'
        use { 'nvim-telescope/telescope.nvim',
            cmd = 'Telescope',
            config = function()
                require 'plugins.telescope'
            end
        }

        -- NVIM-TREESITTER --
        -- ~/.config/nvim/lua/plugins/nvim-treesitter.lua
        use { 'nvim-treesitter/nvim-treesitter',
            -- event = { 'BufRead', 'BufWinEnter', 'BufNewFile' },
            run = ":TSUpdate",
            config = function()
                require "plugins.nvim-treesitter"
            end,
        }

        -- COMMENT --
        -- ~/.config/nvim/lua/plugins/comment.lua
        use { 'numToStr/Comment.nvim',
            keys = { ';c', 'gcc' },
            config = function()
                require('Comment').setup {
                    toggler = {
                        line = ';c',
                        block = ';bc',
                    },
                }
                vim.keymap.set('v', ';c', 'gcgv', { remap = true, silent = true })
            end
        }

        -- HOP --
        -- ~/.config/nvim/lua/plugins/hop.lua
        -- use { 'phaazon/hop.nvim',
        --     branch = 'v1',
        --     cmd = { 'HopWord', 'HopLineAC', 'HopLineBC' },
        --     config = function()
        --         require 'hop'.setup {}
        --     end
        -- }

        -- INDENT-BLANKLINE --
        -- ~/.config/nvim/lua/plugins/indent-blankline.lua
        use { 'lukas-reineke/indent-blankline.nvim',
            event = { 'BufRead', 'BufWinEnter', 'BufNewFile' },
            config = function()
                require('indent_blankline').setup {
                   char = "¦",
                   show_first_indent_level = false,
                }
            end
        }

        -- NVIM-COLORIZER --
        -- ~/.config/nvim/lua/plugins/nvim-colorizer.lua
        use { 'norcalli/nvim-colorizer.lua',
            ft = { 'vim', 'lua' },
            event = { 'BufRead', 'BufNewFile' },
            config = function()
                require 'colorizer'.setup({ '*'; }, { mode = 'foreground' })
            end
        }

        -- TRANSLATOR --
        -- ~/.config/nvim/lua/plugins/vim-translator
        use { 'voldikss/vim-translator',
            keys = ';t',
            config = function()
                vim.g.translator_default_engines = { 'bing' }
                vim.keymap.set('n', ';t', '<PLUG>TranslateW', { noremap = true, silent = true })
                vim.keymap.set('v', ';t', '<PLUG>TranslateWV', { noremap = true, silent = true })
            end,
        }

        -- NVIM-LSP-INSTALLER --
        -- ~/.config/nvim/lua/LSP/nvim-lsp-installer.lua
        use { 'williamboman/nvim-lsp-installer',
            event = { "BufRead", "BufWinEnter", "BufNewFile" },
            setup = function ()
                vim.defer_fn( function ()
                    require("packer").loader("nvim-lsp-installer")
                end, 0)
                vim.defer_fn( function ()
                    vim.cmd 'if &ft == "packer" | echo "" | else | silent! e %'
                end, 0)
                require 'LSP.nvim-lsp-installer'
            end
        }

        -- NVIM-LSPCONFIG --
        -- ~/.config/nvim/lua/LSP/nvim-lspconfig.lua
        use { 'neovim/nvim-lspconfig',
            after = 'nvim-lsp-installer',
            -- ft = { 'c', 'python', 'php', 'lua' },
            config = function ()
                require 'LSP.nvim-lspconfig'
                require 'LSP.UI'
            end,
        }

        -- AERIAL --
        -- ~/.config/nvim/lua/LSP/aerial.lua
        use { 'stevearc/aerial.nvim',
            cmd = 'AerialToggle',
            config = function ()
                require 'LSP.aerial'
            end
        }

        use { 'SmiteshP/nvim-navic',
            -- after = 'nvim-lspconfig',
            config = function ()
                require 'LSP.nvim-navic'
            end
        }

        -- use { 'glepnir/lspsaga.nvim',
        --     after = 'nvim-lspconfig',
        --     cmd = 'Lspsaga',
        --     config = function ()
        --         require 'LSP.lspsaga'
        --     end,
        -- }

        use { 'folke/trouble.nvim',
            cmd = 'TroubleToggle',
            config = function()
                require 'LSP.trouble'
            end
        }

        -- NULL-LS --
        -- use { 'jose-elias-alvarez/null-ls.nvim',
        --     event = { 'BufAdd', 'BufCreate', 'BufNewFile', 'TabEnter' },
        --     config = function()
        --         require 'LSP.null-ls'
        --     end,
        -- }

        use { 'rafamadriz/friendly-snippets', event = 'InsertEnter' }

        -- NVIM-CMP --
        -- ~/.config/nvim/lua/LSP/nvim-cmp.lua
        use { 'hrsh7th/nvim-cmp',
            after = 'friendly-snippets',
            config = function ()
                require 'LSP.nvim-cmp'
            end
        }

        -- LUASNIP --
        -- ~/.config/nvim/lua/LSP/LuaSnip.lua
        use { 'L3MON4D3/LuaSnip',
            after = 'nvim-cmp',
            config = function()
                require 'LSP.LuaSnip'
            end,
        }
        use { 'saadparwaiz1/cmp_luasnip', after = 'LuaSnip' }    -- LUASNIP COMPLETION

        use { 'hrsh7th/cmp-nvim-lua', after = 'cmp_luasnip' }    -- NVIM API COMPLETION
        use { 'hrsh7th/cmp-nvim-lsp', after = 'cmp-nvim-lua' }   -- LSP COMPLETION
        use { 'hrsh7th/cmp-buffer', after = 'cmp-nvim-lsp' }     -- BUFFER COMPLETION
        use { 'hrsh7th/cmp-path', after = 'cmp-buffer' }         -- PATH COMPLETION
        -- use { 'hrsh7th/cmp-cmdline', after = 'cmp-path' }

        -- AUTO-PAIRS --
        use { 'windwp/nvim-autopairs',
            after = 'nvim-cmp',
            config = function ()
                require('nvim-autopairs').setup {
                    disable_filetype = { 'TelescopePrompt' },
                    disable_in_macro = true,
                    disable_in_visualblock = true,
                }
            end
        }

        use { 'rcarriga/nvim-notify',
            event = { 'BufRead', 'BufWinEnter', 'BufNewFile' },
            config = function ()
                require 'notify'.setup {
                    fps = 60,
                    max_width = 45,
                    stages = "fade",
                    timeout = 6000,
                    icons = {
                        DEBUG = "",
                        ERROR = "",
                        INFO = "",
                        TRACE = "",
                        WARN = ""
                    },
                }
                vim.notify = require("notify")
            end,
        }

        -- use { 'ur4ltz/surround.nvim',
        --     event = 'CursorMoved',
        --     config = function ()
        --         require"surround".setup {mappings_style = "sandwich"}
        --     end
        -- }
        --
        -- use { 'tpope/vim-repeat', keys = '.' }

        use { 'yianwillis/vimcdoc',
            event = 'CmdlineEnter',
            ptp = "viml",
        }

        use { 'petertriho/nvim-scrollbar',
            event = { 'BufRead', 'BufWinEnter', 'BufNewFile' },
            config = function ()
                require("scrollbar").setup {}
            end
        }

        use { 'kevinhwang91/nvim-hlslens',
            keys = { '/', '*', '#', '?' },
            config = function ()
                require 'plugins.nvim-hlslens'
            end
        }

        use { 'AndrewRadev/switch.vim', cmd = 'Switch' }

    end
}

vim.api.nvim_create_autocmd({ 'BufWritePost' }, {
    pattern = { 'packer.lua' },
    callback = function()
        vim.cmd "source <afile> | PackerSync"
    end
})
NEX-S commented 2 years ago

this happend to my aerial too, i must enter insert mode to let them work correctly, why would this happend? my lsp-config.lua


local present, lspconfig = pcall(require, "lspconfig")

    if not present then
        vim.notify_once(' [ LSP-CONFIG ] NOT FOUND.')
        return
    end

local navic_ok, navic = pcall(require, 'nvim-navic')

    if not navic_ok then
        vim.notify_once(' [ NVIM-NAVIC ] NOT FOUND.')
        return
    end

local aerial_ok, aerial = pcall(require, 'aerial')

    if not aerial_ok then
        vim.notify_once(' [ AERIAL ] NOT FOUND.')
        return
    end

local M = {}

    M.on_attach = function(client, bufnr)
        client.resolved_capabilities.document_formatting = false
        client.resolved_capabilities.document_range_formatting = false

        if client.supports_method "textDocument/signatureHelp" then
            vim.api.nvim_create_autocmd({ "CursorHoldI" }, {
                pattern = "*",
                group = vim.api.nvim_create_augroup("LspSignature", {}),
                callback = function()
                    vim.lsp.buf.signature_help()
                end,
            })
        end
        aerial.on_attach(client, bufnr)
        navic.attach(client, bufnr)
    end

    -- Mappings.
    -- See `:help vim.diagnostic.*` for documentation on any of the below functions
    -- vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, { noremap = true, silent = true })
    vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { noremap = true, silent = true })
    vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { noremap = true, silent = true })
    -- vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, { noremap = true, silent = true })

    -- Use an on_attach function to only map the following keys
    -- after the language server attaches to the current buffer
    local on_attach = function(client, bufnr)
        -- Enable completion triggered by <c-x><c-o>
        vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

        -- Mappings.
        -- See `:help vim.lsp.*` for documentation on any of the below functions
        vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gd', vim.lsp.buf.definition, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gh', vim.lsp.buf.hover, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';wa', vim.lsp.buf.add_workspace_folder, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';wr', vim.lsp.buf.remove_workspace_folder, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';wl', function()
        -- print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
        -- end, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', ';D', vim.lsp.buf.type_definition, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';rn', vim.lsp.buf.rename, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', ';ca', vim.lsp.buf.code_action, { noremap = true, silent = true, buffer = bufnr })
        vim.keymap.set('n', 'gr', vim.lsp.buf.references, { noremap = true, silent = true, buffer = bufnr })
        -- vim.keymap.set('n', '<space>f', vim.lsp.buf.formatting, { noremap = true, silent = true, buffer = bufnr })
    end

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

    capabilities.textDocument.completion.completionItem = {
        documentationFormat = { "markdown", "plaintext" },
        snippetSupport = true,
        preselectSupport = true,
        insertReplaceSupport = true,
        labelDetailsSupport = true,
        deprecatedSupport = true,
        commitCharactersSupport = true,
        tagSupport = { valueSet = { 1 } },
        resolveSupport = {
            properties = {
                "documentation",
                "detail",
                "additionalTextEdits",
            },
        },
    }

    capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

    lspconfig.sumneko_lua.setup {
        on_attach = M.on_attach,
        capabilities = capabilities,

        settings = {
            Lua = {
                diagnostics = {
                    globals = { "vim" },
                },
                workspace = {
                    library = {
                        [vim.fn.expand "$VIMRUNTIME/lua"] = true,
                        [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
                    },
                    maxPreload = 100000,
                    preloadFileSize = 10000,
                },
            },
        },
    }

    require('lspconfig')['pyright'].setup {
        on_attach = M.on_attach,
        capabilities = capabilities,
    }

    require('lspconfig')['clangd'].setup {
        on_attach = M.on_attach,
        capabilities = capabilities,
    }

    require('lspconfig')['intelephense'].setup {
        on_attach = M.on_attach,
        capabilities = capabilities,
    }

return M
SmiteshP commented 2 years ago

SOMETHING STRANGE HAPPEND.... I Must INTO INSERT MODE TO LET NAVIC RUN, I DONT KNOW WHY THIS WOULD HAPPENED. I thought is lazy_loading cause this, but it seems not.

Yep, its expected behaviour. although you don't need to enter insert mode. If you just move your cursor and hold after some time navic will work. I explained why this happens in more detail over here #3