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

null_ls formatting not working #58

Closed isvicy closed 3 years ago

isvicy commented 3 years ago

after moving my lsp config to navigator, formatting of luastyle in null_ls is not working.

my navigator config:

local lspconfig = require("lspconfig")
local lsp_status = require("lsp-status")
local null_ls = require("null-ls")
local utils = require("personal.utils")
local api = vim.api

lsp_status.register_progress()

require("navigator").setup({
    keymaps = {
        { key = "gd", func = "definition()" },
        { key = "ga", func = "code_action()" },
    },
    on_attach = function(client, bufnr)
        require("lsp_signature").on_attach({
            bind = true,
            hint_enable = true,
            handler_opts = { border = "shadow" },
        })
        lsp_status.on_attach(client, bufnr)
    end,
    lsp = {
        sumneko_lua = {
            sumneko_root_path = vim.fn.expand("$HOME") .. "/github/lua-language-server",
            sumneko_binary = vim.fn.expand("$HOME")
                .. "/github/lua-language-server/bin/"
                .. utils.get_os_for_lua_lsp()
                .. "/lua-language-server",
        },
        tsserver = {
            on_attach = function(client)
                client.resolved_capabilities.document_formatting = false
            end,
        },
        gopls = {
            settings = {
                gopls = {
                    analyses = {
                        unusedparams = true,
                        fieldalignment = true,
                        nilness = true,
                        shadow = true,
                        unusedwrite = true,
                    },
                    staticcheck = true,
                    usePlaceholders = false,
                    completeUnimported = true,
                },
            },
        },
    },
})

-- Null ls
null_ls.config({
    sources = {
        null_ls.builtins.formatting.stylua.with({
            args = {
                "--indent-type",
                "Spaces",
                "-",
            },
        }),
        null_ls.builtins.formatting.prettierd.with({
            filetypes = {
                "javascript",
                "javascriptreact",
                "typescript",
                "typescriptreact",
                "vue",
                "css",
                "html",
                "json",
                "yaml",
                "markdown",
                "vimwiki",
            },
        }),
    },
})
lspconfig["null-ls"].setup({
    capabilities = lsp_status.capabilities,
})

api.nvim_command("hi default LspReferenceRead cterm=bold gui=Bold ctermbg=yellow guifg=none guibg=Black")
api.nvim_command("hi default LspReferenceText cterm=bold gui=Bold ctermbg=yellow guifg=none guibg=Black")
api.nvim_command("hi default LspReferenceWrite cterm=bold gui=Bold ctermbg=yellow guifg=none guibg=Black")

I can't figure out what is exactly the problem is, plz help.

ray-x commented 3 years ago

Do you have a minium vimrc that can startup null-ls (without navigator) I followed the readme in nullls (with or without navigator) but vim.lsp.get_active_clients() still is empty list.

isvicy commented 3 years ago

lsp.lua without navigator:

-- LSP Setup
local lsp = require("lspconfig")
local lsp_status = require("lsp-status")
local null_ls = require("null-ls")
lsp_status.register_progress()

local on_attach = function(client, bufnr)
    require("lsp_signature").on_attach({
        bind = true,
        hint_enable = true,
        handler_opts = { border = "shadow" },
    })
    lsp_status.on_attach(client, bufnr)
end

-- Null ls
null_ls.config({
    sources = {
        null_ls.builtins.formatting.stylua.with({
            args = {
                "--indent-type",
                "Spaces",
                "-",
            },
        }),
        null_ls.builtins.formatting.prettierd.with({
            filetypes = {
                "javascript",
                "javascriptreact",
                "typescript",
                "typescriptreact",
                "vue",
                "css",
                "html",
                "json",
                "yaml",
                "markdown",
                "vimwiki",
            },
        }),
    },
})
lsp["null-ls"].setup({
    on_attach = on_attach,
    capabilities = lsp_status.capabilities,
})

it's basicly same as the one with navigator. the output of lspInfo with this configure is like this:

Screen Shot 2021-09-09 at 12 40 24 PM
ray-x commented 3 years ago

I can not reproduce.


call plug#begin('~/.vim/plugged')

Plug 'neovim/nvim-lspconfig'
Plug 'ray-x/guihua.lua', {'do': 'cd lua/fzy && make' }
Plug 'ray-x/navigator.lua'
Plug 'nvim-lua/plenary.nvim'
Plug 'jose-elias-alvarez/null-ls.nvim'

call plug#end()

lua <<EOF
require 'navigator'.setup{debug = true}
local null_ls = require("null-ls")
null_ls.config({
    sources = {
    null_ls.builtins.formatting.gofumpt,
},
})
require("lspconfig")["null-ls"].setup({})

EOF

set mouse=a
set number

If I trying to save a golang file, nvim will ask which formatter would I choose, gopls or null-ls. I choose null-ls, it will format with gofumpt.

isvicy commented 3 years ago

it could happen when using a null-ls builtin formatter, such as luastyle or prettierd in my case. luastyle and prettierd use third-party binary to do the formatting. I don't use gofumpt provided by null-ls.

I will try to figure it out myself. thanks for your help. closing the issue for now.

ray-x commented 3 years ago

I am still using efm ATM. I do not see much need to turn for null-ls. Also when you start config the null-ls, there is not much log info I can debug with (debug on/off vs efm 10 levels logs). Also for formatter. efm is incremental. Which means less communication between neovim and efm.