project.nvim icon indicating copy to clipboard operation
project.nvim copied to clipboard

Default detection methods { "lsp", "pattern" } cause multiple CWDs when opening files in same project.

Open collinvandyck opened this issue 9 months ago • 0 comments

In a Rust project with an attached LSP I noticed that nvim-tree was flickering when using project.nvim and opening files in different crates within the same workspace. The project would would stay correctly on the workspace root, but I wasn't sure why it was flickering, and also collapsing the directory of the previously opened file in a different sub-crate.

I turned silent_chdir = false to debug what was happening and what I saw is that it was performing multiple chdirs, once for one of the patterns that matched and also for the LSP workspace root.

Changing the detection method to just { "lsp" } removed the flickering and in-project collapse of the tree in the previous buffer in the other workspace crate.

It was my understanding from the documentation that the ordering of the detection methods meant that it would prefer a match from the first detection method encountered. I had assumed that since I had an lsp attached, it would only change directory to that supplied by the LSP and would ignore the patterns configured, but what I saw is that it was using both the LSP and the patterns.

This is my config that produced the flickering:

require("project_nvim").setup {
	detection_methods = { "lsp", "pattern" },                                                                        
	patterns = {
		".git",
		"Cargo.toml",
		"_darcs",
		".hg",
		".bzr",
		".svn",
		"Makefile",
		"package.json",
	},
	silent_chdir = false,
}

and this config stops the flickering and multiple CWD changes:

require("project_nvim").setup {
	detection_methods = { "lsp" },                                                                        
	patterns = {
		".git",
		"Cargo.toml",
		"_darcs",
		".hg",
		".bzr",
		".svn",
		"Makefile",
		"package.json",
	},
	silent_chdir = false,
}

Is there a way to use both lsp and pattern but to disregard the pattern if the lsp supplies a project root?

collinvandyck avatar May 25 '24 20:05 collinvandyck