diff options
author | sigmaSd <bedisnbiba@gmail.com> | 2023-09-05 16:36:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-05 16:36:35 +0100 |
commit | be1fc754a14683bf640b7bf0ecf6e286d02ee118 (patch) | |
tree | e7861eba1de4c0d2bb3afe1cc8c407f8e3b4f668 /cli/lsp/completions.rs | |
parent | 4a561f12dbae5a49203eb2c08fed71d9d0dfeb99 (diff) |
feat(lsp): provide the deno.cache command server-side (#20111)
Co-authored-by: Nayeem Rahman <nayeemrmn99@gmail.com>
Diffstat (limited to 'cli/lsp/completions.rs')
-rw-r--r-- | cli/lsp/completions.rs | 63 |
1 files changed, 44 insertions, 19 deletions
diff --git a/cli/lsp/completions.rs b/cli/lsp/completions.rs index ce83fdeed..d459daee0 100644 --- a/cli/lsp/completions.rs +++ b/cli/lsp/completions.rs @@ -169,7 +169,8 @@ pub async fn get_import_completions( } else if text.starts_with("npm:") { Some(lsp::CompletionResponse::List(lsp::CompletionList { is_incomplete: false, - items: get_npm_completions(&text, &range, npm_search_api).await?, + items: get_npm_completions(specifier, &text, &range, npm_search_api) + .await?, })) } else if !text.is_empty() { // completion of modules from a module registry or cache @@ -464,6 +465,7 @@ fn get_relative_specifiers( /// Get completions for `npm:` specifiers. async fn get_npm_completions( + referrer: &ModuleSpecifier, specifier: &str, range: &lsp::Range, npm_search_api: &impl NpmSearchApi, @@ -513,7 +515,7 @@ async fn get_npm_completions( let command = Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!([&specifier])]), + arguments: Some(vec![json!([&specifier]), json!(referrer)]), }); let text_edit = Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit { range: *range, @@ -546,7 +548,7 @@ async fn get_npm_completions( let command = Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!([&specifier])]), + arguments: Some(vec![json!([&specifier]), json!(referrer)]), }); let text_edit = Some(lsp::CompletionTextEdit::Edit(lsp::TextEdit { range: *range, @@ -854,9 +856,11 @@ mod tests { character: 32, }, }; - let actual = get_npm_completions("npm:puppe", &range, &npm_search_api) - .await - .unwrap(); + let referrer = ModuleSpecifier::parse("file:///referrer.ts").unwrap(); + let actual = + get_npm_completions(&referrer, "npm:puppe", &range, &npm_search_api) + .await + .unwrap(); assert_eq!( actual, vec![ @@ -872,7 +876,7 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer"])]) + arguments: Some(vec![json!(["npm:puppeteer"]), json!(&referrer)]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -891,7 +895,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer-core"])]) + arguments: Some(vec![ + json!(["npm:puppeteer-core"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -910,9 +917,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!([ - "npm:puppeteer-extra-plugin-stealth" - ])]) + arguments: Some(vec![ + json!(["npm:puppeteer-extra-plugin-stealth"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -931,7 +939,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer-extra-plugin"])]) + arguments: Some(vec![ + json!(["npm:puppeteer-extra-plugin"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -967,9 +978,11 @@ mod tests { character: 37, }, }; - let actual = get_npm_completions("npm:puppeteer@", &range, &npm_search_api) - .await - .unwrap(); + let referrer = ModuleSpecifier::parse("file:///referrer.ts").unwrap(); + let actual = + get_npm_completions(&referrer, "npm:puppeteer@", &range, &npm_search_api) + .await + .unwrap(); assert_eq!( actual, vec![ @@ -985,7 +998,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer@21.0.2"])]) + arguments: Some(vec![ + json!(["npm:puppeteer@21.0.2"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -1004,7 +1020,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer@21.0.1"])]) + arguments: Some(vec![ + json!(["npm:puppeteer@21.0.1"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -1023,7 +1042,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer@21.0.0"])]) + arguments: Some(vec![ + json!(["npm:puppeteer@21.0.0"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() @@ -1042,7 +1064,10 @@ mod tests { command: Some(lsp::Command { title: "".to_string(), command: "deno.cache".to_string(), - arguments: Some(vec![json!(["npm:puppeteer@20.9.0"])]) + arguments: Some(vec![ + json!(["npm:puppeteer@20.9.0"]), + json!(&referrer) + ]) }), commit_characters: Some( IMPORT_COMMIT_CHARS.iter().map(|&c| c.into()).collect() |