summaryrefslogtreecommitdiff
path: root/tests/integration
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-10-01 22:55:02 +0100
committerGitHub <noreply@github.com>2024-10-01 22:55:02 +0100
commit3881b7173445ab7f68ec94d5dedbb1cb1c1978ec (patch)
tree2683c9955f19c9e1d19af6a41ce75cab5b3570fa /tests/integration
parentf9300004152ba4b3d091beb04d74f37b3b8ec281 (diff)
feat(lsp): quick fix for @deno-types="npm:@types/*" (#25954)
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/lsp_tests.rs129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 539e3cc7e..fc5437594 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -5907,6 +5907,135 @@ fn lsp_code_actions_deno_cache_all() {
}
#[test]
+fn lsp_code_actions_deno_types_for_npm() {
+ 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!({}).to_string());
+ temp_dir.write(
+ "package.json",
+ json!({
+ "dependencies": {
+ "react": "^18.2.0",
+ "@types/react": "^18.3.10",
+ },
+ })
+ .to_string(),
+ );
+ temp_dir.create_dir_all("managed_node_modules");
+ temp_dir.write(
+ "managed_node_modules/deno.json",
+ json!({
+ "nodeModulesDir": false,
+ })
+ .to_string(),
+ );
+ context.run_npm("install");
+ 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": "import \"react\";\n",
+ }
+ }));
+ let res = client.write_request(
+ "textDocument/codeAction",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.url().join("file.ts").unwrap(),
+ },
+ "range": {
+ "start": { "line": 0, "character": 7 },
+ "end": { "line": 0, "character": 7 },
+ },
+ "context": { "diagnostics": [], "only": ["quickfix"] },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([
+ {
+ "title": "Add @deno-types directive for \"@types/react\"",
+ "kind": "quickfix",
+ "edit": {
+ "changes": {
+ temp_dir.url().join("file.ts").unwrap(): [
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 },
+ },
+ "newText": "// @deno-types=\"@types/react\"\n",
+ },
+ ],
+ },
+ },
+ },
+ ]),
+ );
+ client.did_open(json!({
+ "textDocument": {
+ "uri": temp_dir.url().join("managed_node_modules/file.ts").unwrap(),
+ "languageId": "typescript",
+ "version": 1,
+ "text": "import \"npm:react\";\n",
+ }
+ }));
+ client.write_request(
+ "workspace/executeCommand",
+ json!({
+ "command": "deno.cache",
+ "arguments": [
+ [],
+ temp_dir.url().join("managed_node_modules/file.ts").unwrap(),
+ ],
+ }),
+ );
+ let res = client.write_request(
+ "textDocument/codeAction",
+ json!({
+ "textDocument": {
+ "uri": temp_dir.url().join("managed_node_modules/file.ts").unwrap(),
+ },
+ "range": {
+ "start": { "line": 0, "character": 7 },
+ "end": { "line": 0, "character": 7 },
+ },
+ "context": { "diagnostics": [], "only": ["quickfix"] },
+ }),
+ );
+ assert_eq!(
+ res,
+ json!([
+ {
+ "title": "Add @deno-types directive for \"npm:@types/react@^18.3.10\"",
+ "kind": "quickfix",
+ "edit": {
+ "changes": {
+ temp_dir.url().join("managed_node_modules/file.ts").unwrap(): [
+ {
+ "range": {
+ "start": { "line": 0, "character": 0 },
+ "end": { "line": 0, "character": 0 },
+ },
+ "newText": "// @deno-types=\"npm:@types/react@^18.3.10\"\n",
+ },
+ ],
+ },
+ },
+ },
+ ]),
+ );
+ client.shutdown();
+}
+
+#[test]
fn lsp_cache_on_save() {
let context = TestContextBuilder::new()
.use_http_server()