SpaceVim / SpaceVim

A modular Vim/Neovim configuration
https://spacevim.org/
GNU General Public License v3.0
20.33k stars 1.41k forks source link

Support nested rooter pattern #3760

Closed thawk closed 4 years ago

thawk commented 4 years ago

Is your feature request related to a problem? Please describe. With g:spacevim_project_rooter_outermost=true, it only consider the most inner appearance of each pattern, and use the most outer one for difference patterns.

For example, using subversion, it common for parent project to have external links to sub project. There are multiple .svn/ in difference layer, like this:

parent_proj/
  .svn/
  files
  lib/
    sub1/
      .svn/
      sub1_files
    sub2/
      .svn/
      sub2_files

With outermost=true, we want the project root always be parent_proj/, not sub1 or sub2.

Describe the solution you'd like

It outermost=true, the most outer appearance of the same pattern should be taken into account.

If outermost=false, the most inner appearance of the same pattern should be taken into account instead.

wsdjeg commented 4 years ago

when edit file parent_proj/lib/sub1/sub1_files, the project manager should be able to find following path:

if the project_rooter_outermost option is true, parent_proj/ should be used.

wsdjeg commented 4 years ago

this is path tree

C:\Users\wsdjeg\Desktop\proj>tree /f
文件夹 PATH 列表
卷序列号为 0006-07CC
C:.
├─.git
└─lib
    └─sub1
        │  新建文本文档.txt
        │
        └─.git

here is the log

[ SpaceVim ] [21:04:49] [ Info ] Start to find root for: C:/Users/wsdjeg/Desktop/proj/lib/sub1/新建文本文档.txt
[ SpaceVim ] [21:04:49] [ Info ]         (.git/):C:/Users/wsdjeg/Desktop/proj/lib/sub1/
[   rooter ] [21:04:49] [ Info ] buffer name: C:\Users\wsdjeg\Desktop\proj\lib\sub1\新建文本文档.txt
[   rooter ] [21:04:49] [ Info ] change to root: C:/Users/wsdjeg/Desktop/proj/lib/sub1/

so the bug is, the rooter can only find (.git/):C:/Users/wsdjeg/Desktop/proj/lib/sub1/

wsdjeg commented 4 years ago

there are two ways to improve this feature:

  1. find all paths basded on partten, it will be slow, with this feature, we can find
  1. only find the nested or outmost path, based on project_rooter_outermost, it will be faster.
thawk commented 4 years ago

I think the second way is better.

In my similar code to find project root, I travel from cwd to root and check the existence of every pattern in the current level, returns the last one. With some caching, it seems to be fast enough.

wsdjeg commented 4 years ago

yeah, we can use for loop to check if the path is directory, and return the last one. But if the pattern is a fuzzy pattern, for example *.conf, we can not check it. the current implementation is using finddir() function which only return the first match.

thawk commented 4 years ago

Hey, I found something in the document. finddir() can return all matches, not only the first one. We don't need to use manual loop.

finddir({name} [, {path} [, {count}]])
...
When {count} is negative return all the matches in a |List|.
        This is quite similar to the ex-command |:find|.
wsdjeg commented 4 years ago

This issue should be fixed, please update spacevim.