diff --git a/lua/custom/lsp/config/ts_ls.lua b/lua/custom/lsp/config/ts_ls.lua deleted file mode 100644 index 5991819..0000000 --- a/lua/custom/lsp/config/ts_ls.lua +++ /dev/null @@ -1,7 +0,0 @@ -return { - filetypes = { - "javascript", - "typescript", - "vue", - }, -} diff --git a/lua/custom/lsp/config/volar.lua b/lua/custom/lsp/config/volar.lua deleted file mode 100644 index c27cc1a..0000000 --- a/lua/custom/lsp/config/volar.lua +++ /dev/null @@ -1,11 +0,0 @@ -return { - filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, - init_options = { - vue = { - hybridMode = false, - }, - typescript = { - tsdk = "/home/simon/.local/share/nvim/mason/packages/vue-language-server/node_modules/typescript/lib/", - }, - }, -} diff --git a/lua/custom/plugins/conform.lua b/lua/custom/plugins/conform.lua new file mode 100644 index 0000000..513adcf --- /dev/null +++ b/lua/custom/plugins/conform.lua @@ -0,0 +1,29 @@ +return { + 'stevearc/conform.nvim', + config = function() + require("conform").setup({ + formatters_by_ft = { + html = { "prettierd" }, + yaml = { "prettierd" }, + javascript = { "prettierd" }, + javascriptreact = { "prettierd" }, + markdown = { "prettierd" }, + typescript = { "prettierd" }, + typescriptreact = { "prettierd" }, + ["*"] = { "trim_whitespace" }, + }, + format_on_save = { + timeout_ms = 500, + lsp_fallback = true, + }, + formatters = { + prettierd = { + condition = function() + return vim.loop.fs_realpath(".prettierrc.js") ~= nil or + vim.loop.fs_realpath(".prettierrc") ~= nil + end, + }, + }, + }) + end, +} diff --git a/lua/custom/plugins/format-ts-errors.lua b/lua/custom/plugins/format-ts-errors.lua new file mode 100644 index 0000000..3484df0 --- /dev/null +++ b/lua/custom/plugins/format-ts-errors.lua @@ -0,0 +1,9 @@ +return { + "davidosomething/format-ts-errors.nvim", + config = function() + require("format-ts-errors").setup({ + add_markdown = true, -- wrap output with markdown ```ts ``` markers + start_indent_level = 1, -- initial indent + }) + end, +} diff --git a/lua/custom/plugins/typecript-tools.lua b/lua/custom/plugins/typecript-tools.lua new file mode 100644 index 0000000..782ad68 --- /dev/null +++ b/lua/custom/plugins/typecript-tools.lua @@ -0,0 +1,8 @@ +return { + "pmizio/typescript-tools.nvim", + dependencies = { "nvim-lua/plenary.nvim", "neovim/nvim-lspconfig" }, + opts = {}, + config = function() + require("custom.typescript-tools") + end +} diff --git a/lua/custom/typescript-tools.lua b/lua/custom/typescript-tools.lua new file mode 100644 index 0000000..1cf4a84 --- /dev/null +++ b/lua/custom/typescript-tools.lua @@ -0,0 +1,54 @@ +require("typescript-tools").setup { + on_attach = + function(client, _) + client.server_capabilities.documentFormattingProvider = false + client.server_capabilities.documentRangeFormattingProvider = false + + -- run the current go file in a vertical split terminal pane + vim.keymap.set("n", "", "vsplit term://bun %") + -- open the Go scratchpad + vim.keymap.set("n", "q", "e ~/personal/Node/test/main.ts") + end, + settings = { + jsx_close_tag = { + enable = true, + filetypes = { "javascriptreact", "typescriptreact" }, + } + }, + handlers = { + ["textDocument/publishDiagnostics"] = function( + _, + result, + ctx, + config + ) + if result.diagnostics == nil then + return + end + + -- ignore some tsserver diagnostics + local idx = 1 + while idx <= #result.diagnostics do + local entry = result.diagnostics[idx] + + local formatter = require('format-ts-errors')[entry.code] + entry.message = formatter and formatter(entry.message) or entry.message + + -- codes: https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json + if entry.code == 80001 then + -- { message = "File is a CommonJS module; it may be converted to an ES module.", } + table.remove(result.diagnostics, idx) + else + idx = idx + 1 + end + end + + vim.lsp.diagnostic.on_publish_diagnostics( + _, + result, + ctx, + config + ) + end, + }, +}