diff options
Diffstat (limited to 'lua/lsp')
| -rw-r--r-- | lua/lsp/efm-general-ls.lua | 78 | ||||
| -rw-r--r-- | lua/lsp/init.lua | 45 | ||||
| -rw-r--r-- | lua/lsp/js-ts-ls.lua | 7 | 
3 files changed, 59 insertions, 71 deletions
| diff --git a/lua/lsp/efm-general-ls.lua b/lua/lsp/efm-general-ls.lua index 53327415..d771d898 100644 --- a/lua/lsp/efm-general-ls.lua +++ b/lua/lsp/efm-general-ls.lua @@ -1,25 +1,40 @@  -- Example configuations here: https://github.com/mattn/efm-langserver +-- python +local flake8 = { +    LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -", +    lintStdin = true, +    lintFormats = {"%f:%l:%c: %m"} +} +local isort = {formatCommand = "isort --quiet -", formatStdin = true} +local yapf = {formatCommand = "yapf --quiet", formatStdin = true} +-- lua +local luaFormat = { +    formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120", +    formatStdin = true +} +-- JavaScript/React/TypeScript +local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true} + +local eslint = { +    lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}", +    lintIgnoreExitCode = true, +    lintStdin = true, +    lintFormats = {"%f:%l:%c: %m"}, +    formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}", +    formatStdin = true +} +  require"lspconfig".efm.setup { -    init_options = {documentFormatting = true}, -    filetypes = {"lua", "python"}, +    -- init_options = {initializationOptions}, +    init_options = {documentFormatting = true, codeAction = false}, +    filetypes = {"lua", "python", "javascriptreact", "javascript"},      settings = {          rootMarkers = {".git/"},          languages = { -            lua = { -                { -                    formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=100", -                    formatStdin = true -                } -            }, -            python = { -                { -                    LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -", -                    lintStdin = true, -                    lintFormats = {"%f:%l:%c: %m"}, -                    formatCommand = "yapf --quiet", -                    formatStdin = true -                } -            } +            lua = {luaFormat}, +            python = {isort, yapf}, +            javascriptreact = {prettier, eslint}, +            javascript = {prettier, eslint}          }      }  } @@ -28,32 +43,3 @@ require"lspconfig".efm.setup {  -- TODO also shellcheck and shell formatting  -- Also find way to toggle format on save  -- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim --- { ---   lintCommand = "eslint_d -f unix --stdin --stdin-filename ${INPUT}", ---   lintIgnoreExitCode = true, ---   lintStdin = true, ---   lintFormats = {"%f:%l:%c: %m"}, --- } - - --- local eslint = { ---   lintCommand = './node_modules/.bin/eslint -f compact --stdin', ---   lintStdin = true, ---   lintFormats = {'%f: line %l, col %c, %trror - %m', '%f: line %l, col %c, %tarning - %m'}, ---   lintIgnoreExitCode = true, ---   formatCommand = './node_modules/.bin/prettier-eslint --stdin --single-quote --print-width 120', ---   formatStdin = true, --- } --- --- nvim_lsp.efm.setup({ ---     init_options = { documentFormatting = true }, ---     root_dir = nvim_lsp.util.root_pattern('.git/'), ---     filetypes = {'javascript', 'javascriptreact'}, ---     settings = { ---       rootMarkers = {'.git/'}, ---       languages = { ---         javascript = {eslint}, ---         javascriptreact = {eslint}, ---       } ---     } --- }) diff --git a/lua/lsp/init.lua b/lua/lsp/init.lua index 12ce36a1..9a1bb511 100644 --- a/lua/lsp/init.lua +++ b/lua/lsp/init.lua @@ -1,24 +1,12 @@  -- TODO figure out why this don't work -vim.fn.sign_define("LspDiagnosticsSignError", { -    texthl = "LspDiagnosticsSignError", -    text = "", -    numhl = "LspDiagnosticsSignError" -}) -vim.fn.sign_define("LspDiagnosticsSignWarning", { -    texthl = "LspDiagnosticsSignWarning", -    text = "", -    numhl = "LspDiagnosticsSignWarning" -}) -vim.fn.sign_define("LspDiagnosticsSignInformation", { -    texthl = "LspDiagnosticsSignInformation", -    text = "", -    numhl = "LspDiagnosticsSignInformation" -}) -vim.fn.sign_define("LspDiagnosticsSignHint", { -    texthl = "LspDiagnosticsSignHint", -    text = "", -    numhl = "LspDiagnosticsSignHint" -}) +vim.fn.sign_define("LspDiagnosticsSignError", +                   {texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError"}) +vim.fn.sign_define("LspDiagnosticsSignWarning", +                   {texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning"}) +vim.fn.sign_define("LspDiagnosticsSignInformation", +                   {texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation"}) +vim.fn.sign_define("LspDiagnosticsSignHint", +                   {texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint"})  vim.cmd('nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>')  vim.cmd('nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>') @@ -42,10 +30,7 @@ autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]]  -- Java  -- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR> -local lsp_config = {} - -function lsp_config.common_on_attach(client, bufnr) - +local function documentHighlight(client, bufnr)      -- Set autocommands conditional on server_capabilities      if client.resolved_capabilities.document_highlight then          vim.api.nvim_exec([[ @@ -58,7 +43,19 @@ function lsp_config.common_on_attach(client, bufnr)          autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()        augroup END      ]], false) +      end + +end +local lsp_config = {} + +function lsp_config.common_on_attach(client, bufnr) +    documentHighlight(client, bufnr) +end + +function lsp_config.tsserver_on_attach(client, bufnr) +    lsp_config.common_on_attach(client, bufnr) +    client.resolved_capabilities.document_formatting = false  end  -- Use a loop to conveniently both setup defined servers diff --git a/lua/lsp/js-ts-ls.lua b/lua/lsp/js-ts-ls.lua index 0c4a02e3..a0bd7a88 100644 --- a/lua/lsp/js-ts-ls.lua +++ b/lua/lsp/js-ts-ls.lua @@ -7,4 +7,9 @@  -- require'completion'.on_attach(client)  -- require'illuminate'.on_attach(client)  -- end -require'lspconfig'.tsserver.setup {on_attach = require'lsp'.common_on_attach} +require'lspconfig'.tsserver.setup { +    on_attach = require'lsp'.tsserver_on_attach, +    -- This makes sure tsserver is not used for formatting (I prefer prettier) +    -- on_attach = require'lsp'.common_on_attach, +    settings = {documentFormatting = false} +} | 
