@@ -11,6 +11,7 @@ import * as util from '../common';
11
11
import { logAndReturn } from '../Utility/Async/returns' ;
12
12
import { Client } from './client' ;
13
13
import { clients } from './extension' ;
14
+ import { hasFileAssociation } from './settings' ;
14
15
import { shouldChangeFromCToCpp } from './utils' ;
15
16
16
17
export const RequestCancelled : number = - 32800 ;
@@ -30,14 +31,16 @@ export function createProtocolFilter(): Middleware {
30
31
client . TrackedDocuments . set ( uriString , document ) ;
31
32
// Work around vscode treating ".C" or ".H" as c, by adding this file name to file associations as cpp
32
33
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
+ }
41
44
}
42
45
// client.takeOwnership() will call client.TrackedDocuments.add() again, but that's ok. It's a Set.
43
46
client . takeOwnership ( document ) ;
0 commit comments