diff --git a/modules/nvim/plugins/lsp/config.lua b/modules/nvim/plugins/lsp/config.lua index ebd1624..d610745 100644 --- a/modules/nvim/plugins/lsp/config.lua +++ b/modules/nvim/plugins/lsp/config.lua @@ -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 { @@ -73,6 +74,8 @@ local jsFiletypes = { 'typescript.tsx', } +require('lspconfig.configs').vtsls = require('vtsls').lspconfig + lspconfig.vtsls.setup { filetypes = jsFiletypes, settings = { @@ -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 { diff --git a/modules/nvim/plugins/lsp/default.nix b/modules/nvim/plugins/lsp/default.nix index ab8815f..d09366e 100644 --- a/modules/nvim/plugins/lsp/default.nix +++ b/modules/nvim/plugins/lsp/default.nix @@ -5,6 +5,7 @@ fidget-nvim nvim-lspconfig lsp-format-nvim + pkgs.localVimPlugins.vtsls-nvim ]; extraPackages = with pkgs; [ efm-langserver diff --git a/overlays/default.nix b/overlays/default.nix index 21bf408..483177a 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -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; } diff --git a/overlays/nixpkgs-local-vim-plugins.nix b/overlays/nixpkgs-local-vim-plugins.nix new file mode 100644 index 0000000..0307f6d --- /dev/null +++ b/overlays/nixpkgs-local-vim-plugins.nix @@ -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="; + }; + }; + } + ); + }; +} +