From cd18f64211e816ce9d0427419f08ea6b33f523f9 Mon Sep 17 00:00:00 2001 From: taskylizard <75871323+taskylizard@users.noreply.github.com> Date: Wed, 15 Mar 2023 15:20:28 +0100 Subject: [PATCH] feat(pack/typescript): handle neotree rename imports Signed-off-by: taskylizard <75871323+taskylizard@users.noreply.github.com> --- lua/astrocommunity/pack/typescript/README.md | 1 + .../pack/typescript/typescript.lua | 36 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/lua/astrocommunity/pack/typescript/README.md b/lua/astrocommunity/pack/typescript/README.md index 1aeaab4bf..d88693c4d 100644 --- a/lua/astrocommunity/pack/typescript/README.md +++ b/lua/astrocommunity/pack/typescript/README.md @@ -8,3 +8,4 @@ This plugin pack does the following: - Adds [nvim-dap-vscode-js](https://github.com/mxsdev/nvim-dap-vscode-js) for debugging - Adds [typescript.nvim](https://github.com/jose-elias-alvarez/typescript.nvim) for language specific tooling - Adds [package-info.nvim](https://github.com/vuki656/package-info.nvim) for project package management +- Handles file imports on rename or move within neo-tree diff --git a/lua/astrocommunity/pack/typescript/typescript.lua b/lua/astrocommunity/pack/typescript/typescript.lua index 7a743ef31..8928712d3 100644 --- a/lua/astrocommunity/pack/typescript/typescript.lua +++ b/lua/astrocommunity/pack/typescript/typescript.lua @@ -1,4 +1,20 @@ local utils = require "astrocommunity.utils" +local events = require "neo-tree.events" +local function on_file_remove(args) + local ts_clients = vim.lsp.get_active_clients { name = "tsserver" } + for _, ts_client in ipairs(ts_clients) do + ts_client.request("workspace/executeCommand", { + command = "_typescript.applyRenameFile", + arguments = { + { + sourceUri = vim.uri_from_fname(args.source), + targetUri = vim.uri_from_fname(args.destination), + }, + }, + }) + end +end + return { { "nvim-treesitter/nvim-treesitter", @@ -51,7 +67,10 @@ return { ft = { "ts", "js", "tsx", "jsx" }, enabled = true, dependencies = { - { "mxsdev/nvim-dap-vscode-js", opts = { debugger_cmd = { "js-debug-adapter" }, adapters = { "pwa-node" } } }, + { + "mxsdev/nvim-dap-vscode-js", + opts = { debugger_cmd = { "js-debug-adapter" }, adapters = { "pwa-node" } }, + }, { "theHamsta/nvim-dap-virtual-text", config = true }, { "rcarriga/nvim-dap-ui", config = true }, }, @@ -108,4 +127,19 @@ return { }, opts = function() return { server = require("astronvim.utils.lsp").config "tsserver" } end, }, + { + "nvim-neo-tree/neo-tree.nvim", + opts = { + event_handlers = { + { + event = events.FILE_MOVED, + handler = on_file_remove, + }, + { + event = events.FILE_RENAMED, + handler = on_file_remove, + }, + }, + }, + }, }