Skip to content

Commit

Permalink
feat(nvim): enable vtsls
Browse files Browse the repository at this point in the history
  • Loading branch information
radoslawgrochowski committed Aug 1, 2024
1 parent cd8260e commit 7575f71
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
53 changes: 53 additions & 0 deletions modules/nvim/plugins/lsp/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local lspconfig = require 'lspconfig'
local lspformat = require 'lsp-format'
lspformat.setup {}

vim.lsp.inlay_hint.enable(true)
local capabilities = require('cmp_nvim_lsp').default_capabilities()

wk.register {
Expand Down Expand Up @@ -73,6 +74,8 @@ local jsFiletypes = {
'typescript.tsx',
}

require('lspconfig.configs').vtsls = require('vtsls').lspconfig

lspconfig.vtsls.setup {
filetypes = jsFiletypes,
settings = {
Expand All @@ -91,6 +94,56 @@ lspconfig.vtsls.setup {
},

capabilities = capabilities,
on_attach = function(client, buffer)
client.commands['_typescript.moveToFileRefactoring'] = function(command, ctx)
---@type string, string, lsp.Range
local action, uri, range = unpack(command.arguments)

local function move(newf)
client.request('workspace/executeCommand', {
command = command.command,
arguments = { action, uri, range, newf },
})
end

local fname = vim.uri_to_fname(uri)
client.request('workspace/executeCommand', {
command = 'typescript.tsserverRequest',
arguments = {
'getMoveToRefactoringFileSuggestions',
{
file = fname,
startLine = range.start.line + 1,
startOffset = range.start.character + 1,
endLine = range['end'].line + 1,
endOffset = range['end'].character + 1,
},
},
}, function(_, result)
---@type string[]
local files = result.body.files
table.insert(files, 1, 'Enter new path...')
vim.ui.select(files, {
prompt = 'Select move destination:',
format_item = function(f)
return vim.fn.fnamemodify(f, ':~:.')
end,
}, function(f)
if f and f:find '^Enter new path' then
vim.ui.input({
prompt = 'Enter move destination:',
default = vim.fn.fnamemodify(fname, ':h') .. '/',
completion = 'file',
}, function(newf)
return newf and move(newf)
end)
elseif f then
move(f)
end
end)
end)
end
end,
}

lspconfig.eslint.setup {
Expand Down
1 change: 1 addition & 0 deletions modules/nvim/plugins/lsp/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
fidget-nvim
nvim-lspconfig
lsp-format-nvim
pkgs.localVimPlugins.vtsls-nvim
];
extraPackages = with pkgs; [
efm-langserver
Expand Down
1 change: 1 addition & 0 deletions overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
{
nixpkgsCustom = (import ./nixpkgs-custom.nix { inherit inputs; }).nixpkgsCustom;
nixpkgsLocalNodePackages = (import ./nixpkgs-local-node-packages.nix { inherit inputs; }).nixpkgsLocalNodePackages;
nixpkgsLocalVimPlugins = (import ./nixpkgs-local-vim-plugins.nix { inherit inputs; }).nixpkgsLocalVimPlugins;
}
24 changes: 24 additions & 0 deletions overlays/nixpkgs-local-vim-plugins.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{ inputs, ... }:
{
nixpkgsLocalVimPlugins = final: _prev: {
localVimPlugins = (
let
system = final.system;
pkgs = import inputs.nixpkgs { inherit system; };
in
{
vtsls-nvim = pkgs.vimUtils.buildVimPlugin
{
name = "vtsls-nvim";
src = pkgs.fetchFromGitHub {
owner = "yioneko";
repo = "nvim-vtsls";
rev = "45c6dfea9f83a126e9bfc5dd63430562b3f8af16";
hash = "sha256-/y1k7FHfzL1WQNGXcskexEIYCsQjHg03DrMFgZ4nuiI=";
};
};
}
);
};
}

0 comments on commit 7575f71

Please sign in to comment.