mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-01-03 01:25:57 +00:00
ts: add vue support for ts_ls
This commit is contained in:
parent
ef1f22efaf
commit
52d9434377
1 changed files with 99 additions and 19 deletions
|
|
@ -17,11 +17,27 @@
|
||||||
|
|
||||||
cfg = config.vim.languages.ts;
|
cfg = config.vim.languages.ts;
|
||||||
|
|
||||||
defaultServers = ["ts_ls"];
|
defaultServers = [
|
||||||
|
"ts_ls"
|
||||||
|
"vue_ls"
|
||||||
|
];
|
||||||
servers = let
|
servers = let
|
||||||
ts_ls = {
|
ts_ls = {
|
||||||
cmd = [(getExe pkgs.typescript-language-server) "--stdio"];
|
cmd = [
|
||||||
init_options = {hostInfo = "neovim";};
|
(getExe pkgs.typescript-language-server)
|
||||||
|
"--stdio"
|
||||||
|
];
|
||||||
|
init_options = {
|
||||||
|
hostInfo = "neovim";
|
||||||
|
plugins = [
|
||||||
|
{
|
||||||
|
name = "@vue/typescript-plugin";
|
||||||
|
location = "${pkgs.vue-language-server}/lib/language-tools/packages/language-server";
|
||||||
|
languages = ["vue"];
|
||||||
|
configNamespace = "typescript";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
filetypes = [
|
filetypes = [
|
||||||
"javascript"
|
"javascript"
|
||||||
"javascriptreact"
|
"javascriptreact"
|
||||||
|
|
@ -29,6 +45,7 @@
|
||||||
"typescript"
|
"typescript"
|
||||||
"typescriptreact"
|
"typescriptreact"
|
||||||
"typescript.tsx"
|
"typescript.tsx"
|
||||||
|
"vue"
|
||||||
];
|
];
|
||||||
root_markers = ["tsconfig.json" "jsconfig.json" "package.json" ".git"];
|
root_markers = ["tsconfig.json" "jsconfig.json" "package.json" ".git"];
|
||||||
handlers = {
|
handlers = {
|
||||||
|
|
@ -48,23 +65,32 @@
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
on_attach = mkLuaInline ''
|
on_attach =
|
||||||
function(client, bufnr)
|
mkLuaInline
|
||||||
-- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in
|
# lua
|
||||||
-- `vim.lsp.buf.code_action()` if specified in `context.only`.
|
''
|
||||||
vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function()
|
function(client, bufnr)
|
||||||
local source_actions = vim.tbl_filter(function(action)
|
-- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in
|
||||||
return vim.startswith(action, 'source.')
|
-- `vim.lsp.buf.code_action()` if specified in `context.only`.
|
||||||
end, client.server_capabilities.codeActionProvider.codeActionKinds)
|
vim.api.nvim_buf_create_user_command(0, 'LspTypescriptSourceAction', function()
|
||||||
|
local source_actions = vim.tbl_filter(function(action)
|
||||||
|
return vim.startswith(action, 'source.')
|
||||||
|
end, client.server_capabilities.codeActionProvider.codeActionKinds)
|
||||||
|
|
||||||
vim.lsp.buf.code_action({
|
vim.lsp.buf.code_action({
|
||||||
context = {
|
context = {
|
||||||
only = source_actions,
|
only = source_actions,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
end, {})
|
end, {})
|
||||||
end
|
|
||||||
'';
|
if vim.bo.filetype == 'vue' then
|
||||||
|
client.server_capabilities.semanticTokensProvider.full = false
|
||||||
|
else
|
||||||
|
client.server_capabilities.semanticTokensProvider.full = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
inherit ts_ls;
|
inherit ts_ls;
|
||||||
|
|
@ -73,6 +99,60 @@
|
||||||
# redirect the user to the correct server.
|
# redirect the user to the correct server.
|
||||||
tsserver = ts_ls;
|
tsserver = ts_ls;
|
||||||
|
|
||||||
|
vue_ls = {
|
||||||
|
cmd = [
|
||||||
|
(getExe pkgs.vue-language-server)
|
||||||
|
"--stdio"
|
||||||
|
];
|
||||||
|
filetypes = [
|
||||||
|
"vue"
|
||||||
|
];
|
||||||
|
root_markers = [
|
||||||
|
"tsconfig.json"
|
||||||
|
"jsconfig.json"
|
||||||
|
"package.json"
|
||||||
|
".git"
|
||||||
|
];
|
||||||
|
on_init =
|
||||||
|
mkLuaInline
|
||||||
|
# lua
|
||||||
|
''
|
||||||
|
function(client)
|
||||||
|
client.handlers['tsserver/request'] = function(_, result, context)
|
||||||
|
local ts_clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'ts_ls' })
|
||||||
|
local clients = {}
|
||||||
|
|
||||||
|
vim.list_extend(clients, ts_clients)
|
||||||
|
|
||||||
|
if #clients == 0 then
|
||||||
|
vim.notify('Could not find `vtsls` or `ts_ls` lsp client, `vue_ls` would not work without it.', vim.log.levels.ERROR)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ts_client = clients[1]
|
||||||
|
|
||||||
|
local param = unpack(result)
|
||||||
|
local id, command, payload = unpack(param)
|
||||||
|
ts_client:exec_cmd({
|
||||||
|
title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd`
|
||||||
|
command = 'typescript.tsserverRequest',
|
||||||
|
arguments = {
|
||||||
|
command,
|
||||||
|
payload,
|
||||||
|
},
|
||||||
|
}, { bufnr = context.bufnr }, function(_, r)
|
||||||
|
local response = r and r.body
|
||||||
|
-- TODO: handle error or response nil here, e.g. logging
|
||||||
|
-- NOTE: Do NOT return if there's an error or no response, just return nil back to the vue_ls to prevent memory leak
|
||||||
|
local response_data = { { id, response } }
|
||||||
|
|
||||||
|
---@diagnostic disable-next-line: param-type-mismatch
|
||||||
|
client:notify('tsserver/response', response_data)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
denols = {
|
denols = {
|
||||||
cmd = [(getExe pkgs.deno) "lsp"];
|
cmd = [(getExe pkgs.deno) "lsp"];
|
||||||
cmd_env = {NO_COLOR = true;};
|
cmd_env = {NO_COLOR = true;};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue