@@ -58,7 +58,7 @@ import { DataBinding } from './dataBinding';
58
58
import { cachedEditorConfigSettings , getEditorConfigSettings } from './editorConfig' ;
59
59
import { CppSourceStr , clients , configPrefix , updateLanguageConfigurations , usesCrashHandler , watchForCrashes } from './extension' ;
60
60
import { LocalizeStringParams , getLocaleId , getLocalizedString } from './localization' ;
61
- import { PersistentFolderState , PersistentWorkspaceState } from './persistentState' ;
61
+ import { PersistentFolderState , PersistentState , PersistentWorkspaceState } from './persistentState' ;
62
62
import { RequestCancelled , ServerCancelled , createProtocolFilter } from './protocolFilter' ;
63
63
import * as refs from './references' ;
64
64
import { CppSettings , OtherSettings , SettingsParams , WorkspaceFolderSettingsParams } from './settings' ;
@@ -564,6 +564,16 @@ export interface ProjectContextResult {
564
564
fileContext : FileContextResult ;
565
565
}
566
566
567
+ interface FolderFilesEncodingChanged {
568
+ uri : string ;
569
+ filesEncoding : string ;
570
+ }
571
+
572
+ interface FilesEncodingChanged {
573
+ workspaceFallbackEncoding ?: string ;
574
+ foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
575
+ }
576
+
567
577
// Requests
568
578
const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
569
579
const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -642,6 +652,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType<number> = new Notifi
642
652
const DoxygenCommentGeneratedNotification : NotificationType < GenerateDoxygenCommentResult > = new NotificationType < GenerateDoxygenCommentResult > ( 'cpptools/insertDoxygenComment' ) ;
643
653
const CanceledReferencesNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/canceledReferences' ) ;
644
654
const IntelliSenseResultNotification : NotificationType < IntelliSenseResult > = new NotificationType < IntelliSenseResult > ( 'cpptools/intelliSenseResult' ) ;
655
+ const FilesEncodingChangedNotification : NotificationType < FilesEncodingChanged > = new NotificationType < FilesEncodingChanged > ( 'cpptools/filesEncodingChanged' ) ;
645
656
646
657
let failureMessageShown : boolean = false ;
647
658
@@ -819,6 +830,7 @@ export interface Client {
819
830
getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
820
831
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
821
832
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
833
+ filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
822
834
}
823
835
824
836
export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -1367,7 +1379,13 @@ export class DefaultClient implements Client {
1367
1379
DefaultClient . isStarted . resolve ( ) ;
1368
1380
}
1369
1381
1370
- private getWorkspaceFolderSettings ( workspaceFolderUri : vscode . Uri | undefined , settings : CppSettings , otherSettings : OtherSettings ) : WorkspaceFolderSettingsParams {
1382
+ private getWorkspaceFolderSettings ( workspaceFolderUri : vscode . Uri | undefined , workspaceFolder : vscode . WorkspaceFolder | undefined , settings : CppSettings , otherSettings : OtherSettings ) : WorkspaceFolderSettingsParams {
1383
+ const filesEncoding : string = otherSettings . filesEncoding ;
1384
+ let filesEncodingChanged : boolean = false ;
1385
+ if ( workspaceFolder ) {
1386
+ const lastFilesEncoding : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastFilesEncoding" , "" , workspaceFolder ) ;
1387
+ filesEncodingChanged = lastFilesEncoding . Value !== filesEncoding ;
1388
+ }
1371
1389
const result : WorkspaceFolderSettingsParams = {
1372
1390
uri : workspaceFolderUri ?. toString ( ) ,
1373
1391
intelliSenseEngine : settings . intelliSenseEngine ,
@@ -1464,7 +1482,8 @@ export class DefaultClient implements Client {
1464
1482
doxygenSectionTags : settings . doxygenSectionTags ,
1465
1483
filesExclude : otherSettings . filesExclude ,
1466
1484
filesAutoSaveAfterDelay : otherSettings . filesAutoSaveAfterDelay ,
1467
- filesEncoding : otherSettings . filesEncoding ,
1485
+ filesEncoding : filesEncoding ,
1486
+ filesEncodingChanged : filesEncodingChanged ,
1468
1487
searchExclude : otherSettings . searchExclude ,
1469
1488
editorAutoClosingBrackets : otherSettings . editorAutoClosingBrackets ,
1470
1489
editorInlayHintsEnabled : otherSettings . editorInlayHintsEnabled ,
@@ -1480,10 +1499,10 @@ export class DefaultClient implements Client {
1480
1499
const workspaceFolderSettingsParams : WorkspaceFolderSettingsParams [ ] = [ ] ;
1481
1500
if ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ) {
1482
1501
for ( const workspaceFolder of vscode . workspace . workspaceFolders ) {
1483
- workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( workspaceFolder . uri , new CppSettings ( workspaceFolder . uri ) , new OtherSettings ( workspaceFolder . uri ) ) ) ;
1502
+ workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( workspaceFolder . uri , workspaceFolder , new CppSettings ( workspaceFolder . uri ) , new OtherSettings ( workspaceFolder . uri ) ) ) ;
1484
1503
}
1485
1504
} else {
1486
- workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( this . RootUri , workspaceSettings , workspaceOtherSettings ) ) ;
1505
+ workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( this . RootUri , undefined , workspaceSettings , workspaceOtherSettings ) ) ;
1487
1506
}
1488
1507
return workspaceFolderSettingsParams ;
1489
1508
}
@@ -1498,9 +1517,13 @@ export class DefaultClient implements Client {
1498
1517
if ( this . currentCopilotHoverEnabled && workspaceSettings . copilotHover !== this . currentCopilotHoverEnabled . Value ) {
1499
1518
void util . promptForReloadWindowDueToSettingsChange ( ) ;
1500
1519
}
1520
+ const workspaceFallbackEncoding : string = workspaceOtherSettings . filesEncoding ;
1521
+ const lastWorkspaceFallbackEncoding : PersistentState < string > = new PersistentState < string > ( "CPP.lastWorkspaceFallbackEncoding" , "" ) ;
1522
+ const workspaceFallbackEncodingChanged = lastWorkspaceFallbackEncoding . Value !== workspaceFallbackEncoding ;
1501
1523
return {
1502
1524
filesAssociations : workspaceOtherSettings . filesAssociations ,
1503
- workspaceFallbackEncoding : workspaceOtherSettings . filesEncoding ,
1525
+ workspaceFallbackEncoding : workspaceFallbackEncoding ,
1526
+ workspaceFallbackEncodingChanged : workspaceFallbackEncodingChanged ,
1504
1527
maxConcurrentThreads : workspaceSettings . maxConcurrentThreads ,
1505
1528
maxCachedProcesses : workspaceSettings . maxCachedProcesses ,
1506
1529
maxMemory : workspaceSettings . maxMemory ,
@@ -2438,6 +2461,7 @@ export class DefaultClient implements Client {
2438
2461
this . languageClient . onNotification ( ReportCodeAnalysisTotalNotification , ( e ) => this . updateCodeAnalysisTotal ( e ) ) ;
2439
2462
this . languageClient . onNotification ( DoxygenCommentGeneratedNotification , ( e ) => void this . insertDoxygenComment ( e ) ) ;
2440
2463
this . languageClient . onNotification ( CanceledReferencesNotification , this . serverCanceledReferences ) ;
2464
+ this . languageClient . onNotification ( FilesEncodingChangedNotification , ( e ) => this . filesEncodingChanged ( e ) ) ;
2441
2465
}
2442
2466
2443
2467
private handleIntelliSenseResult ( intelliSenseResult : IntelliSenseResult ) : void {
@@ -4085,6 +4109,20 @@ export class DefaultClient implements Client {
4085
4109
public getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined {
4086
4110
return this . copilotHoverProvider ;
4087
4111
}
4112
+
4113
+ public filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void {
4114
+ if ( filesEncodingChanged . workspaceFallbackEncoding !== undefined ) {
4115
+ const lastWorkspaceFallbackEncoding : PersistentState < string > = new PersistentState < string > ( "CPP.lastWorkspaceFallbackEncoding" , "" ) ;
4116
+ lastWorkspaceFallbackEncoding . Value = filesEncodingChanged . workspaceFallbackEncoding ;
4117
+ }
4118
+ for ( const folderFilesEncoding of filesEncodingChanged . foldersFilesEncoding ) {
4119
+ const workspaceFolder : vscode . WorkspaceFolder | undefined = vscode . workspace . getWorkspaceFolder ( vscode . Uri . parse ( folderFilesEncoding . uri ) ) ;
4120
+ if ( workspaceFolder !== undefined ) {
4121
+ const lastFilesEncoding : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastFilesEncoding" , "" , workspaceFolder ) ;
4122
+ lastFilesEncoding . Value = folderFilesEncoding . filesEncoding ;
4123
+ }
4124
+ }
4125
+ }
4088
4126
}
4089
4127
4090
4128
function getLanguageServerFileName ( ) : string {
@@ -4200,4 +4238,5 @@ class NullClient implements Client {
4200
4238
getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
4201
4239
getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
4202
4240
getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4241
+ filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
4203
4242
}
0 commit comments