mirror of
https://github.com/NotAShelf/nvf.git
synced 2026-04-27 20:05:23 +00:00
lsp/presets/typescript-language-server: init
This commit is contained in:
parent
3f11748007
commit
32ba93fe34
3 changed files with 63 additions and 0 deletions
|
|
@ -6,5 +6,6 @@
|
|||
./tinymist.nix
|
||||
./twig-language-server.nix
|
||||
./typescript-go.nix
|
||||
./typescript-language-server.nix
|
||||
];
|
||||
}
|
||||
|
|
|
|||
60
modules/plugins/lsp/presets/typescript-language-server.nix
Normal file
60
modules/plugins/lsp/presets/typescript-language-server.nix
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.meta) getExe;
|
||||
inherit (lib.modules) mkIf;
|
||||
inherit (lib.options) mkEnableOption;
|
||||
inherit (lib.generators) mkLuaInline;
|
||||
|
||||
cfg = config.vim.lsp.presets.typescript-language-server;
|
||||
in {
|
||||
options.vim.lsp.presets.typescript-language-server = {
|
||||
enable = mkEnableOption "the Typescript Language Server";
|
||||
};
|
||||
|
||||
config = mkIf cfg.enable {
|
||||
vim.lsp.servers.typescript-language-server = {
|
||||
enable = true;
|
||||
cmd = [(getExe pkgs.typescript-language-server) "--stdio"];
|
||||
root_markers = [".git" "package.json"];
|
||||
init_options = {hostInfo = "neovim";};
|
||||
handlers = {
|
||||
# handle rename request for certain code actions like extracting functions / types
|
||||
"_typescript.rename" = mkLuaInline ''
|
||||
function(_, result, ctx)
|
||||
local client = assert(vim.lsp.get_client_by_id(ctx.client_id))
|
||||
vim.lsp.util.show_document({
|
||||
uri = result.textDocument.uri,
|
||||
range = {
|
||||
start = result.position,
|
||||
['end'] = result.position,
|
||||
},
|
||||
}, client.offset_encoding)
|
||||
vim.lsp.buf.rename()
|
||||
return vim.NIL
|
||||
end
|
||||
'';
|
||||
};
|
||||
on_attach = mkLuaInline ''
|
||||
function(client, bufnr)
|
||||
-- ts_ls provides `source.*` code actions that apply to the whole file. These only appear in
|
||||
-- `vim.lsp.buf.code_action()` if specified in `context.only`.
|
||||
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({
|
||||
context = {
|
||||
only = source_actions,
|
||||
},
|
||||
})
|
||||
end, {})
|
||||
end
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue