@@ -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,14 +31,16 @@ 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 definitely cause the file to be closed and reopened.
38- // setTextDocumentLanguage takes precedence over setting the languageId in UI.
39- void vscode . languages . setTextDocumentLanguage ( document , "cpp" ) ;
40- 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+ }
4144 }
4245 // client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
4346 client . takeOwnership ( document ) ;
0 commit comments