-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
:Clap files --path <p>
should include <p>
in it's output
#992
Comments
This patch should fix the files provider for this partcular case. However, I'm still thinking about whether such a design is reasonable ( diff --git a/autoload/clap/rooter.vim b/autoload/clap/rooter.vim
index 576eba2..517b241 100644
--- a/autoload/clap/rooter.vim
+++ b/autoload/clap/rooter.vim
@@ -41,8 +41,9 @@ endfunction
function! s:run_from_target_dir(target_dir, Run, run_args) abort
let save_cwd = getcwd()
+ let target_dir = type(a:target_dir) == v:t_list ? a:target_dir[0] : a:target_dir
try
- execute 'lcd' a:target_dir
+ execute 'lcd' target_dir
let l:result = call(a:Run, [a:run_args])
catch
call clap#helper#echo_error(
@@ -55,7 +56,7 @@ function! s:run_from_target_dir(target_dir, Run, run_args) abort
finally
" If the sink function changes cwd intentionally? Then we
" should not restore to the current cwd after executing the sink function.
- if getcwd(winnr()) ==# a:target_dir
+ if getcwd(winnr()) ==# target_dir
execute 'lcd' save_cwd
endif
endtry
diff --git a/crates/maple_core/src/stdio_server/provider/files.rs b/crates/maple_core/src/stdio_server/provider/files.rs
index 5362ece..747ddad 100644
--- a/crates/maple_core/src/stdio_server/provider/files.rs
+++ b/crates/maple_core/src/stdio_server/provider/files.rs
@@ -1,7 +1,9 @@
+use crate::paths::AbsPathBuf;
use crate::stdio_server::provider::{ClapProvider, Context, SearcherControl};
use anyhow::Result;
use clap::Parser;
use matcher::{Bonus, MatchScope};
+use serde_json::json;
use std::path::PathBuf;
use std::sync::atomic::AtomicBool;
use std::sync::Arc;
@@ -108,8 +110,31 @@ impl FilesProvider {
impl ClapProvider for FilesProvider {
async fn on_initialize(&mut self, ctx: &mut Context) -> Result<()> {
let query = ctx.vim.context_query_or_input().await?;
+ if self.args.base.no_cwd && !self.args.paths.is_empty() {
+ let new_working_dir = &self.args.paths[0];
+ if let Ok(path) = ctx.vim.expand(new_working_dir.to_string_lossy()).await {
+ let new_cwd = match AbsPathBuf::try_from(path.as_str()) {
+ Ok(abs_path) => {
+ ctx.cwd = abs_path.clone();
+ abs_path
+ }
+ Err(_) => {
+ ctx.cwd = ctx
+ .cwd
+ .join(path)
+ .try_into()
+ .expect("Failed to convert to absolute path");
+ ctx.cwd.clone()
+ }
+ };
+
+ ctx.vim.set_var("g:__clap_provider_cwd", json!([new_cwd]))?;
+ }
+ }
+
// All files will be collected if query is empty
self.process_query(query, ctx);
+
Ok(())
} |
|
Applied the patch and tested it and it seems to work. Thanks for this (I tried to fix it myself but well I'm c++ dev and I don't know rust sufficiently to find quickly a solution). |
@liuchengxu I tested Clap files --query and it's exactly what I wanted. Thanks. |
For example if you have a directory structure like this one:
Vim CWD is
<my dir>
.:Clap files
--> lists:Everything look and works fine (preview, edit, fuzzy match).
Now, I would want to list only files in
src
(because in my dev environment the "editable" headers are in src but are copied by the build outside, I don't want to check everytime I open the right one).As suggested in #987 comments:
:Clap files --no-cwd --path src
, list only one file in my basic example:mylib/a.cxx
. It's what I want.But now I cannot open or preview because it tries to open
mylib/a.cxx
relative path (= absolute:<my dir>/mylib/a.cxx
) instead ofsrc/mylib/a.cxx
(= absolute:<my dir>/src/mylib/a.cxx
).IMHO
:Clap files
should include the path value in its output for it to work.This worked with < 0.45.
Environment:
g:clap_disable_run_rooter = 1
but I tried with it set to 0)Clap debug
The text was updated successfully, but these errors were encountered: