From 09d14b1b57ffe28e5d43d3fb3ae237cc944596ae Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Tue, 2 Aug 2022 08:54:17 +1000 Subject: fix(lsp): use correct commit chars for completions (#15366) Fixes: #15252 --- cli/lsp/completions.rs | 2 +- cli/lsp/registries.rs | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 1 deletion(-) (limited to 'cli/lsp') diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index dfa2c612d..5eb42d3b0 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -31,7 +31,7 @@ static FILE_PROTO_RE: Lazy = const CURRENT_PATH: &str = "."; const PARENT_PATH: &str = ".."; const LOCAL_PATHS: &[&str] = &[CURRENT_PATH, PARENT_PATH]; -const IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'", "/"]; +pub(crate) const IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'"]; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] diff --git a/cli/lsp/registries.rs b/cli/lsp/registries.rs index b22e15a1f..c9ed5da63 100644 --- a/cli/lsp/registries.rs +++ b/cli/lsp/registries.rs @@ -1,5 +1,6 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +use super::completions::IMPORT_COMMIT_CHARS; use super::logging::lsp_log; use super::path_to_regex::parse; use super::path_to_regex::string_to_regex; @@ -64,6 +65,8 @@ const COMPONENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS .add(b'+') .add(b','); +const REGISTRY_IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'", "/"]; + static REPLACEMENT_VARIABLE_RE: Lazy = Lazy::new(|| Regex::new(r"\$\{\{?(\w+)\}?\}").unwrap()); @@ -493,6 +496,12 @@ impl ModuleRegistry { filter_text, sort_text: Some("1".to_string()), text_edit, + commit_characters: Some( + REGISTRY_IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ), ..Default::default() }, ); @@ -784,6 +793,21 @@ impl ModuleRegistry { &key, &item, ); + let commit_characters = if is_incomplete { + Some( + REGISTRY_IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ) + } else { + Some( + IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ) + }; completions.insert( item, lsp::CompletionItem { @@ -796,6 +820,7 @@ impl ModuleRegistry { command, preselect, data, + commit_characters, ..Default::default() }, ); @@ -836,6 +861,12 @@ impl ModuleRegistry { sort_text: Some("1".to_string()), text_edit, preselect: Some(true), + commit_characters: Some( + REGISTRY_IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ), ..Default::default() }, ); @@ -889,6 +920,21 @@ impl ModuleRegistry { let preselect = get_preselect(item.clone(), preselect.clone()); let data = get_data(registry, &specifier, k, &path); + let commit_characters = if is_incomplete { + Some( + REGISTRY_IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ) + } else { + Some( + IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ) + }; completions.insert( item.clone(), lsp::CompletionItem { @@ -901,6 +947,7 @@ impl ModuleRegistry { command, preselect, data, + commit_characters, ..Default::default() }, ); @@ -969,6 +1016,12 @@ impl ModuleRegistry { detail: Some("(registry)".to_string()), sort_text: Some("2".to_string()), text_edit, + commit_characters: Some( + REGISTRY_IMPORT_COMMIT_CHARS + .iter() + .map(|&c| c.into()) + .collect(), + ), ..Default::default() }) } else { -- cgit v1.2.3