fix(nvim): lsp typescrypt logic
This commit is contained in:
parent
a17f9eba6c
commit
2e0681d5a5
@ -41,7 +41,7 @@ nvim_lsp.html.setup {
|
|||||||
on_attach = on_attach_no_formatting,
|
on_attach = on_attach_no_formatting,
|
||||||
flags = lsp_flags,
|
flags = lsp_flags,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
cmd = {nix_vars.vscls, "--stdio"}
|
cmd = {nix_vars.vscls .. "/bin/vscode-html-language-server", "--stdio"}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- JSON LSP Configuration
|
-- JSON LSP Configuration
|
||||||
@ -49,7 +49,7 @@ nvim_lsp.jsonls.setup {
|
|||||||
on_attach = on_attach_no_formatting,
|
on_attach = on_attach_no_formatting,
|
||||||
flags = lsp_flags,
|
flags = lsp_flags,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
cmd = {nix_vars.vscls, "--stdio"}
|
cmd = {nix_vars.vscls .. "/bin/vscode-html-language-server", "--stdio"}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- CSS LSP Configuration
|
-- CSS LSP Configuration
|
||||||
@ -57,29 +57,22 @@ nvim_lsp.cssls.setup {
|
|||||||
on_attach = on_attach_no_formatting,
|
on_attach = on_attach_no_formatting,
|
||||||
flags = lsp_flags,
|
flags = lsp_flags,
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
cmd = {nix_vars.vscls, "--stdio"}
|
cmd = {nix_vars.vscls .. "/bin/vscode-html-language-server", "--stdio"}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Typescript / Javascript LSP Configuration
|
-- Typescript / Javascript LSP Configuration
|
||||||
nvim_lsp.tsserver.setup {
|
nvim_lsp.tsserver.setup {
|
||||||
|
-- on_attach = on_attach,
|
||||||
on_attach = on_attach_no_formatting,
|
on_attach = on_attach_no_formatting,
|
||||||
flags = lsp_flags,
|
flags = lsp_flags,
|
||||||
handlers = {
|
-- handlers = {
|
||||||
-- Disable Diagnostics (ESLints Job)
|
-- -- Disable Diagnostics (ESLints Job)
|
||||||
["textDocument/publishDiagnostics"] = function() end
|
-- ["textDocument/publishDiagnostics"] = function() end
|
||||||
},
|
-- },
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
cmd = {nix_vars.tsls, "--stdio"}
|
cmd = {nix_vars.tsls, "--stdio"}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Javascript / Typescript LSP Configuration
|
|
||||||
nvim_lsp.eslint.setup {
|
|
||||||
on_attach = on_attach_no_formatting,
|
|
||||||
flags = lsp_flags,
|
|
||||||
capabilities = capabilities,
|
|
||||||
cmd = {nix_vars.vscls, "--stdio"}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Svelte LSP Configuration
|
-- Svelte LSP Configuration
|
||||||
nvim_lsp.svelte.setup {
|
nvim_lsp.svelte.setup {
|
||||||
on_attach = on_attach_no_formatting,
|
on_attach = on_attach_no_formatting,
|
||||||
@ -101,25 +94,51 @@ nvim_lsp.gopls.setup {
|
|||||||
------------------------------------------------------
|
------------------------------------------------------
|
||||||
local null_ls = require("null-ls")
|
local null_ls = require("null-ls")
|
||||||
|
|
||||||
local eslint_root_files = {
|
local function has_file_in_parents(current_dir, file_pattern)
|
||||||
".eslintrc", ".eslintrc.js", ".eslintrc.json", ".eslintrc.yml"
|
-- Check if directory has file pattern
|
||||||
}
|
local function has_file(dir)
|
||||||
local prettier_root_files = {
|
local handle = vim.loop.fs_scandir(dir)
|
||||||
".prettierrc", ".prettierrc.js", ".prettierrc.json"
|
if handle then
|
||||||
}
|
while true do
|
||||||
|
local name, type = vim.loop.fs_scandir_next(handle)
|
||||||
|
if not name then break end
|
||||||
|
if type == "file" and name:match(file_pattern) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Continously walk upwards
|
||||||
|
while true do
|
||||||
|
if has_file(current_dir) then return true end
|
||||||
|
local parent_dir = vim.fn.fnamemodify(current_dir, ":h")
|
||||||
|
if parent_dir == current_dir then break end
|
||||||
|
current_dir = parent_dir
|
||||||
|
end
|
||||||
|
|
||||||
|
-- No match found
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
null_ls.setup({
|
null_ls.setup({
|
||||||
sources = {
|
sources = {
|
||||||
|
-- Prettier Formatting
|
||||||
null_ls.builtins.formatting.prettier.with({
|
null_ls.builtins.formatting.prettier.with({
|
||||||
condition = function(utils)
|
condition = function(utils)
|
||||||
return not utils.has_file(".eslintrc.yml")
|
return has_file_in_parents(vim.fn.getcwd(), "^%.prettierrc%.")
|
||||||
end
|
end
|
||||||
}), null_ls.builtins.formatting.eslint.with({
|
}), -- ESLint Diagnostics & Formatting
|
||||||
|
null_ls.builtins.diagnostics.eslint_d.with({
|
||||||
condition = function(utils)
|
condition = function(utils)
|
||||||
return utils.has_file(".eslintrc.yml")
|
return has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.")
|
||||||
|
end
|
||||||
|
}), null_ls.builtins.formatting.eslint_d.with({
|
||||||
|
condition = function(utils)
|
||||||
|
return has_file_in_parents(vim.fn.getcwd(), "^%.eslintrc%.")
|
||||||
end
|
end
|
||||||
}), null_ls.builtins.formatting.djlint.with({filetypes = {"template"}}),
|
}), null_ls.builtins.formatting.djlint.with({filetypes = {"template"}}),
|
||||||
null_ls.builtins.formatting.prettier.with({filetypes = {"svelte"}}),
|
|
||||||
null_ls.builtins.completion.spell,
|
null_ls.builtins.completion.spell,
|
||||||
null_ls.builtins.formatting.nixpkgs_fmt,
|
null_ls.builtins.formatting.nixpkgs_fmt,
|
||||||
null_ls.builtins.formatting.lua_format,
|
null_ls.builtins.formatting.lua_format,
|
||||||
|
@ -94,6 +94,7 @@ in
|
|||||||
go
|
go
|
||||||
gopls
|
gopls
|
||||||
nodePackages.eslint
|
nodePackages.eslint
|
||||||
|
nodePackages.eslint_d
|
||||||
nodePackages.pyright
|
nodePackages.pyright
|
||||||
nodePackages.svelte-language-server
|
nodePackages.svelte-language-server
|
||||||
nodePackages.typescript
|
nodePackages.typescript
|
||||||
@ -128,7 +129,7 @@ in
|
|||||||
gopls = "${pkgs.gopls}/bin/gopls",
|
gopls = "${pkgs.gopls}/bin/gopls",
|
||||||
sveltels = "${pkgs.nodePackages.svelte-language-server}/bin/svelteserver",
|
sveltels = "${pkgs.nodePackages.svelte-language-server}/bin/svelteserver",
|
||||||
tsls = "${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server",
|
tsls = "${pkgs.nodePackages.typescript-language-server}/bin/typescript-language-server",
|
||||||
vscls = "${pkgs.nodePackages.vscode-langservers-extracted}/bin/vscode-html-language-server",
|
vscls = "${pkgs.nodePackages.vscode-langservers-extracted}",
|
||||||
}
|
}
|
||||||
return nix_vars
|
return nix_vars
|
||||||
'';
|
'';
|
||||||
|
Loading…
Reference in New Issue
Block a user