summaryrefslogtreecommitdiff
path: root/cli/lsp/completions.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-08-06 16:30:34 +0100
committerGitHub <noreply@github.com>2024-08-06 16:30:34 +0100
commit9a83efa04b6e733ca0fdbf9e780c4b77f0d9f4be (patch)
tree262621aedc6b78c0acc43371007a8a28cad74897 /cli/lsp/completions.rs
parentb3f1f3ba04e51554ab59d6255bf34a79a9c42bd0 (diff)
feat(lsp): node specifier completions (#24904)
Diffstat (limited to 'cli/lsp/completions.rs')
-rw-r--r--cli/lsp/completions.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs
index a51edcb33..88900ceef 100644
--- a/cli/lsp/completions.rs
+++ b/cli/lsp/completions.rs
@@ -18,6 +18,7 @@ use crate::util::path::is_importable_ext;
use crate::util::path::relative_specifier;
use deno_graph::source::ResolutionMode;
use deno_graph::Range;
+use deno_runtime::deno_node::SUPPORTED_BUILTIN_NODE_MODULES;
use deno_runtime::fs_util::specifier_to_file_path;
use deno_ast::LineAndColumnIndex;
@@ -192,6 +193,8 @@ pub async fn get_import_completions(
get_npm_completions(specifier, &text, &range, npm_search_api).await
{
Some(lsp::CompletionResponse::List(completion_list))
+ } else if let Some(completion_list) = get_node_completions(&text, &range) {
+ Some(lsp::CompletionResponse::List(completion_list))
} else if let Some(completion_list) =
get_import_map_completions(specifier, &text, &range, maybe_import_map)
{
@@ -732,6 +735,40 @@ async fn get_npm_completions(
})
}
+/// Get completions for `node:` specifiers.
+fn get_node_completions(
+ specifier: &str,
+ range: &lsp::Range,
+) -> Option<CompletionList> {
+ if !specifier.starts_with("node:") {
+ return None;
+ }
+ let items = SUPPORTED_BUILTIN_NODE_MODULES
+ .iter()
+ .map(|name| {
+ let specifier = format!("node:{}", name);
+ let text_edit = Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit {
+ range: *range,
+ new_text: specifier.clone(),
+ }));
+ lsp::CompletionItem {
+ label: specifier,
+ kind: Some(lsp::CompletionItemKind::FILE),
+ detail: Some("(node)".to_string()),
+ text_edit,
+ commit_characters: Some(
+ IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect(),
+ ),
+ ..Default::default()
+ }
+ })
+ .collect();
+ Some(CompletionList {
+ is_incomplete: false,
+ items,
+ })
+}
+
/// Get workspace completions that include modules in the Deno cache which match
/// the current specifier string.
fn get_workspace_completions(