Skip to content

Commit

Permalink
read diagnostics in change_configuration()
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Feb 7, 2025
1 parent a18abde commit 022bdb2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
20 changes: 6 additions & 14 deletions tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1415,7 +1415,7 @@ fn lsp_import_attributes() {
},
}));

client.did_open(json!({
client.did_open_raw(json!({
"textDocument": {
"uri": "file:///a/test.json",
"languageId": "json",
Expand Down Expand Up @@ -2092,7 +2092,6 @@ fn lsp_suggestion_actions_disabled() {
},
},
}));
client.read_diagnostics();
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": temp_dir.url().join("file.ts").unwrap(),
Expand Down Expand Up @@ -14061,10 +14060,10 @@ fn lsp_node_modules_dir() {
"arguments": [["npm:chalk", "npm:@types/node"], file_uri],
}),
);
client.read_diagnostics()
};

cache(&mut client);
client.read_diagnostics();

assert!(!temp_dir.path().join("node_modules").exists());

Expand Down Expand Up @@ -14095,15 +14094,12 @@ fn lsp_node_modules_dir() {
"imports": {},
},
"unstable": [],
} }));
} }))
};
refresh_config(&mut client);

let diagnostics = client.read_diagnostics();
let diagnostics = refresh_config(&mut client);
assert_eq!(diagnostics.all().len(), 2, "{:#?}", diagnostics); // not cached

cache(&mut client);
client.read_diagnostics();

assert!(temp_dir.path().join("node_modules/chalk").exists());
assert!(temp_dir.path().join("node_modules/@types/node").exists());
Expand All @@ -14115,10 +14111,7 @@ fn lsp_node_modules_dir() {
"{ \"nodeModulesDir\": \"auto\" }\n",
);
refresh_config(&mut client);
client.read_diagnostics();
cache(&mut client);

let diagnostics = client.read_diagnostics();
let diagnostics = cache(&mut client);
assert_eq!(diagnostics.all().len(), 0, "{:#?}", diagnostics);

assert!(lockfile_path.exists());
Expand Down Expand Up @@ -14195,7 +14188,7 @@ fn lsp_vendor_dir() {
temp_dir.path().join("deno.json"),
"{ \"vendor\": true, \"lock\": false }\n",
);
client.change_configuration(json!({ "deno": {
let diagnostics = client.change_configuration(json!({ "deno": {
"enable": true,
"config": "./deno.json",
"codeLens": {
Expand All @@ -14214,7 +14207,6 @@ fn lsp_vendor_dir() {
"unstable": [],
} }));

let diagnostics = client.read_diagnostics();
// won't be cached until a manual cache occurs
assert_eq!(
diagnostics
Expand Down
6 changes: 5 additions & 1 deletion tests/util/server/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,10 @@ impl LspClient {
self.write_notification("textDocument/didOpen", params);
}

pub fn change_configuration(&mut self, config: Value) {
pub fn change_configuration(
&mut self,
config: Value,
) -> CollectedDiagnostics {
self.config = config;
if self.supports_workspace_configuration {
self.write_notification(
Expand All @@ -932,6 +935,7 @@ impl LspClient {
json!({ "settings": &self.config }),
);
}
self.read_diagnostics()
}

pub fn handle_configuration_request(&mut self) {
Expand Down

0 comments on commit 022bdb2

Please sign in to comment.