Skip to content

Commit

Permalink
clone the TextDocument on didOpen to fix a race condition (#4110)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrow authored and sean-mcmanus committed Aug 20, 2019
1 parent 4be6550 commit e17de19
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Extension/src/LanguageServer/protocolFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'use strict';

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

me.onDidOpenTextDocument(document);

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

0 comments on commit e17de19

Please sign in to comment.