From 9206d3ca435dc63d5075056b4ee85f28b244afbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sascha=20L=C3=BCdecke?= Date: Tue, 13 May 2025 10:53:41 +0200 Subject: [PATCH] Migrated lspconfig for ts_ls --- lua/lsp.lua | 74 +++++++++++++++++------------------------------------ 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/lua/lsp.lua b/lua/lsp.lua index c1a2405..8a34b1b 100644 --- a/lua/lsp.lua +++ b/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 { - init_options = { - plugins = { - { - name = '@vue/typescript-plugin', - location = vue_language_server_path, - 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', - }, +lspconfig.ts_ls.setup { + init_options = { + plugins = { + { + name = '@vue/typescript-plugin', + location = vim.fn.expand '$MASON/packages' .. '/vue-language-server' .. '/node_modules/@vue/language-server', + languages = { 'vue' }, }, }, }, + filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, } + +-- 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, +})