From 800eb42600b62cf362b2d5d598927187e33b4493 Mon Sep 17 00:00:00 2001 From: Emilia Date: Thu, 15 Sep 2022 00:21:27 +1200 Subject: fix(astro): enable typescript server (#2139) As of version 0.24 of the LSP, a `typescript` field is required, with the same convention as `volar`. --- lua/lspconfig/server_configurations/astro.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'lua') diff --git a/lua/lspconfig/server_configurations/astro.lua b/lua/lspconfig/server_configurations/astro.lua index 61d5d301..b643e16d 100644 --- a/lua/lspconfig/server_configurations/astro.lua +++ b/lua/lspconfig/server_configurations/astro.lua @@ -7,14 +7,32 @@ if vim.fn.has 'win32' == 1 then cmd = { 'cmd.exe', '/C', bin_name, '--stdio' } end +local function get_typescript_server_path(root_dir) + local project_root = util.find_node_modules_ancestor(root_dir) + return project_root and (util.path.join(project_root, 'node_modules', 'typescript', 'lib', 'tsserverlibrary.js')) + or '' +end + return { default_config = { cmd = cmd, filetypes = { 'astro' }, root_dir = util.root_pattern('package.json', 'tsconfig.json', 'jsconfig.json', '.git'), init_options = { + typescript = { + serverPath = '', + }, configuration = {}, }, + on_new_config = function(new_config, new_root_dir) + if + new_config.init_options + and new_config.init_options.typescript + and new_config.init_options.typescript.serverPath == '' + then + new_config.init_options.typescript.serverPath = get_typescript_server_path(new_root_dir) + end + end, }, docs = { description = [[ -- cgit v1.2.3-70-g09d2