Skip to content

Commit e17de19

Browse files
bobbrowsean-mcmanus
authored andcommitted
clone the TextDocument on didOpen to fix a race condition (#4110)
1 parent 4be6550 commit e17de19

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Extension/src/LanguageServer/protocolFilter.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
'use strict';
66

77
import * as path from 'path';
8+
import { TextDocument } from 'vscode';
89
import { Middleware } from 'vscode-languageclient';
910
import { ClientCollection } from './clientCollection';
1011
import { Client } from './client';
@@ -33,8 +34,14 @@ export function createProtocolFilter(me: Client, clients: ClientCollection): Mid
3334
}
3435

3536
me.onDidOpenTextDocument(document);
37+
38+
// 'document' is a reference to the live TextDocument. Because the document can change while we wait for
39+
// custom configurations, we must clone the current state of the object before yielding the thread.
40+
// Theoretically, we should do this everywhere, but there are no other callbacks that read the document
41+
// state directly (just the Uri) so there doesn't appear to be a need to do it.
42+
const documentCopy: TextDocument = {...document};
3643
me.provideCustomConfiguration(document.uri, null);
37-
me.notifyWhenReady(() => sendMessage(document));
44+
me.notifyWhenReady(() => sendMessage(documentCopy));
3845
}
3946
},
4047
didChange: (textDocumentChangeEvent, sendMessage) => {

0 commit comments

Comments
 (0)