Repository: nushell/nushell
File: crates/nu-cli/src/completions/dotnu_completions.rs (Rust)

Code before:
            .or(working_set.get_env_var("NU_LIB_DIRS"))
            .map(|lib_dirs| {
                lib_dirs
                    .as_list()
                    .into_iter()
                    .flat_map(|it| it.iter().filter_map(|x| x.to_path().ok()))
                    .map(expand_tilde)
                    .collect()
            })
            .unwrap_or_default();

        // Check if the base_dir is a folder
        // rsplit_once removes the separator
        let cwd = working_set.permanent_state.cwd(None);
        if base_dir != "." {
            let expanded_base_dir = expand_tilde(&base_dir);
            let is_base_dir_relative = expanded_base_dir.is_relative();
            // Search in base_dir as well as lib_dirs.
            // After expanded, base_dir can be a relative path or absolute path.
            // If relative, we join "current working dir" with it to get subdirectory and add to search_dirs.
            // If absolute, we add it to search_dirs.
            if let Ok(mut cwd) = cwd {
                if is_base_dir_relative {
                    cwd.push(&base_dir);
                    search_dirs.push(cwd.into_std_path_buf());
                } else {
                    search_dirs.push(expanded_base_dir);
                }
            }
            if is_base_dir_relative {
                search_dirs.extend(lib_dirs.into_iter().map(|mut dir| {
                    dir.push(&base_dir);
                    dir
                }));
            }
        } else {
            if let Ok(cwd) = cwd {
                search_dirs.push(cwd.into_std_path_buf());
            }
            search_dirs.extend(lib_dirs);
        }

        // Fetch the files filtering the ones that ends with .nu
        // and transform them into suggestions
        let completions = file_path_completion(
            span,
            partial,
            &search_dirs
                .iter()
                .filter_map(|d| d.to_str())
                .collect::<Vec<_>>(),

Review comment (suggestion):
I don't think it's necessary anymore to have a separate `else` branch here just for `./`. The `else` branch doesn't account for `./two/slashes` and stuff anyway, as far as I can tell.

However, you may have to account for the fact that `.is_relative()` returns `true` for all paths starting with `.`. You'll need to treat them like absolute paths (don't search inside `NU_LIB_DIRS`).

Code after:
        };
        let base_dir = base.replace(is_separator, MAIN_SEPARATOR_STR);

        // Fetch the lib dirs
        // NOTE: 2 ways to setup `NU_LIB_DIRS`
        // 1. `const NU_LIB_DIRS = [paths]`, equal to `nu -I paths`
        // 2. `$env.NU_LIB_DIRS = [paths]`
        let const_lib_dirs = working_set
            .find_variable(b"$NU_LIB_DIRS")
            .and_then(|vid| working_set.get_variable(vid).const_val.as_ref());
        let env_lib_dirs = working_set.get_env_var("NU_LIB_DIRS");
        let lib_dirs: HashSet<PathBuf> = [const_lib_dirs, env_lib_dirs]
            .into_iter()
            .flatten()
            .flat_map(|lib_dirs| {
                lib_dirs
                    .as_list()
                    .into_iter()
                    .flat_map(|it| it.iter().filter_map(|x| x.to_path().ok()))
                    .map(expand_tilde)
            })
            .collect();

        // Check if the base_dir is a folder
        let cwd = working_set.permanent_state.cwd(None);
        if base_dir != "." {
            let expanded_base_dir = expand_tilde(&base_dir);
            let is_base_dir_relative = expanded_base_dir.is_relative();
            // Search in base_dir as well as lib_dirs.
            // After expanded, base_dir can be a relative path or absolute path.
            // If relative, we join "current working dir" with it to get subdirectory and add to search_dirs.
            // If absolute, we add it to search_dirs.
            if let Ok(mut cwd) = cwd {
                if is_base_dir_relative {
                    cwd.push(&base_dir);
                    search_dirs.push(cwd.into_std_path_buf());
                } else {
                    search_dirs.push(expanded_base_dir);
                }
            }
            if !not_lib_dirs {
                search_dirs.extend(lib_dirs.into_iter().map(|mut dir| {
                    dir.push(&base_dir);
                    dir
                }));
            }
        } else {
            if let Ok(cwd) = cwd {
                search_dirs.push(cwd.into_std_path_buf());
            }
            if !not_lib_dirs {