feat: enhance typescript configuration
Remove several extensions and add typescript-tools along with conform and format-ts-errors (could be better but is the best I found)
This commit is contained in:
parent
9055397ba0
commit
b700549bf3
6 changed files with 100 additions and 18 deletions
|
|
@ -1,7 +0,0 @@
|
||||||
return {
|
|
||||||
filetypes = {
|
|
||||||
"javascript",
|
|
||||||
"typescript",
|
|
||||||
"vue",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
@ -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/",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
29
lua/custom/plugins/conform.lua
Normal file
29
lua/custom/plugins/conform.lua
Normal file
|
|
@ -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,
|
||||||
|
}
|
||||||
9
lua/custom/plugins/format-ts-errors.lua
Normal file
9
lua/custom/plugins/format-ts-errors.lua
Normal file
|
|
@ -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,
|
||||||
|
}
|
||||||
8
lua/custom/plugins/typecript-tools.lua
Normal file
8
lua/custom/plugins/typecript-tools.lua
Normal file
|
|
@ -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
|
||||||
|
}
|
||||||
54
lua/custom/typescript-tools.lua
Normal file
54
lua/custom/typescript-tools.lua
Normal file
|
|
@ -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", "<leader><CR>", "<cmd>vsplit term://bun %<CR>")
|
||||||
|
-- open the Go scratchpad
|
||||||
|
vim.keymap.set("n", "<leader>q", "<cmd>e ~/personal/Node/test/main.ts<CR>")
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue