diff options
| author | William Boman <william@redwill.se> | 2021-10-14 17:45:54 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-14 08:45:54 -0700 |
| commit | dd8c77a689b9e69bb08693d6d387cbb93669a791 (patch) | |
| tree | 4b70439bb332c573209ad604f23e3dd4d5b52382 /lua | |
| parent | feat: add emmet_ls (#1295) (diff) | |
| download | nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.tar nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.tar.gz nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.tar.bz2 nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.tar.lz nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.tar.xz nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.tar.zst nvim-lspconfig-dd8c77a689b9e69bb08693d6d387cbb93669a791.zip | |
fix(eslint): provide extra settings to make it work outside of a VSCode context (#1299)
* avoid word splitting when opening doc, also add windows support
* add settings that makes server work outside a VSCode context
* add more custom handlers
* change root pattern to search for eslint config file formats
See https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats.
* specify workspaceFolder in on_new_config
* use uv_os_uname() to determine OS
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/lspconfig/eslint.lua | 51 |
1 files changed, 43 insertions, 8 deletions
diff --git a/lua/lspconfig/eslint.lua b/lua/lspconfig/eslint.lua index a3ddfd17..54d17d21 100644 --- a/lua/lspconfig/eslint.lua +++ b/lua/lspconfig/eslint.lua @@ -54,21 +54,37 @@ configs.eslint = { 'typescriptreact', 'typescript.tsx', }, - root_dir = util.root_pattern('.eslintrc.json', '.eslintrc.js', 'package.json', 'tsconfig.json', '.git'), + -- https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-file-formats + root_dir = util.root_pattern( + '.eslintrc.js', + '.eslintrc.cjs', + '.eslintrc.yaml', + '.eslintrc.yml', + '.eslintrc.json', + 'package.json' + ), + -- Refer to https://github.com/Microsoft/vscode-eslint#settings-options for documentation. settings = { - validate = 'off', + validate = 'on', packageManager = 'npm', useESLintClass = false, codeActionOnSave = { enable = false, mode = 'all', }, - format = false, + format = true, quiet = false, onIgnoredFiles = 'off', rulesCustomizations = {}, run = 'onType', - nodePath = vim.NIL, + -- If nodePath is a non-null/undefined value the eslint LSP runs into runtime exceptions. + -- + -- It's recommended not to change this. + nodePath = '', + -- Automatically determine working directory by locating .eslintrc config files. + -- + -- It's recommended not to change this. + workingDirectory = { mode = 'auto' }, codeAction = { disableRuleComment = { enable = true, @@ -79,13 +95,26 @@ configs.eslint = { }, }, }, + on_new_config = function(config, new_root_dir) + -- The "workspaceFolder" is a VSCode concept. It limits how far the + -- server will traverse the file system when locating the ESLint config + -- file (e.g., .eslintrc). + config.settings.workspaceFolder = { + uri = new_root_dir, + name = vim.fn.fnamemodify(new_root_dir, ':t'), + } + end, handlers = { ['eslint/openDoc'] = function(_, result) if not result then return end - vim.cmd('!open ' .. result.url) - return {} + local sysname = vim.loop.os_uname().sysname + if sysname:match 'Windows' then + os.execute(string.format('start %q', result.url)) + else + os.execute(string.format('open %q', result.url)) + end end, ['eslint/confirmESLintExecution'] = function(_, result) if not result then @@ -93,6 +122,12 @@ configs.eslint = { end return 4 -- approved end, + ['eslint/probeFailed'] = function() + vim.notify('ESLint probe failed.', vim.log.levels.WARN) + end, + ['eslint/noLibrary'] = function() + vim.notify('Unable to find ESLint library.', vim.log.levels.WARN) + end, }, }, commands = { @@ -121,8 +156,8 @@ autocmd BufWritePre <buffer> <cmd>EslintFixAll<CR> See [vscode-eslint](https://github.com/microsoft/vscode-eslint/blob/55871979d7af184bf09af491b6ea35ebd56822cf/server/src/eslintServer.ts#L216-L229) for configuration options. -Additional messages you can handle: eslint/probeFailed, eslint/noLibrary, eslint/noConfig -Messages already handled in lspconfig: eslint/openDoc, eslint/confirmESLintExecution +Additional messages you can handle: eslint/noConfig +Messages already handled in lspconfig: eslint/openDoc, eslint/confirmESLintExecution, eslint/probeFailed, eslint/noLibrary ]], }, } |
