@@ -26,40 +26,42 @@ export function createProtocolFilter(clients: ClientCollection): Middleware {
2626 didOpen : ( document , sendMessage ) => {
2727 const editor : vscode . TextEditor | undefined = vscode . window . visibleTextEditors . find ( e => e . document === document ) ;
2828 if ( editor ) {
29- // Log warm start.
30- clients . timeTelemetryCollector . setDidOpenTime ( document . uri ) ;
3129 // If the file was visible editor when we were activated, we will not get a call to
3230 // onDidChangeVisibleTextEditors, so immediately open any file that is visible when we receive didOpen.
3331 // Otherwise, we defer opening the file until it's actually visible.
3432 const me : Client = clients . getClientFor ( document . uri ) ;
35- if ( clients . checkOwnership ( me , document ) ) {
36- me . TrackedDocuments . add ( document ) ;
37- const finishDidOpen = ( doc : vscode . TextDocument ) => {
38- me . provideCustomConfiguration ( doc . uri , undefined ) ;
39- me . notifyWhenReady ( ( ) => {
40- sendMessage ( doc ) ;
41- me . onDidOpenTextDocument ( doc ) ;
42- if ( editor && editor === vscode . window . activeTextEditor ) {
43- onDidChangeActiveTextEditor ( editor ) ;
44- }
45- } ) ;
46- } ;
47- let languageChanged : boolean = false ;
48- if ( ( document . uri . path . endsWith ( ".C" ) || document . uri . path . endsWith ( ".H" ) ) && document . languageId === "c" ) {
49- const cppSettings : CppSettings = new CppSettings ( ) ;
50- if ( cppSettings . autoAddFileAssociations ) {
51- const fileName : string = path . basename ( document . uri . fsPath ) ;
52- const mappingString : string = fileName + "@" + document . uri . fsPath ;
53- me . addFileAssociations ( mappingString , false ) ;
54- me . sendDidChangeSettings ( { files : { associations : new OtherSettings ( ) . filesAssociations } } ) ;
55- vscode . languages . setTextDocumentLanguage ( document , "cpp" ) . then ( ( newDoc : vscode . TextDocument ) => {
56- finishDidOpen ( newDoc ) ;
33+ if ( ! me . TrackedDocuments . has ( document ) ) {
34+ // Log warm start.
35+ clients . timeTelemetryCollector . setDidOpenTime ( document . uri ) ;
36+ if ( clients . checkOwnership ( me , document ) ) {
37+ me . TrackedDocuments . add ( document ) ;
38+ const finishDidOpen = ( doc : vscode . TextDocument ) => {
39+ me . provideCustomConfiguration ( doc . uri , undefined ) ;
40+ me . notifyWhenReady ( ( ) => {
41+ sendMessage ( doc ) ;
42+ me . onDidOpenTextDocument ( doc ) ;
43+ if ( editor && editor === vscode . window . activeTextEditor ) {
44+ onDidChangeActiveTextEditor ( editor ) ;
45+ }
5746 } ) ;
58- languageChanged = true ;
47+ } ;
48+ let languageChanged : boolean = false ;
49+ if ( ( document . uri . path . endsWith ( ".C" ) || document . uri . path . endsWith ( ".H" ) ) && document . languageId === "c" ) {
50+ const cppSettings : CppSettings = new CppSettings ( ) ;
51+ if ( cppSettings . autoAddFileAssociations ) {
52+ const fileName : string = path . basename ( document . uri . fsPath ) ;
53+ const mappingString : string = fileName + "@" + document . uri . fsPath ;
54+ me . addFileAssociations ( mappingString , false ) ;
55+ me . sendDidChangeSettings ( { files : { associations : new OtherSettings ( ) . filesAssociations } } ) ;
56+ vscode . languages . setTextDocumentLanguage ( document , "cpp" ) . then ( ( newDoc : vscode . TextDocument ) => {
57+ finishDidOpen ( newDoc ) ;
58+ } ) ;
59+ languageChanged = true ;
60+ }
61+ }
62+ if ( ! languageChanged ) {
63+ finishDidOpen ( document ) ;
5964 }
60- }
61- if ( ! languageChanged ) {
62- finishDidOpen ( document ) ;
6365 }
6466 }
6567 } else {
0 commit comments