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 {
|
} else {
|
||||||
let mut path: PathBuf = Path::new(&tok).to_path_buf();
|
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);
|
path = current_dir_path.join(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Ok(npath) = path.canonicalize() {
|
|
||||||
path = npath;
|
|
||||||
}
|
|
||||||
|
|
||||||
if path.exists() && path.is_dir() {
|
if path.exists() && path.is_dir() {
|
||||||
if let Ok(entries) = path.read_dir() {
|
if let Ok(entries) = path.read_dir() {
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
if let Ok(e) = entry {
|
if let Ok(e) = entry {
|
||||||
|
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("inexplicable stringification error")
|
||||||
|
.to_owned();
|
||||||
|
if d {
|
||||||
|
str_path = str_path + "/";
|
||||||
|
}
|
||||||
sugg.push(Suggestion {
|
sugg.push(Suggestion {
|
||||||
value: e.path()
|
value: str_path,
|
||||||
.as_os_str()
|
|
||||||
.to_str()
|
|
||||||
.expect("bad dir somehow?")
|
|
||||||
.to_owned() + "/",
|
|
||||||
description: None,
|
description: None,
|
||||||
extra: None,
|
extra: None,
|
||||||
span: Span {
|
span: Span {
|
||||||
|
|
@ -178,8 +185,14 @@ impl Completer for CustomCompleter {
|
||||||
.to_mut()
|
.to_mut()
|
||||||
.as_str()
|
.as_str()
|
||||||
) {
|
) {
|
||||||
|
let mut path = e.path();
|
||||||
|
if rel {
|
||||||
|
path = path.strip_prefix(current_dir_path.clone())
|
||||||
|
.unwrap()
|
||||||
|
.to_path_buf();
|
||||||
|
}
|
||||||
sugg.push(Suggestion {
|
sugg.push(Suggestion {
|
||||||
value: e.path()
|
value: path
|
||||||
.as_os_str()
|
.as_os_str()
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect("bad dir somehow?")
|
.expect("bad dir somehow?")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue