summaryrefslogtreecommitdiff
path: root/cli/lsp/completions.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-08-20 19:38:47 +0100
committerGitHub <noreply@github.com>2024-08-20 19:38:47 +0100
commitacba2cd48c3b8725c93513edc291a107bdc7eeaf (patch)
tree419bc06d81882506fa323558adac3ae7ff5327a0 /cli/lsp/completions.rs
parenta7c8bb1596411f91e20ddd5cd54c9dbd055d1059 (diff)
fix(lsp): include scoped import map keys in completions (#25047)
Diffstat (limited to 'cli/lsp/completions.rs')
-rw-r--r--cli/lsp/completions.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs
index 7e0705e99..ab2d8000c 100644
--- a/cli/lsp/completions.rs
+++ b/cli/lsp/completions.rs
@@ -249,7 +249,7 @@ pub async fn get_import_completions(
.collect();
let mut is_incomplete = false;
if let Some(import_map) = maybe_import_map {
- items.extend(get_base_import_map_completions(import_map));
+ items.extend(get_base_import_map_completions(import_map, specifier));
}
if let Some(origin_items) =
module_registries.get_origin_completions(&text, &range)
@@ -268,20 +268,20 @@ pub async fn get_import_completions(
/// map as completion items.
fn get_base_import_map_completions(
import_map: &ImportMap,
+ referrer: &ModuleSpecifier,
) -> Vec<lsp::CompletionItem> {
import_map
- .imports()
- .keys()
- .map(|key| {
+ .entries_for_referrer(referrer)
+ .map(|entry| {
// for some strange reason, keys that start with `/` get stored in the
// import map as `file:///`, and so when we pull the keys out, we need to
// change the behavior
- let mut label = if key.starts_with("file://") {
- FILE_PROTO_RE.replace(key, "").to_string()
+ let mut label = if entry.key.starts_with("file://") {
+ FILE_PROTO_RE.replace(entry.key, "").to_string()
} else {
- key.to_string()
+ entry.key.to_string()
};
- let kind = if key.ends_with('/') {
+ let kind = if entry.key.ends_with('/') {
label.pop();
Some(lsp::CompletionItemKind::FOLDER)
} else {