1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

fix(lsp): restart TS language service when caching dependencies (#14979)

This commit is contained in:
Bartek Iwańczuk 2022-06-27 19:43:43 +02:00 committed by GitHub
parent 440250c054
commit 681bb49d0d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 3 deletions

View file

@ -2814,9 +2814,16 @@ impl Inner {
self.client.show_message(MessageType::WARNING, err).await; self.client.show_message(MessageType::WARNING, err).await;
} }
// now that we have dependencies loaded, we need to re-analyze them and // Now that we have dependencies loaded, we need to re-analyze all the files.
// invalidate some diagnostics // For that we're invalidating all the existing diagnostics and restarting
self.diagnostics_server.invalidate(&[referrer]); // the language server for TypeScript (as it might hold to some stale
// documents).
self.diagnostics_server.invalidate_all();
let _: bool = self
.ts_server
.request(self.snapshot(), tsc::RequestMethod::Restart)
.await
.unwrap();
self.send_diagnostics_update(); self.send_diagnostics_update();
self.send_testing_update(); self.send_testing_update();

View file

@ -2871,6 +2871,9 @@ pub enum RequestMethod {
ProvideCallHierarchyIncomingCalls((ModuleSpecifier, u32)), ProvideCallHierarchyIncomingCalls((ModuleSpecifier, u32)),
/// Resolve outgoing call hierarchy items for a specific position. /// Resolve outgoing call hierarchy items for a specific position.
ProvideCallHierarchyOutgoingCalls((ModuleSpecifier, u32)), ProvideCallHierarchyOutgoingCalls((ModuleSpecifier, u32)),
// Special request, used only internally by the LSP
Restart,
} }
impl RequestMethod { impl RequestMethod {
@ -3084,6 +3087,10 @@ impl RequestMethod {
"position": position "position": position
}) })
} }
RequestMethod::Restart => json!({
"id": id,
"method": "restart",
}),
} }
} }
} }

View file

@ -589,11 +589,16 @@ delete Object.prototype.__proto__;
*/ */
function serverRequest({ id, ...request }) { function serverRequest({ id, ...request }) {
debug(`serverRequest()`, { id, ...request }); debug(`serverRequest()`, { id, ...request });
// reset all memoized source files names // reset all memoized source files names
scriptFileNamesCache = undefined; scriptFileNamesCache = undefined;
// evict all memoized source file versions // evict all memoized source file versions
scriptVersionCache.clear(); scriptVersionCache.clear();
switch (request.method) { switch (request.method) {
case "restart": {
serverRestart();
return respond(id, true);
}
case "configure": { case "configure": {
const { options, errors } = ts const { options, errors } = ts
.convertCompilerOptionsFromJson(request.compilerOptions, ""); .convertCompilerOptionsFromJson(request.compilerOptions, "");
@ -918,6 +923,11 @@ delete Object.prototype.__proto__;
debug("serverInit()"); debug("serverInit()");
} }
function serverRestart() {
languageService = ts.createLanguageService(host);
debug("serverRestart()");
}
let hasStarted = false; let hasStarted = false;
/** Startup the runtime environment, setting various flags. /** Startup the runtime environment, setting various flags.

View file

@ -251,4 +251,8 @@ declare global {
specifier: string; specifier: string;
position: number; position: number;
} }
interface Restart {
method: "restart";
}
} }