-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Change sys.write to async in tsserver #5354
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This seems pretty dangerous as a change -- how do we know we don't have any consumers of |
That is a legitimate concern. As the problem currently only affects tsserver, it might be safer to overwrite the definition of |
I do not think this is the right thing to do. we have had that in the past, and we run into issues not draining the stream before the process ends. if this is for ts server purposes, we can override the implementation in the server.ts |
I moved the changes to |
|
||
function writeNext() { | ||
if (messagesToWrite.length > 0) { | ||
messagesToWrite = copyListRemovingItem(messagesToWrite[0], messagesToWrite); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need to copy the list (given that messagesToWrite
is effectively a queue so items are added\removed at known positions)? You can do better with messagesToWrite.shift
let pending: string[] = [];
function queueMessage(s: string) {
pending.push(s);
if (pending.length === 1) {
drain();
}
}
function drain() {
Debug.assert(pending.length > 0);
writeBuffer(new Buffer(pending[0], "utf8"), 0);
}
function writeBuffer(buffer: Buffer, offset: number) {
const toWrite = buffer.length - offset;
fs.write(1, buffer, offset, toWrite, undefined, (err, written, buffer) => {
if (toWrite > written) {
writeBuffer(buffer, offset + written);
}
else {
Debug.assert(pending.length > 0);
pending.shift();
if (pending.length > 0) {
drain();
}
}
});
}
👍 |
|
||
function writeBuffer(buffer: Buffer, offset: number) { | ||
const toWrite = buffer.length - offset; | ||
fs.write(1, buffer, offset, toWrite, undefined, (err, written, buffer) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we care about errors here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are retrying instead of handling the error anyway, it may only be used for printing error messages I think.
LGTM |
Change sys.write to async in tsserver
This is related to
microsoft/TypeScript-Sublime-Plugin#379
and
#2758 (comment)
fs.writeSync
truncates a long line, and will throw an exception ofEAGAIN: Resource not available
if re trying right away. Changing the writing behavior to async solves the problem.