From 53953488fef9a13c1a78e080c2903fc674e1f2c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20La=C3=ADn?= Date: Sat, 24 Feb 2024 01:27:08 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(nvim):=20typescri?= =?UTF-8?q?pt-extended=20extra=20big=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit added typescript-tools. created variable to choose between typescript-tools (which has some things I need to work on like inlay hints not working or disabling when inside a deno based project) or lsp-config tsserver --- .../extras/lang/web/typescript-extended.lua | 74 ++++++++++++------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/.config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua b/.config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua index 6767e802..a2832933 100644 --- a/.config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua +++ b/.config/nvim/lua/plugins/extras/lang/web/typescript-extended.lua @@ -1,14 +1,5 @@ -local source_action = function(name) - return function() - vim.lsp.buf.code_action({ - apply = true, - context = { - only = { string.format("source.%s.ts", name) }, - diagnostics = {}, - }, - }) - end -end +local ts_server_activated = true +local ft = { "typescript", "typescriptreact", "javascript", "javascriptreact" } local inlayHints = { includeInlayParameterNameHints = "all", @@ -21,17 +12,16 @@ local inlayHints = { includeInlayEnumMemberValueHints = true, } -local function denoConfigExists() - local configs = { "deno.json", "deno.jsonc" } - local root = require("lazyvim.util.root").get() - - for _, config in ipairs(configs) do - if vim.fn.filereadable(root .. "/" .. config) == 1 then - return true - end +local source_action = function(name) + return function() + vim.lsp.buf.code_action({ + apply = true, + context = { + only = { string.format("source.%s.ts", name) }, + diagnostics = {}, + }, + }) end - - return false end return { @@ -49,6 +39,7 @@ return { opts = { servers = { tsserver = { + enabled = ts_server_activated, init_options = { preferences = { disableSuggestions = true, @@ -82,13 +73,44 @@ return { }, denols = {}, }, - setup = { - tsserver = function(_, opts) - -- Disable tsserver if denols is present - return denoConfigExists() - end, + }, + }, + { + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + enabled = not ts_server_activated, + ft = ft, + opts = { + cmd = { "typescript-language-server", "--stdio" }, + settings = { + code_lens = "all", + expose_as_code_action = "all", + tsserver_plugins = { + "@styled/typescript-styled-plugin", + }, + tsserver_file_preferences = { + completions = { + completeFunctionCalls = true, + }, + init_options = { + preferences = { + disableSuggestions = true, + }, + }, + includeInlayParameterNameHints = "all", + includeInlayEnumMemberValueHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayFunctionParameterTypeHints = true, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayVariableTypeHints = true, + }, }, }, + keys = { + { "co", ft = ft, "TSToolsOrganizeImports", desc = "Organize Imports" }, + { "cR", ft = ft, "TSToolsRemoveUnusedImports", desc = "Remove Unused Imports" }, + { "cM", ft = ft, "TSToolsAddMissingImports", desc = "Add Missing Imports" }, + }, }, { "nvim-treesitter/nvim-treesitter",