big important improvements to path autocomplete
This commit is contained in:
parent
eba113b034
commit
23b295c10d
1 changed files with 24 additions and 11 deletions
|
|
@ -135,24 +135,31 @@ impl Completer for CustomCompleter {
|
|||
}
|
||||
} else {
|
||||
let mut path: PathBuf = Path::new(&tok).to_path_buf();
|
||||
if path.is_relative() {
|
||||
let rel = path.is_relative();
|
||||
if rel {
|
||||
path = current_dir_path.join(path);
|
||||
}
|
||||
|
||||
if let Ok(npath) = path.canonicalize() {
|
||||
path = npath;
|
||||
}
|
||||
|
||||
if path.exists() && path.is_dir() {
|
||||
if let Ok(entries) = path.read_dir() {
|
||||
for entry in entries {
|
||||
if let Ok(e) = entry {
|
||||
sugg.push(Suggestion {
|
||||
value: e.path()
|
||||
.as_os_str()
|
||||
let mut path = e.path();
|
||||
if rel {
|
||||
path = path.strip_prefix(current_dir_path.clone())
|
||||
.unwrap()
|
||||
.to_path_buf();
|
||||
}
|
||||
let d = path.is_dir();
|
||||
let mut str_path = path.as_os_str()
|
||||
.to_str()
|
||||
.expect("bad dir somehow?")
|
||||
.to_owned() + "/",
|
||||
.expect("inexplicable stringification error")
|
||||
.to_owned();
|
||||
if d {
|
||||
str_path = str_path + "/";
|
||||
}
|
||||
sugg.push(Suggestion {
|
||||
value: str_path,
|
||||
description: None,
|
||||
extra: None,
|
||||
span: Span {
|
||||
|
|
@ -178,8 +185,14 @@ impl Completer for CustomCompleter {
|
|||
.to_mut()
|
||||
.as_str()
|
||||
) {
|
||||
let mut path = e.path();
|
||||
if rel {
|
||||
path = path.strip_prefix(current_dir_path.clone())
|
||||
.unwrap()
|
||||
.to_path_buf();
|
||||
}
|
||||
sugg.push(Suggestion {
|
||||
value: e.path()
|
||||
value: path
|
||||
.as_os_str()
|
||||
.to_str()
|
||||
.expect("bad dir somehow?")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue