@@ -11,6 +11,7 @@ import * as util from '../common';
1111import { logAndReturn } from '../Utility/Async/returns' ;
1212import { Client } from './client' ;
1313import { clients } from './extension' ;
14+ import { hasFileAssociation } from './settings' ;
1415import { shouldChangeFromCToCpp } from './utils' ;
1516
1617export const RequestCancelled : number = - 32800 ;
@@ -30,21 +31,22 @@ export function createProtocolFilter(): Middleware {
3031 client . TrackedDocuments . set ( uriString , document ) ;
3132 // Work around vscode treating ".C" or ".H" as c, by adding this file name to file associations as cpp
3233 if ( document . languageId === "c" && shouldChangeFromCToCpp ( document ) ) {
33- const baseFileName : string = path . basename ( document . fileName ) ;
34- const mappingString : string = baseFileName + "@" + document . fileName ;
35- client . addFileAssociations ( mappingString , "cpp" ) ;
36- client . sendDidChangeSettings ( ) ;
37- // This will cause the file to be closed and reopened.
38- void vscode . languages . setTextDocumentLanguage ( document , "cpp" ) ;
39- return ;
34+ // Don't override the user's setting.
35+ if ( ! hasFileAssociation ( path . basename ( document . uri . fsPath ) ) ) {
36+ const baseFileName : string = path . basename ( document . fileName ) ;
37+ const mappingString : string = baseFileName + "@" + document . fileName ;
38+ client . addFileAssociations ( mappingString , "cpp" ) ;
39+ client . sendDidChangeSettings ( ) ;
40+ // The following will cause the file to be closed and reopened.
41+ void vscode . languages . setTextDocumentLanguage ( document , "cpp" ) ;
42+ return ;
43+ }
4044 }
4145 // client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
4246 client . takeOwnership ( document ) ;
4347 void sendMessage ( document ) ;
44- const editor : vscode . TextEditor | undefined = vscode . window . visibleTextEditors . find ( editor => editor . document === document ) ;
45- if ( editor ) {
46- client . onDidChangeVisibleTextEditors ( [ editor ] ) . catch ( logAndReturn . undefined ) ;
47- }
48+ const cppEditors : vscode . TextEditor [ ] = vscode . window . visibleTextEditors . filter ( e => util . isCpp ( e . document ) ) ;
49+ client . onDidChangeVisibleTextEditors ( cppEditors ) . catch ( logAndReturn . undefined ) ;
4850 }
4951 }
5052 } ,
0 commit comments