Migrated lspconfig for ts_ls

This commit is contained in:
2025-05-13 10:53:41 +02:00
parent f3157898b6
commit 9206d3ca43

View File

@@ -83,61 +83,33 @@ function LSPRangeFormatFunction()
}) })
end end
-- Set different settings for different languages' LSP -- Set different settings for different languages' LSP
-- LSP list: https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md
-- How to use setup({}): https://github.com/neovim/nvim-lspconfig/wiki/Understanding-setup-%7B%7D
-- - the settings table is sent to the LSP
-- - on_attach: a lua callback function to run after LSP attaches to a given buffer
local lspconfig = require('lspconfig') local lspconfig = require('lspconfig')
-- from :h mason-lspconfig-automatic-server-setup lspconfig.ts_ls.setup {
require('mason-lspconfig').setup_handlers({
-- The first entry (without a key) will be the default handler
-- and will be called for each installed server that doesn't have
-- a dedicated handler.
function(server_name) -- default handler (optional)
if server_name == 'ts_ls' then
-- taken from https://github.com/vuejs/language-tools
-- If you are using mason.nvim, you can get the ts_plugin_path like this
local mason_registry = require('mason-registry')
local vue_language_server_path = mason_registry.get_package('vue-language-server'):get_install_path() ..
'/node_modules/@vue/language-server'
lspconfig[server_name].setup {
init_options = { init_options = {
plugins = { plugins = {
{ {
name = '@vue/typescript-plugin', name = '@vue/typescript-plugin',
location = vue_language_server_path, location = vim.fn.expand '$MASON/packages' .. '/vue-language-server' .. '/node_modules/@vue/language-server',
languages = { 'vue' }, languages = { 'vue' },
}, },
}, },
}, },
filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' },
}
else
lspconfig[server_name].setup {
}
end
end
})
-- setup sqls support
lspconfig.sqls.setup {
settings = {
sqls = {
connections = {
-- {
-- driver = 'mysql',
-- dataSourceName = 'root:root@tcp(127.0.0.1:13306)/world',
-- },
{
driver = 'postgresql',
dataSourceName = 'host=127.0.0.1 port=5432 sslmode=disable',
},
},
},
},
} }
-- add autoformat to Dioxus projects
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = "*.rs",
callback = function()
local cwd = vim.lsp.buf.list_workspace_folders()
if not (cwd == nil) then
if vim.fn.filereadable(cwd[1] .. "/Dioxus.toml") == 1 then
local command = "dx fmt --file %"
vim.cmd("silent ! " .. command)
-- vim.notify(command)
end
end
end,
})