summaryrefslogtreecommitdiff
path: root/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r--tests/integration/lsp_tests.rs124
1 files changed, 124 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index dcef69608..a5b0ee247 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -8271,6 +8271,130 @@ fn lsp_npm_auto_import_and_quick_fix_byonm() {
}
#[test]
+fn lsp_npm_auto_import_with_deno_types() {
+ let context = TestContextBuilder::new()
+ .use_http_server()
+ .use_temp_cwd()
+ .add_npm_env_vars()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write(
+ "deno.json",
+ json!({
+ "compilerOptions": {
+ "jsx": "react-jsx",
+ "jsxImportSource": "react",
+ "jsxImportSourceTypes": "@types/react",
+ },
+ })
+ .to_string(),
+ );
+ temp_dir.write(
+ "package.json",
+ json!({
+ "dependencies": {
+ "react": "*",
+ "@types/react": "*",
+ "lz-string": "1.3",
+ "@types/lz-string": "1.3",
+ },
+ })
+ .to_string(),
+ );
+ context.run_npm("install");
+ temp_dir.write(
+ "other.ts",
+ r#"
+ // @deno-types="@types/lz-string"
+ import "lz-string";
+ "#,
+ );
+ let mut client = context.new_lsp_command().build();
+ client.initialize_default();
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.url().join("file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": r#"
+ compressToBase64();
+ createRef();
+ "#,
+ },
+ }));
+ let list = client.get_completion_list(
+ temp_dir.url().join("file.ts").unwrap(),
+ (1, 24),
+ json!({ "triggerKind": 1 }),
+ );
+ let item = list
+ .items
+ .iter()
+ .find(|item| item.label == "compressToBase64")
+ .unwrap();
+ let res = client.write_request("completionItem/resolve", item);
+ assert_eq!(
+ res,
+ json!({
+ "label": "compressToBase64",
+ "labelDetails": {
+ "description": "lz-string",
+ },
+ "kind": 2,
+ "detail": "(method) LZString.LZStringStatic.compressToBase64(uncompressed: string): string",
+ "documentation": {
+ "kind": "markdown",
+ "value": "Compresses input string producing an instance of a ASCII UTF-16 string,\nwhich represents the original string encoded in Base64.\nThe result can be safely transported outside the browser with a\nguarantee that none of the characters produced need to be URL-encoded.\n\n*@param* - uncompressed A string which should be compressed.",
+ },
+ "sortText": "￿16_0",
+ "additionalTextEdits": [
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 },
+ },
+ "newText": "// @deno-types=\"@types/lz-string\"\nimport { compressToBase64 } from \"lz-string\";\n",
+ },
+ ],
+ }),
+ );
+ let list = client.get_completion_list(
+ temp_dir.url().join("file.ts").unwrap(),
+ (2, 17),
+ json!({ "triggerKind": 1 }),
+ );
+ let item = list
+ .items
+ .iter()
+ .find(|item| item.label == "createRef")
+ .unwrap();
+ let res = client.write_request("completionItem/resolve", item);
+ assert_eq!(
+ res,
+ json!({
+ "label": "createRef",
+ "labelDetails": {
+ "description": "react",
+ },
+ "kind": 3,
+ "detail": "function React.createRef<T>(): React.RefObject<T>",
+ "documentation": { "kind": "markdown", "value": "" },
+ "sortText": "￿16_0",
+ "additionalTextEdits": [
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 },
+ },
+ "newText": "// @deno-types=\"@types/react\"\nimport { createRef } from \"react\";\n",
+ },
+ ],
+ }),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_completions_node_specifier() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();