Migrated lspconfig for ts_ls
This commit is contained in:
62
lua/lsp.lua
62
lua/lsp.lua
@@ -83,61 +83,33 @@ function LSPRangeFormatFunction()
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
-- 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')
|
||||
|
||||
-- from :h mason-lspconfig-automatic-server-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 {
|
||||
lspconfig.ts_ls.setup {
|
||||
init_options = {
|
||||
plugins = {
|
||||
{
|
||||
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' },
|
||||
},
|
||||
},
|
||||
},
|
||||
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,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user