summaryrefslogtreecommitdiff
path: root/tests/integration/lsp_tests.rs
diff options
context:
space:
mode:
authorNayeem Rahman <nayeemrmn99@gmail.com>2024-05-29 01:26:43 +0100
committerGitHub <noreply@github.com>2024-05-29 01:26:43 +0100
commit14a74600de6f1c206ffe4750f6cb6da59657db8e (patch)
treece593041af972fd31f83fa6b7b50458bc9f689dc /tests/integration/lsp_tests.rs
parent2024c974b613f94f31559a1b32e2d747c2083e91 (diff)
perf(lsp): lock out requests until init is complete (#23998)
Diffstat (limited to 'tests/integration/lsp_tests.rs')
-rw-r--r--tests/integration/lsp_tests.rs87
1 files changed, 27 insertions, 60 deletions
diff --git a/tests/integration/lsp_tests.rs b/tests/integration/lsp_tests.rs
index 33943d83e..09882a666 100644
--- a/tests/integration/lsp_tests.rs
+++ b/tests/integration/lsp_tests.rs
@@ -933,27 +933,30 @@ fn lsp_workspace_enable_paths_no_workspace_configuration() {
fn lsp_did_change_deno_configuration_notification() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
+ temp_dir.write("deno.json", json!({}).to_string());
+ temp_dir.write("package.json", json!({}).to_string());
let mut client = context.new_lsp_command().build();
client.initialize_default();
- temp_dir.write("deno.json", json!({}).to_string());
- client.did_change_watched_files(json!({
- "changes": [{
- "uri": temp_dir.uri().join("deno.json").unwrap(),
- "type": 1,
- }],
- }));
let res = client
.read_notification_with_method::<Value>("deno/didChangeDenoConfiguration");
assert_eq!(
res,
Some(json!({
- "changes": [{
- "scopeUri": temp_dir.uri(),
- "fileUri": temp_dir.uri().join("deno.json").unwrap(),
- "type": "added",
- "configurationType": "denoJson"
- }],
+ "changes": [
+ {
+ "scopeUri": temp_dir.uri(),
+ "fileUri": temp_dir.uri().join("deno.json").unwrap(),
+ "type": "added",
+ "configurationType": "denoJson"
+ },
+ {
+ "scopeUri": temp_dir.uri(),
+ "fileUri": temp_dir.uri().join("package.json").unwrap(),
+ "type": "added",
+ "configurationType": "packageJson"
+ },
+ ],
}))
);
@@ -1002,27 +1005,6 @@ fn lsp_did_change_deno_configuration_notification() {
}))
);
- temp_dir.write("package.json", json!({}).to_string());
- client.did_change_watched_files(json!({
- "changes": [{
- "uri": temp_dir.uri().join("package.json").unwrap(),
- "type": 1,
- }],
- }));
- let res = client
- .read_notification_with_method::<Value>("deno/didChangeDenoConfiguration");
- assert_eq!(
- res,
- Some(json!({
- "changes": [{
- "scopeUri": temp_dir.uri(),
- "fileUri": temp_dir.uri().join("package.json").unwrap(),
- "type": "added",
- "configurationType": "packageJson"
- }],
- }))
- );
-
temp_dir.write("package.json", json!({ "type": "module" }).to_string());
client.did_change_watched_files(json!({
"changes": [{
@@ -9691,26 +9673,17 @@ fn lsp_format_exclude_default_config() {
#[test]
fn lsp_format_json() {
let context = TestContextBuilder::new().use_temp_cwd().build();
- let temp_dir_path = context.temp_dir().path();
- // Also test out using a non-json file extension here.
- // What should matter is the language identifier.
- let lock_file_path = temp_dir_path.join("file.lock");
+ let temp_dir = context.temp_dir();
+ let json_file =
+ source_file(temp_dir.path().join("file.json"), "{\"key\":\"value\"}");
let mut client = context.new_lsp_command().build();
client.initialize_default();
- client.did_open(json!({
- "textDocument": {
- "uri": lock_file_path.uri_file(),
- "languageId": "json",
- "version": 1,
- "text": "{\"key\":\"value\"}"
- }
- }));
let res = client.write_request(
"textDocument/formatting",
json!({
"textDocument": {
- "uri": lock_file_path.uri_file(),
+ "uri": json_file.uri(),
},
"options": {
"tabSize": 2,
@@ -9751,7 +9724,7 @@ fn lsp_json_no_diagnostics() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let mut client = context.new_lsp_command().build();
client.initialize_default();
- client.did_open(json!({
+ client.did_open_raw(json!({
"textDocument": {
"uri": "file:///a/file.json",
"languageId": "json",
@@ -9798,7 +9771,7 @@ fn lsp_json_import_with_query_string() {
);
let mut client = context.new_lsp_command().build();
client.initialize_default();
- client.did_open(json!({
+ client.did_open_raw(json!({
"textDocument": {
"uri": temp_dir.uri().join("data.json").unwrap(),
"languageId": "json",
@@ -9821,23 +9794,17 @@ fn lsp_json_import_with_query_string() {
#[test]
fn lsp_format_markdown() {
let context = TestContextBuilder::new().use_temp_cwd().build();
- let markdown_file = context.temp_dir().path().join("file.md");
+ let temp_dir = context.temp_dir();
+ let markdown_file =
+ source_file(temp_dir.path().join("file.md"), "# Hello World");
let mut client = context.new_lsp_command().build();
client.initialize_default();
- client.did_open(json!({
- "textDocument": {
- "uri": markdown_file.uri_file(),
- "languageId": "markdown",
- "version": 1,
- "text": "# Hello World"
- }
- }));
let res = client.write_request(
"textDocument/formatting",
json!({
"textDocument": {
- "uri": markdown_file.uri_file()
+ "uri": markdown_file.uri()
},
"options": {
"tabSize": 2,
@@ -9980,7 +9947,7 @@ fn lsp_markdown_no_diagnostics() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let mut client = context.new_lsp_command().build();
client.initialize_default();
- client.did_open(json!({
+ client.did_open_raw(json!({
"textDocument": {
"uri": "file:///a/file.md",
"languageId": "markdown",