Skip to content

Commit

Permalink
fix(lsp): include mtime in tsc script version (denoland#20911)
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Oct 17, 2023
1 parent 659cd90 commit 7561f6e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cli/lsp/documents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl Document {
pub fn script_version(&self) -> String {
self
.maybe_lsp_version()
.map(|v| v.to_string())
.map(|v| format!("{}+{v}", self.fs_version()))
.unwrap_or_else(|| self.fs_version().to_string())
}

Expand Down
47 changes: 47 additions & 0 deletions cli/tests/integration/lsp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8092,6 +8092,53 @@ fn lsp_diagnostics_refresh_dependents() {
assert_eq!(client.queue_len(), 0);
}

// Regression test for https://github.com/denoland/deno/issues/10897.
#[test]
fn lsp_ts_diagnostics_refresh_on_lsp_version_reset() {
let context = TestContextBuilder::new().use_temp_cwd().build();
let temp_dir = context.temp_dir();
temp_dir.write("file.ts", r#"Deno.readTextFileSync(1);"#);
let mut client = context.new_lsp_command().build();
client.initialize_default();
let diagnostics = client.did_open(json!({
"textDocument": {
"uri": temp_dir.uri().join("file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": temp_dir.read_to_string("file.ts"),
},
}));
assert_eq!(diagnostics.all().len(), 1);
client.write_notification(
"textDocument/didClose",
json!({
"textDocument": {
"uri": temp_dir.uri().join("file.ts").unwrap(),
},
}),
);
temp_dir.remove_file("file.ts");
// VSCode opens with `version: 1` again because the file was deleted. Ensure
// diagnostics are still refreshed.
client.did_open_raw(json!({
"textDocument": {
"uri": temp_dir.uri().join("file.ts").unwrap(),
"languageId": "typescript",
"version": 1,
"text": "",
},
}));
temp_dir.write("file.ts", r#""#);
client.did_save(json!({
"textDocument": {
"uri": temp_dir.uri().join("file.ts").unwrap(),
},
}));
let diagnostics = client.read_diagnostics();
assert_eq!(diagnostics.all(), vec![]);
client.shutdown();
}

#[test]
fn lsp_npm_missing_type_imports_diagnostics() {
let context = TestContextBuilder::new()
Expand Down

0 comments on commit 7561f6e

Please sign in to comment.