antosha417 / nvim-lsp-file-operations Goto Github PK
View Code? Open in Web Editor NEWNeovim plugin that adds support for file operations using built-in LSP
License: Apache License 2.0
Neovim plugin that adds support for file operations using built-in LSP
License: Apache License 2.0
I'm not sure if I missed anything, but for me the default setup is not enough, because nvim will not include the corresponding capabilities in the LSP initialize
request.
So for nvim-lspconfig
I had to add something like this to my config:
local lspconfig = require'lspconfig'
local util = lspconfig.util
-- Set global defaults for all servers
util.default_config = vim.tbl_extend(
'force',
util.default_config,
{
capabilities = vim.tbl_deep_extend(
"force",
vim.lsp.protocol.make_client_capabilities(),
-- support added by lsp-file-operations
{
workspace = {
fileOperations = {
willRename = true,
didRename = true,
willCreate = true,
didCreate = true,
willDelete = true,
didDelete = true,
}
}
}
)
}
)
Shouldn't this be mentioned in the README?
Tried same min config on Ubuntu Wsl on same project and plugin works perfectly but on Windows it doesn't make any changes while renaming/moving files etc. Server is attached correctly, renaming works fine on Windows with jose-elias-alvarez/typescript.nvim plugin.
Expected behaviour: imports update.
Current behaviour: no changes.
This is my one file config:
-- Plugin manager loading
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Plugins setup
require("lazy").setup({
-- Min lsp config with tsserver
{
"neovim/nvim-lspconfig",
config = function()
require("lspconfig").tsserver.setup({})
end,
},
-- nvim-lsp-file-operations min config
{
"antosha417/nvim-lsp-file-operations",
dependencies = {
"nvim-lua/plenary.nvim",
{
"nvim-tree/nvim-tree.lua",
version = "*",
config = function()
require("nvim-tree").setup({})
end,
},
},
config = function()
require("lsp-file-operations").setup({
debug = true,
})
end,
},
}, {})
Those are logs while renaming file:
[DEBUG 13 / 05 / 2023 22: 39: 56] ...im - lsp - file - operations / lua / lsp - file - operations / utils.lua: 50: Matching name C: \Programming\React\project\src\Components\NewName.js to pattern[\/].*\.\(ts\|js\|jsx\|tsx\|mjs\|mts\|cjs\|cts\)$
[DEBUG 13 / 05 / 2023 22: 39: 56] ...im - lsp - file - operations / lua / lsp - file - operations / utils.lua: 66: Path did match the filter C: \Programming\React\project\src\Components\NewName.js {
pattern = {
glob = "**/*.{ts,js,jsx,tsx,mjs,mts,cjs,cts}",
matches = "file"
},
scheme = "file"
}
[DEBUG 13 / 05 / 2023 22: 39: 56] ...-file - operations / lua / lsp - file - operations / will - rename.lua: 7: going to get workspace edit
[DEBUG 13 / 05 / 2023 22: 39: 56] ...-file - operations / lua / lsp - file - operations / will - rename.lua: 16: Sending workspace / willRenameFiles request {
files = { {
newUri = "file://C:\\Programming\\React\\project\\src\\Components\\Message.js",
oldUri = "file://C:\\Programming\\React\\project\\src\\Components\\NewName.js"
}
}
}
[DEBUG 13 / 05 / 2023 22: 39: 56] ...-file - operations / lua / lsp - file - operations / will - rename.lua: 19: Got workspace / willRenameFiles response {
result = {
changes = vim.empty_dict()
}
}
[DEBUG 13 / 05 / 2023 22: 39: 56] ...-file - operations / lua / lsp - file - operations / will - rename.lua: 32: going to apply workspace edit {
changes = vim.empty_dict()
}
Logs while moving to subfolder:
[DEBUG 13/05/2023 22:40:29] ...im-lsp-file-operations/lua/lsp-file-operations/utils.lua:50: Matching name C:\Programming\React\project\src\Components\subfolder\Message.js to pattern [\/].*\.\(ts\|js\|jsx\|tsx\|mjs\|mts\|cjs\|cts\)$
[DEBUG 13/05/2023 22:40:29] ...im-lsp-file-operations/lua/lsp-file-operations/utils.lua:66: Path did match the filter C:\Programming\React\project\src\Components\subfolder\Message.js {
pattern = {
glob = "**/*.{ts,js,jsx,tsx,mjs,mts,cjs,cts}",
matches = "file"
},
scheme = "file"
}
[DEBUG 13/05/2023 22:40:29] ...-file-operations/lua/lsp-file-operations/will-rename.lua:7: going to get workspace edit
[DEBUG 13/05/2023 22:40:29] ...-file-operations/lua/lsp-file-operations/will-rename.lua:16: Sending workspace/willRenameFiles request {
files = { {
newUri = "file://C:\\Programming\\React\\project\\src\\Components\\Message.js",
oldUri = "file://C:\\Programming\\React\\project\\src\\Components\\subfolder\\Message.js"
} }
}
[DEBUG 13/05/2023 22:40:29] ...-file-operations/lua/lsp-file-operations/will-rename.lua:19: Got workspace/willRenameFiles response {
result = {
changes = vim.empty_dict()
}
}
[DEBUG 13/05/2023 22:40:29] ...-file-operations/lua/lsp-file-operations/will-rename.lua:32: going to apply workspace edit {
changes = vim.empty_dict()
}
Maybe Windows paths cause problems.
Hi, I am using LunarVim, I have installed typescript-language-server. Also typescript and tsx from treesitter. I installed and setup lsp-file-operations. When I rename the filename (.ts or .tsx) through nvim-tree only the filename is changed. No imports are updated. Do you have any ideas about what is wrong?
Hey,
So, the plugin currently uses vim.lsp.get_active_clients()
, which was deprecated, in favor of vim.lsp.get_clients()
. Should be a simple change, I could make a PR
Hey!
When renaming a dart file, I get the error below:
Handler for event WillRenameNode errored. nvim-lsp-file-operations/lua/lsp-file-operations/utils.lua:27: attempt to call method 'new' (a nil value)
My dart lsp is setup and it does support willRenameFiles request.
Thank you for your work on this plugin, it has been working very well for me with nvim-tree so far!
I'm not sure how difficult this would be to support, however I think it would be a killer feature to support asynchronous LSP file operations. Currently, when renaming a file (especially in a larger codebase) it may take several seconds to complete the LSP file operation.
Since this is happening synchronously, it blocks the UI for several seconds until the action is completed.
Opening up this ticket here to at least start a conversation of the feasibility of supporting async LSP file operations in order to unblock the UI until the file operations are completed. Ideally once complete, it would have nvim-tree/neo-tree refresh with updated files.
Thanks for this fantastic plugin! I noticed that, copying the setup (using Lazy as a package manager) in the README, the plugin never loaded. I've "solved" the issue by adding lazy = false
but ideally it would load on the correct event. Could you suggest the appropriate event to ensure the plugin is loaded only when necessary for renaming/moving (cutting and pasting) the file in nvim-tree? Thanks
When using with https://github.com/pmizio/typescript-tools.nvim, which does support workspace/willRenameFiles
, I am getting the following error:
Error in event handler for event file_renamed[nvim_lsp_file_operations_rename]: ...-file-operations/lua/lsp-file-operations/will-rename.lua:20: attempt to index local 'resp' (a nil value)
I am using neo-tree if that helps.
first of all, appreciate your efforts. you know, some people don't like Nviem-tree and want to go straight to telescope file-browser.
I'm using nvim 0.9.4 on macOS 14.1.1 and I've noticed enabling this plugin causes nvim to exit with an error status:
$ nvim
$ echo $?
134
This happens consistently when the plugin is enabled, even just loading vim and immediately quitting is sufficient. There is no error message or log that I can see, but it causes issues with programs using EDITOR
and then expecting a zero status from saving and quitting.
I enabled the debug log for nvim-lsp-file-operations
but all it shows is:
[DEBUG Sat Dec 2 22:30:53 2023] /Users/me/.local/share/LazyVim/lazy/nvim-lsp-file-operations/lua/lsp-file-operations.lua:27: Setting up neo-tree integration
[DEBUG Sat Dec 2 22:30:53 2023] /Users/me/.local/share/LazyVim/lazy/nvim-lsp-file-operations/lua/lsp-file-operations.lua:56: Neo-tree integration setup complete
[DEBUG Sat Dec 2 22:32:17 2023] /Users/me/.local/share/LazyVim/lazy/nvim-lsp-file-operations/lua/lsp-file-operations.lua:27: Setting up neo-tree integration
[DEBUG Sat Dec 2 22:32:17 2023] /Users/me/.local/share/LazyVim/lazy/nvim-lsp-file-operations/lua/lsp-file-operations.lua:56: Neo-tree integration setup complete
Neovim does dot save the files after applying workspace edit. Because of that we need to manually save files to stop seeing errors after refactoring.
Wolud be great to have an option to automatically save edited files. Or to put them in quckfix list. Or something like that.
i'm not sure but I occurring this problem after sync the lazy.nvim, because previous day I can do the rename and moving file stuff, hopefully you can help me resolve this issue. your plugin really help me.
[email protected]
lazy as package manager
what I do is just copy (x) and paste (p) file into nested folder
here's the debug log:
[DEBUG Tue 21 Mar 2023 10:02:23 AM WIB] ...im-lsp-file-operations/lua/lsp-file-operations/utils.lua:66: Path did match the filter /home/nandafirmans/Development/dataon/fe-micro-standard/src/lib/components/other/date-time-picker/DateTimePickerMobileCarousel.js {
pattern = {
glob = "**/*.{ts,js,jsx,tsx,mjs,mts,cjs,cts}",
matches = "file"
},
scheme = "file"
}
[DEBUG Tue 21 Mar 2023 10:02:23 AM WIB] ...-file-operations/lua/lsp-file-operations/will-rename.lua:7: going to get workspace edit
[DEBUG Tue 21 Mar 2023 10:02:23 AM WIB] ...-file-operations/lua/lsp-file-operations/will-rename.lua:16: Sending workspace/willRenameFiles request {
files = { {
newUri = "file:///home/nandafirmans/Development/dataon/fe-micro-standard/src/lib/components/other/date-time-picker/context/DateTimePickerMobileCarousel.js",
oldUri = "file:///home/nandafirmans/Development/dataon/fe-micro-standard/src/lib/components/other/date-time-picker/DateTimePickerMobileCarousel.js"
} }
}
[DEBUG Tue 21 Mar 2023 10:02:48 AM WIB] ...-file-operations/lua/lsp-file-operations/will-rename.lua:19: Got workspace/willRenameFiles response nil```
After setting this up and trying to rename a TypeScript file, nothing happens and the debug also doesn't do anything when renaming. The plugin seems to be properly setup because there is an initial debug saying "Setting up nvim-tree integration"
Has tsserver support yet to be added?
I personally don't use neotree/nvim-tree but rather Oil.nvim
I would love to see support for that plugin because that's the main plugin I use for file operations like renaming/moving/deleting
It works great when you rename a file, but renaming a folder in the path or moving a file to a different location won't.
my config:
{
"antosha417/nvim-lsp-file-operations",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-neo-tree/neo-tree.nvim",
},
config = function()
require("lsp-file-operations").setup({ debug = false })
end,
},
If I change the file name directly on the file tree, it won't work.
If I open this file and then modify it it works fine.
Hi! I am working with a neovim plugin for a terminal file manager. I added support for renaming and deleting files using your implementation (love it).
I was wondering if you could skim over my implementation here mikavilpas/yazi.nvim#190
lsp-file-operations.did-rename
etc.)? Or should this be done some other way? I am not sure if you consider them a part of your stable, public API.Also, I asked for your plugin to be packaged into luarocks here nvim-neorocks/nurr#14 so that I can depend on it from my continuous integration test suite.
I'm trying to make this work and it is not, I enabled debug and all it shows are the following:
[DEBUG Tue Nov 21 23:52:50 2023] /Users/slu/.local/share/nvim/lazy/nvim-lsp-file-operations/lua/lsp-file-operations.lua:27: Setting up neo-tree integration
[DEBUG Tue Nov 21 23:52:50 2023] /Users/slu/.local/share/nvim/lazy/nvim-lsp-file-operations/lua/lsp-file-operations.lua:56: Neo-tree integration setup complete
We should at least have an output of some kind when neotree sends some event.
require("lsp-file-operations").setup()
Error detected while processing /home/alex/.dotfiles/config/nvim/init.lua:
E5113: Error while calling lua chunk: vim/shared.lua:0: after the second argument: expected table, got nil
stack traceback:
[C]: in function 'error'
vim/shared.lua: in function 'validate'
vim/shared.lua: in function 'tbl_deep_extend'
...art/nvim-lsp-file-operations/lua/lsp-file-operations.lua:11: in function 'setup'
Might want to null check the argument, something like
opts = vim.tbl_deep_extend("force", default_config, opts or {})
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.