From 2fb20eca8b44ac81f6ac09902b919558196917ba Mon Sep 17 00:00:00 2001 From: Felix Date: Mon, 2 Oct 2023 09:01:10 +0200 Subject: [PATCH 1/2] feat: add "as" completion for imports --- uvls/src/ide/completion.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/uvls/src/ide/completion.rs b/uvls/src/ide/completion.rs index d5d0bc30..1403a212 100644 --- a/uvls/src/ide/completion.rs +++ b/uvls/src/ide/completion.rs @@ -1012,19 +1012,26 @@ fn compute_completions_impl( is_incomplete = true } CompletionEnv::Import => { - for (path, name, node) in snapshot.fs().sub_files(origin, &ctx.prefix) { - let len = path.as_str().chars().filter(|c| c == &'.').count(); - top.push(CompletionOpt::new( - match node { - FSNode::Dir => CompletionKind::Folder, - _ => CompletionKind::File, - }, - name, - path.clone(), - len, - TextOP::Put(path), - &ctx, - )) + match &ctx.offset { + CompletionOffset::SameLine => { + add_keywords(&ctx.postfix, &mut top, 2.0, ["as ".into()]) + } + _ => { + for (path, name, node) in snapshot.fs().sub_files(origin, &ctx.prefix) { + let len = path.as_str().chars().filter(|c| c == &'.').count(); + top.push(CompletionOpt::new( + match node { + FSNode::Dir => CompletionKind::Folder, + _ => CompletionKind::File, + }, + name, + path.clone(), + len, + TextOP::Put(path), + &ctx, + )) + } + } } is_incomplete = true } From 9ea36f0452ddd5c66e154d4235cdcfe7d5cbd6a9 Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 10 Oct 2023 14:01:18 +0200 Subject: [PATCH 2/2] fix: CompletionEnv for import from different folder --- uvls/src/ide/completion.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/uvls/src/ide/completion.rs b/uvls/src/ide/completion.rs index 1403a212..934be3cc 100644 --- a/uvls/src/ide/completion.rs +++ b/uvls/src/ide/completion.rs @@ -338,7 +338,9 @@ fn estimate_env(node: Node, source: &Rope, pos: &Position) -> Option Some(CompletionEnv::Import), - "ref" if node.kind() == "path" => Some(CompletionEnv::Import), + "ref" if node.kind() == "path" || node.kind() == "name" => { + Some(CompletionEnv::Import) + } _ => None, } }