Description
Bug Report
If a configure
request is sent prior to an open
request, the projectLoadingStart
event doesn't arrive until the project is finished loading.
🕗 Version & Regression Information
This behaviour exists in 4.5.4 and HEAD (at the time of writing).
💻 Code
Here's a minimal tsserver client which demonstrates the issue. If you tail the tsserver.log
you'll see that the projectLoadingStart
is being sent at the correct time. If I remove the configure
request, the projectLoadingStart
arrives right away.
import { fork } from "child_process";
const tsserver = "/home/icholy/src/github.com/microsoft/TypeScript/bin/tsserver";
const args = [
"--logFile", "tsserver.log",
"--logVerbosity", "verbose",
];
const proc = fork(tsserver, args, { silent: true });
proc.once("exit", () => {
console.error("tsserver exited");
process.exit();
});
const { stdin, stdout } = proc;
if (!stdin || !stdout) {
throw new Error("failed to get stdin/stdout");
}
stdout.on("data", (data) => {
console.log(data.toString());
});
const configure = {
command: "configure",
seq: 1,
type: "request",
arguments: {
preferences: {}
}
};
const open = {
command: "open",
seq: 2,
type: "request",
arguments: {
file: "/home/icholy/src/example/main.ts",
},
};
const msg = JSON.stringify(configure) + "\n" + JSON.stringify(open) + "\n";
stdin.write(msg);
🙁 Actual behavior
The projectLoadingStart
event arrives at the same time as projectLoadingFinish
.
🙂 Expected behavior
The projectLoadingStart
arrives immediately after the open
request is sent.
Details
The configure
response is sent first and sets canWrite = false
. The projectLoadingStart
event is then placed into the pending
array. I'm assuming the project loading/analysis is starving the event loop which prevents setCanWriteFlagAndWriteMessageIfNecessary
from being called.
TypeScript/src/tsserver/nodeServer.ts
Lines 321 to 336 in c71ff4d
It seems like the analysis/loading would need some preemption points to allow for the event loop to process pending tasks.