Extract manual PWD extraction with method current_work_dir (#7812)

This commit is contained in:
Hofer-Julian 2023-01-21 14:44:17 +01:00 committed by GitHub
parent e6f6f17c6d
commit 2d98d0fcc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 24 deletions

View file

@ -33,14 +33,7 @@ impl Completer for DirectoryCompletion {
_: usize,
options: &CompletionOptions,
) -> Vec<Suggestion> {
let cwd = if let Some(d) = self.engine_state.get_env_var("PWD") {
match d.as_string() {
Ok(s) => s,
Err(_) => "".to_string(),
}
} else {
"".to_string()
};
let cwd = self.engine_state.current_work_dir();
let partial = String::from_utf8_lossy(&prefix).to_string();
// Filter only the folders

View file

@ -70,14 +70,7 @@ impl Completer for DotNuCompletion {
partial = base_dir_partial;
} else {
// Fetch the current folder
let current_folder = if let Some(d) = self.engine_state.get_env_var("PWD") {
match d.as_string() {
Ok(s) => s,
Err(_) => "".to_string(),
}
} else {
"".to_string()
};
let current_folder = self.engine_state.current_work_dir();
is_current_folder = true;
// Add the current folder and the lib dirs into the

View file

@ -30,14 +30,7 @@ impl Completer for FileCompletion {
_: usize,
options: &CompletionOptions,
) -> Vec<Suggestion> {
let cwd = if let Some(d) = self.engine_state.get_env_var("PWD") {
match d.as_string() {
Ok(s) => s,
Err(_) => "".to_string(),
}
} else {
"".to_string()
};
let cwd = self.engine_state.current_work_dir();
let prefix = String::from_utf8_lossy(&prefix).to_string();
let output: Vec<_> = file_path_completion(span, &prefix, &cwd, options)
.into_iter()

View file

@ -965,6 +965,12 @@ impl EngineState {
self.get_module_comments(module_id)
.map(|comment_spans| self.build_usage(comment_spans))
}
pub fn current_work_dir(&self) -> String {
self.get_env_var("PWD")
.map(|d| d.as_string().unwrap_or_default())
.unwrap_or_default()
}
}
/// A temporary extension to the global state. This handles bridging between the global state and the