diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-04-22 08:03:16 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-22 08:03:16 -0700 |
commit | aac7a8cb7cc675e3cb2ca1ddb39629a8fa59113b (patch) | |
tree | c7bfff39027d739281b8f666d91023e921a45746 /cli/tsc/99_main_compiler.js | |
parent | 2f5a6a8514ad8eadce1a0a9f1a7a419692e337ef (diff) |
perf(lsp): Batch "$projectChanged" notification in with the next JS request (#23451)
The actual handling of `$projectChanged` is quick, but JS requests are
not. The cleared caches only get repopulated on the next actual request,
so just batch the change notification in with the next actual request.
No significant difference in benchmarks on my machine, but this speeds
up `did_change` handling and reduces our total number of JS requests (in
addition to coalescing multiple JS change notifs into one).
Diffstat (limited to 'cli/tsc/99_main_compiler.js')
-rw-r--r-- | cli/tsc/99_main_compiler.js | 59 |
1 files changed, 30 insertions, 29 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 836d81f87..c2c9a88d5 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -542,7 +542,7 @@ delete Object.prototype.__proto__; } } - /** @type {ts.LanguageService} */ + /** @type {ts.LanguageService & { [k:string]: any }} */ let languageService; /** An object literal of the incremental compiler host, which provides the @@ -1073,42 +1073,43 @@ delete Object.prototype.__proto__; ops.op_respond(JSON.stringify(data)); } - function serverRequest(id, method, args) { + /** + * @param {number} id + * @param {string} method + * @param {any[]} args + * @param {[[string, number][], number, boolean] | null} maybeChange + */ + function serverRequest(id, method, args, maybeChange) { if (logDebug) { - debug(`serverRequest()`, id, method, args); + debug(`serverRequest()`, id, method, args, maybeChange); } lastRequestMethod = method; - switch (method) { - case "$projectChanged": { - /** @type {[string, number][]} */ - const changedScripts = args[0]; - /** @type {number} */ - const newProjectVersion = args[1]; - /** @type {boolean} */ - const configChanged = args[2]; - - if (configChanged) { - tsConfigCache = null; - isNodeSourceFileCache.clear(); - } + if (maybeChange !== null) { + const changedScripts = maybeChange[0]; + const newProjectVersion = maybeChange[1]; + const configChanged = maybeChange[2]; + + if (configChanged) { + tsConfigCache = null; + isNodeSourceFileCache.clear(); + } - projectVersionCache = newProjectVersion; + projectVersionCache = newProjectVersion; - let opened = false; - for (const { 0: script, 1: changeKind } of changedScripts) { - if (changeKind == ChangeKind.Opened) { - opened = true; - } - scriptVersionCache.delete(script); - sourceTextCache.delete(script); - } - - if (configChanged || opened) { - scriptFileNamesCache = undefined; + let opened = false; + for (const { 0: script, 1: changeKind } of changedScripts) { + if (changeKind == ChangeKind.Opened) { + opened = true; } + scriptVersionCache.delete(script); + sourceTextCache.delete(script); + } - return respond(id); + if (configChanged || opened) { + scriptFileNamesCache = undefined; } + } + switch (method) { case "$getSupportedCodeFixes": { return respond( id, |