diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-04-10 18:06:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 18:06:37 -0700 |
commit | 736f73b008c3f0354b870b70b8d494983046b0f7 (patch) | |
tree | a6f51edc66cdc41fc5d8c4efa912f6e15231a393 /cli/lsp/language_server.rs | |
parent | 9304126be5633d4e7d384a8df87f5833a7a145e2 (diff) |
perf(lsp): Only evict caches on JS side when things actually change (#23293)
Currently we evict a lot of the caches on the JS side of things on every
request, namely script versions, script file names, and compiler
settings (as of #23283, it's not quite every request but it's still
unnecessarily often).
This PR reports changes to the JS side, so that it can evict exactly the
caches that it needs too. We might want to do some batching in the
future so as not to do 1 request per change.
Diffstat (limited to 'cli/lsp/language_server.rs')
-rw-r--r-- | cli/lsp/language_server.rs | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 17c8cc5ba..2e1386fd0 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -84,6 +84,7 @@ use super::text; use super::tsc; use super::tsc::Assets; use super::tsc::AssetsSnapshot; +use super::tsc::ChangeKind; use super::tsc::GetCompletionDetailsArgs; use super::tsc::TsServer; use super::urls; @@ -1183,13 +1184,23 @@ impl Inner { // refresh the npm specifiers because it might have discovered // a @types/node package and now's a good time to do that anyway self.refresh_npm_specifiers().await; + + self + .ts_server + .project_changed( + self.snapshot(), + &[], + self.documents.project_version(), + true, + ) + .await; } fn shutdown(&self) -> LspResult<()> { Ok(()) } - fn did_open( + async fn did_open( &mut self, specifier: &ModuleSpecifier, params: DidOpenTextDocumentParams, @@ -1217,6 +1228,16 @@ impl Inner { params.text_document.language_id.parse().unwrap(), params.text_document.text.into(), ); + let version = self.documents.project_version(); + self + .ts_server + .project_changed( + self.snapshot(), + &[(document.specifier(), ChangeKind::Opened)], + version, + false, + ) + .await; self.performance.measure(mark); document @@ -1234,6 +1255,16 @@ impl Inner { ) { Ok(document) => { if document.is_diagnosable() { + let version = self.documents.project_version(); + self + .ts_server + .project_changed( + self.snapshot(), + &[(document.specifier(), ChangeKind::Modified)], + version, + false, + ) + .await; self.refresh_npm_specifiers().await; self.diagnostics_server.invalidate(&[specifier]); self.send_diagnostics_update(); @@ -1284,6 +1315,16 @@ impl Inner { if let Err(err) = self.documents.close(&specifier) { error!("{:#}", err); } + let version = self.documents.project_version(); + self + .ts_server + .project_changed( + self.snapshot(), + &[(&specifier, ChangeKind::Closed)], + version, + false, + ) + .await; self.performance.measure(mark); } @@ -3174,7 +3215,7 @@ impl tower_lsp::LanguageServer for LanguageServer { let specifier = inner .url_map .normalize_url(¶ms.text_document.uri, LspUrlKind::File); - let document = inner.did_open(&specifier, params); + let document = inner.did_open(&specifier, params).await; if document.is_diagnosable() { inner.refresh_npm_specifiers().await; inner.diagnostics_server.invalidate(&[specifier]); |