From 265c64ae4a870d71155ec99437d806bef65aa633 Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Wed, 20 Oct 2021 01:57:38 +0700 Subject: [PATCH] neovim: lsp: add eslint language server --- home/.config/nvim/lua/modules/lsp.lua | 46 +++++++++++++++++++++------ home/.config/nvim/scripts/install | 4 +-- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/home/.config/nvim/lua/modules/lsp.lua b/home/.config/nvim/lua/modules/lsp.lua index d360ad3..56698ed 100644 --- a/home/.config/nvim/lua/modules/lsp.lua +++ b/home/.config/nvim/lua/modules/lsp.lua @@ -1,4 +1,3 @@ --- TODO: eslint language server local M = {} function M.lsp_conf() @@ -229,6 +228,42 @@ function M.lsp_conf() filetypes = {'html', 'markdown'} } + -- Eslint + lspconf.eslint.setup { + on_attach = on_attach, + capabilities = capabilities, + cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-eslint-language-server', '--stdio'}, + filetypes = {'javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'svelte'}, + handlers = { + ['eslint/noConfig'] = function() + vim.notify('Unable to parse ESLint config.', vim.log.levels.WARN) + end + }, + settings = { + codeAction = { + disableRuleComment = { + enable = true, + location = 'separateLine' + }, + showDocumentation = {enable = true} + }, + codeActionOnSave = { + enable = false, -- run ':EslintFixAll' manually + mode = 'all' + }, + format = true, + nodePath = '', + onIgnoredFiles = 'off', + packageManager = 'npm', + quiet = false, + rulesCustomizations = {}, + run = 'onType', + useESLintClass = false, + validate = 'on', + workingDirectory = {mode = 'auto'} + } + } + -- JSON lspconf.jsonls.setup { on_attach = on_attach, @@ -316,12 +351,6 @@ function M.lsp_conf() -- null_ls.builtins.formatting.cmake_format.with { -- command = 'cmake-format' -- }, - -- null_ls.builtins.formatting.eslint.with { - -- condition = function(utils) - -- return utils.root_has_file('.eslintrc.js') - -- end, - -- command = 'eslint' - -- }, null_ls.builtins.formatting.fish_indent, -- null_ls.builtins.formatting.fixjson.with { -- command = 'fixjson' @@ -374,9 +403,6 @@ function M.lsp_conf() -- null_ls.builtins.diagnostics.codespell.with { -- command = 'codespell' -- }, - -- null_ls.builtins.diagnostics.eslint.with { - -- command = 'eslint' - -- }, -- null_ls.builtins.diagnostics.flake8.with { -- command = 'flake8' -- }, diff --git a/home/.config/nvim/scripts/install b/home/.config/nvim/scripts/install index 1002741..48e744a 100755 --- a/home/.config/nvim/scripts/install +++ b/home/.config/nvim/scripts/install @@ -2,7 +2,7 @@ if [ "$#" -ne 1 ]; then echo "Usage:" - printf " - %s server_name: install specified server\n" "$0" + printf " - %s [server_name]: install specified server\n" "$0" printf " - %s -lsp: install all lsp servers\n" "$0" printf " - %s -dap: install all dap servers\n" "$0" printf " - %s -lint: install everything\n" "$0" @@ -27,7 +27,7 @@ else # Each server should have an unique name server_path=$(find "${nvim_script_dir}" -mindepth 2 -type f -name "$1" | head -n 1) if [ -z "${server_path}" ]; then - echo "Incorrect server name $1" + printf "Incorrect server name \033[1;31m%s\033[0m.\n" "$1" exit 1 fi printf "\033[1;34mInstalling \033[1;32m%s\033[1;34m...\033[0m\n" "$1"