1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-07 06:46:59 -05:00

fix(lsp): use correct commit chars for completions (#15366)

Fixes: #15252
This commit is contained in:
Kitson Kelly 2022-08-02 08:54:17 +10:00 committed by crowlkats
parent 95fc447012
commit 6305c9ce1f
No known key found for this signature in database
GPG key ID: A82C9D461FC483E8
4 changed files with 68 additions and 12 deletions

View file

@ -31,7 +31,7 @@ static FILE_PROTO_RE: Lazy<Regex> =
const CURRENT_PATH: &str = "."; const CURRENT_PATH: &str = ".";
const PARENT_PATH: &str = ".."; const PARENT_PATH: &str = "..";
const LOCAL_PATHS: &[&str] = &[CURRENT_PATH, PARENT_PATH]; const LOCAL_PATHS: &[&str] = &[CURRENT_PATH, PARENT_PATH];
const IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'", "/"]; pub(crate) const IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'"];
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")] #[serde(rename_all = "camelCase")]

View file

@ -1,5 +1,6 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use super::completions::IMPORT_COMMIT_CHARS;
use super::logging::lsp_log; use super::logging::lsp_log;
use super::path_to_regex::parse; use super::path_to_regex::parse;
use super::path_to_regex::string_to_regex; use super::path_to_regex::string_to_regex;
@ -64,6 +65,8 @@ const COMPONENT: &percent_encoding::AsciiSet = &percent_encoding::CONTROLS
.add(b'+') .add(b'+')
.add(b','); .add(b',');
const REGISTRY_IMPORT_COMMIT_CHARS: &[&str] = &["\"", "'", "/"];
static REPLACEMENT_VARIABLE_RE: Lazy<Regex> = static REPLACEMENT_VARIABLE_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r"\$\{\{?(\w+)\}?\}").unwrap()); Lazy::new(|| Regex::new(r"\$\{\{?(\w+)\}?\}").unwrap());
@ -493,6 +496,12 @@ impl ModuleRegistry {
filter_text, filter_text,
sort_text: Some("1".to_string()), sort_text: Some("1".to_string()),
text_edit, text_edit,
commit_characters: Some(
REGISTRY_IMPORT_COMMIT_CHARS
.iter()
.map(|&c| c.into())
.collect(),
),
..Default::default() ..Default::default()
}, },
); );
@ -784,6 +793,21 @@ impl ModuleRegistry {
&key, &key,
&item, &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( completions.insert(
item, item,
lsp::CompletionItem { lsp::CompletionItem {
@ -796,6 +820,7 @@ impl ModuleRegistry {
command, command,
preselect, preselect,
data, data,
commit_characters,
..Default::default() ..Default::default()
}, },
); );
@ -836,6 +861,12 @@ impl ModuleRegistry {
sort_text: Some("1".to_string()), sort_text: Some("1".to_string()),
text_edit, text_edit,
preselect: Some(true), preselect: Some(true),
commit_characters: Some(
REGISTRY_IMPORT_COMMIT_CHARS
.iter()
.map(|&c| c.into())
.collect(),
),
..Default::default() ..Default::default()
}, },
); );
@ -889,6 +920,21 @@ impl ModuleRegistry {
let preselect = let preselect =
get_preselect(item.clone(), preselect.clone()); get_preselect(item.clone(), preselect.clone());
let data = get_data(registry, &specifier, k, &path); 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( completions.insert(
item.clone(), item.clone(),
lsp::CompletionItem { lsp::CompletionItem {
@ -901,6 +947,7 @@ impl ModuleRegistry {
command, command,
preselect, preselect,
data, data,
commit_characters,
..Default::default() ..Default::default()
}, },
); );
@ -969,6 +1016,12 @@ impl ModuleRegistry {
detail: Some("(registry)".to_string()), detail: Some("(registry)".to_string()),
sort_text: Some("2".to_string()), sort_text: Some("2".to_string()),
text_edit, text_edit,
commit_characters: Some(
REGISTRY_IMPORT_COMMIT_CHARS
.iter()
.map(|&c| c.into())
.collect(),
),
..Default::default() ..Default::default()
}) })
} else { } else {

View file

@ -775,7 +775,7 @@ fn lsp_import_map_import_completions() {
"detail": "(local)", "detail": "(local)",
"sortText": "1", "sortText": "1",
"insertText": ".", "insertText": ".",
"commitCharacters": ["\"", "'", "/"], "commitCharacters": ["\"", "'"],
}, },
{ {
"label": "..", "label": "..",
@ -783,7 +783,7 @@ fn lsp_import_map_import_completions() {
"detail": "(local)", "detail": "(local)",
"sortText": "1", "sortText": "1",
"insertText": "..", "insertText": "..",
"commitCharacters": ["\"", "'", "/"], "commitCharacters": ["\"", "'"],
}, },
{ {
"label": "std", "label": "std",
@ -791,7 +791,7 @@ fn lsp_import_map_import_completions() {
"detail": "(import map)", "detail": "(import map)",
"sortText": "std", "sortText": "std",
"insertText": "std", "insertText": "std",
"commitCharacters": ["\"", "'", "/"], "commitCharacters": ["\"", "'"],
}, },
{ {
"label": "fs", "label": "fs",
@ -799,7 +799,7 @@ fn lsp_import_map_import_completions() {
"detail": "(import map)", "detail": "(import map)",
"sortText": "fs", "sortText": "fs",
"insertText": "fs", "insertText": "fs",
"commitCharacters": ["\"", "'", "/"], "commitCharacters": ["\"", "'"],
}, },
{ {
"label": "/~", "label": "/~",
@ -807,7 +807,7 @@ fn lsp_import_map_import_completions() {
"detail": "(import map)", "detail": "(import map)",
"sortText": "/~", "sortText": "/~",
"insertText": "/~", "insertText": "/~",
"commitCharacters": ["\"", "'", "/"], "commitCharacters": ["\"", "'"],
} }
] ]
})) }))
@ -889,7 +889,7 @@ fn lsp_import_map_import_completions() {
}, },
"newText": "/~/b.ts" "newText": "/~/b.ts"
}, },
"commitCharacters": ["\"", "'", "/"], "commitCharacters": ["\"", "'"],
} }
] ]
})) }))

View file

@ -9,8 +9,7 @@
"insertText": ".", "insertText": ".",
"commitCharacters": [ "commitCharacters": [
"\"", "\"",
"'", "'"
"/"
] ]
}, },
{ {
@ -21,8 +20,7 @@
"insertText": "..", "insertText": "..",
"commitCharacters": [ "commitCharacters": [
"\"", "\"",
"'", "'"
"/"
] ]
}, },
{ {
@ -42,7 +40,12 @@
} }
}, },
"newText": "http://localhost:4545" "newText": "http://localhost:4545"
} },
"commitCharacters": [
"\"",
"'",
"/"
]
} }
] ]
} }