1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-28 21:50:35 +08:00

feat(projectmanager): support project_non_root option

the RootchandgeCallback function should only be
called on project.
This commit is contained in:
wsdjeg 2022-10-26 18:54:44 +08:00
parent 0d26faa31d
commit f458b75dcb
2 changed files with 42 additions and 6 deletions

View File

@ -2012,6 +2012,26 @@ For example, to ignore the `node_packages/` directory:
project_rooter_outermost = false project_rooter_outermost = false
``` ```
There are three options for non-project files/directories:
- Don't change directory (default).
```
project_non_root = ''
```
- Change to file's directory (similar to 'autochdir').
```
project_non_root = 'current'
```
- Change to home directory.
```
project_non_root = 'home'
```
You can also disable project root detection completely (i.e. vim will set the You can also disable project root detection completely (i.e. vim will set the
root directory to the present working directory): root directory to the present working directory):
@ -2385,7 +2405,7 @@ The default color for iedit is `red`/`green` which is based on the current color
SpaceVim provides an asynchronous code runner plugin. In most language layers, SpaceVim provides an asynchronous code runner plugin. In most language layers,
the key binding `SPC l r` is defined for running the current buffer. the key binding `SPC l r` is defined for running the current buffer.
To close the code runner windows, you can use ``Ctrl-` `` key binding. To close the code runner windows, you can use `` Ctrl-` `` key binding.
If you need to add new commands, you can use the bootstrap function. For example: If you need to add new commands, you can use the bootstrap function. For example:
Use `F5` to build the project asynchronously. Use `F5` to build the project asynchronously.
@ -2400,7 +2420,6 @@ Key bindings within code runner buffer:
| `ctrl-c` | stop code runner | | `ctrl-c` | stop code runner |
| `i` | open promote to insert text | | `i` | open promote to insert text |
#### Custom runner #### Custom runner
If you want to set custom code runner for specific language. You need to use `SpaceVim#plugins#runner#reg_runner(ft, runner)` api in bootstrap function. If you want to set custom code runner for specific language. You need to use `SpaceVim#plugins#runner#reg_runner(ft, runner)` api in bootstrap function.

View File

@ -383,13 +383,30 @@ function M.current_root()
if rootdir == '' then if rootdir == '' then
rootdir = find_root_directory() rootdir = find_root_directory()
if rootdir == nil or rootdir == '' then if rootdir == nil or rootdir == '' then
rootdir = sp_file.unify_path(fn.getcwd()) -- for no project
if vim.g.spacevim_project_non_root == '' then
rootdir = sp_file.unify_path(fn.getcwd())
elseif vim.g.spacevim_project_non_root == 'home' and filereadable(bufname) then
rootdir = sp_file.unify_path(fn.expand('~'))
elseif vim.g.spacevim_project_non_root == 'current' then
local dir = sp_file.unify_path(bufname, ':p:h')
if isdirectory(dir) then
rootdir = dir
else
rootdir = sp_file.unify_path(fn.getcwd())
end
else
-- maybe log error
end
change_dir(rootdir)
else
-- for project
if change_dir(rootdir) then
M.RootchandgeCallback()
end
end end
fn.setbufvar('%', 'rootDir', rootdir) fn.setbufvar('%', 'rootDir', rootdir)
end end
if change_dir(rootdir) then
M.RootchandgeCallback()
end
return rootdir return rootdir
end end