Skip to content

Commit

Permalink
fix: relative path completion fixes (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
reubeno authored Jul 23, 2024
1 parent 1e95afc commit bf52bcf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion brush-core/src/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ impl Config {
fn get_file_completions(shell: &Shell, context: &Context, must_be_dir: bool) -> Vec<String> {
let glob = std::format!("{}*", context.token_to_complete);

let path_filter = |path: &Path| !must_be_dir || path.is_dir();
let path_filter = |path: &Path| !must_be_dir || shell.get_absolute_path(path).is_dir();

// TODO: Pass through quoting.
patterns::Pattern::from(glob)
Expand Down
2 changes: 1 addition & 1 deletion brush-core/src/shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ impl Shell {
/// # Arguments
///
/// * `path` - The path to get the absolute form of.
pub(crate) fn get_absolute_path(&self, path: &Path) -> PathBuf {
pub fn get_absolute_path(&self, path: &Path) -> PathBuf {
if path.is_absolute() {
path.to_owned()
} else {
Expand Down
16 changes: 13 additions & 3 deletions brush-interactive/src/interactive_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ impl EditorHelper {
line: &str,
pos: usize,
) -> rustyline::Result<(usize, Vec<rustyline::completion::Pair>)> {
let working_dir = self.shell.working_dir.clone();

// Intentionally ignore any errors that arise.
let completion_future = self.shell.get_completions(line, pos);
tokio::pin!(completion_future);
Expand All @@ -261,9 +263,17 @@ impl EditorHelper {
if completions.options.treat_as_filenames {
for candidate in &mut completions.candidates {
// Check if it's a directory.
if !candidate.ends_with(std::path::MAIN_SEPARATOR) && Path::new(candidate).is_dir()
{
candidate.push(std::path::MAIN_SEPARATOR);
if !candidate.ends_with(std::path::MAIN_SEPARATOR) {
let candidate_path = Path::new(candidate);
let abs_candidate_path = if candidate_path.is_absolute() {
PathBuf::from(candidate_path)
} else {
working_dir.join(candidate_path)
};

if abs_candidate_path.is_dir() {
candidate.push(std::path::MAIN_SEPARATOR);
}
}
}
}
Expand Down

0 comments on commit bf52bcf

Please sign in to comment.