@@ -58,7 +58,7 @@ import { DataBinding } from './dataBinding';
5858import { cachedEditorConfigSettings , getEditorConfigSettings } from './editorConfig' ;
5959import { CppSourceStr , clients , configPrefix , updateLanguageConfigurations , usesCrashHandler , watchForCrashes } from './extension' ;
6060import { LocalizeStringParams , getLocaleId , getLocalizedString } from './localization' ;
61- import { PersistentFolderState , PersistentWorkspaceState } from './persistentState' ;
61+ import { PersistentFolderState , PersistentState , PersistentWorkspaceState } from './persistentState' ;
6262import { RequestCancelled , ServerCancelled , createProtocolFilter } from './protocolFilter' ;
6363import * as refs from './references' ;
6464import { CppSettings , OtherSettings , SettingsParams , WorkspaceFolderSettingsParams } from './settings' ;
@@ -564,6 +564,16 @@ export interface ProjectContextResult {
564564 fileContext : FileContextResult ;
565565}
566566
567+ interface FolderFilesEncodingChanged {
568+ uri : string ;
569+ filesEncoding : string ;
570+ }
571+
572+ interface FilesEncodingChanged {
573+ workspaceFallbackEncoding ?: string ;
574+ foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
575+ }
576+
567577// Requests
568578const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
569579const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -642,6 +652,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType<number> = new Notifi
642652const DoxygenCommentGeneratedNotification : NotificationType < GenerateDoxygenCommentResult > = new NotificationType < GenerateDoxygenCommentResult > ( 'cpptools/insertDoxygenComment' ) ;
643653const CanceledReferencesNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/canceledReferences' ) ;
644654const IntelliSenseResultNotification : NotificationType < IntelliSenseResult > = new NotificationType < IntelliSenseResult > ( 'cpptools/intelliSenseResult' ) ;
655+ const FilesEncodingChangedNotification : NotificationType < FilesEncodingChanged > = new NotificationType < FilesEncodingChanged > ( 'cpptools/filesEncodingChanged' ) ;
645656
646657let failureMessageShown : boolean = false ;
647658
@@ -819,6 +830,7 @@ export interface Client {
819830 getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
820831 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
821832 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
833+ filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
822834}
823835
824836export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -1367,7 +1379,13 @@ export class DefaultClient implements Client {
13671379 DefaultClient . isStarted . resolve ( ) ;
13681380 }
13691381
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+ }
13711389 const result : WorkspaceFolderSettingsParams = {
13721390 uri : workspaceFolderUri ?. toString ( ) ,
13731391 intelliSenseEngine : settings . intelliSenseEngine ,
@@ -1464,7 +1482,8 @@ export class DefaultClient implements Client {
14641482 doxygenSectionTags : settings . doxygenSectionTags ,
14651483 filesExclude : otherSettings . filesExclude ,
14661484 filesAutoSaveAfterDelay : otherSettings . filesAutoSaveAfterDelay ,
1467- filesEncoding : otherSettings . filesEncoding ,
1485+ filesEncoding : filesEncoding ,
1486+ filesEncodingChanged : filesEncodingChanged ,
14681487 searchExclude : otherSettings . searchExclude ,
14691488 editorAutoClosingBrackets : otherSettings . editorAutoClosingBrackets ,
14701489 editorInlayHintsEnabled : otherSettings . editorInlayHintsEnabled ,
@@ -1480,10 +1499,10 @@ export class DefaultClient implements Client {
14801499 const workspaceFolderSettingsParams : WorkspaceFolderSettingsParams [ ] = [ ] ;
14811500 if ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ) {
14821501 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 ) ) ) ;
14841503 }
14851504 } else {
1486- workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( this . RootUri , workspaceSettings , workspaceOtherSettings ) ) ;
1505+ workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( this . RootUri , undefined , workspaceSettings , workspaceOtherSettings ) ) ;
14871506 }
14881507 return workspaceFolderSettingsParams ;
14891508 }
@@ -1498,9 +1517,13 @@ export class DefaultClient implements Client {
14981517 if ( this . currentCopilotHoverEnabled && workspaceSettings . copilotHover !== this . currentCopilotHoverEnabled . Value ) {
14991518 void util . promptForReloadWindowDueToSettingsChange ( ) ;
15001519 }
1520+ const workspaceFallbackEncoding : string = workspaceOtherSettings . filesEncoding ;
1521+ const lastWorkspaceFallbackEncoding : PersistentState < string > = new PersistentState < string > ( "CPP.lastWorkspaceFallbackEncoding" , "" ) ;
1522+ const workspaceFallbackEncodingChanged = lastWorkspaceFallbackEncoding . Value !== workspaceFallbackEncoding ;
15011523 return {
15021524 filesAssociations : workspaceOtherSettings . filesAssociations ,
1503- workspaceFallbackEncoding : workspaceOtherSettings . filesEncoding ,
1525+ workspaceFallbackEncoding : workspaceFallbackEncoding ,
1526+ workspaceFallbackEncodingChanged : workspaceFallbackEncodingChanged ,
15041527 maxConcurrentThreads : workspaceSettings . maxConcurrentThreads ,
15051528 maxCachedProcesses : workspaceSettings . maxCachedProcesses ,
15061529 maxMemory : workspaceSettings . maxMemory ,
@@ -2438,6 +2461,7 @@ export class DefaultClient implements Client {
24382461 this . languageClient . onNotification ( ReportCodeAnalysisTotalNotification , ( e ) => this . updateCodeAnalysisTotal ( e ) ) ;
24392462 this . languageClient . onNotification ( DoxygenCommentGeneratedNotification , ( e ) => void this . insertDoxygenComment ( e ) ) ;
24402463 this . languageClient . onNotification ( CanceledReferencesNotification , this . serverCanceledReferences ) ;
2464+ this . languageClient . onNotification ( FilesEncodingChangedNotification , ( e ) => this . filesEncodingChanged ( e ) ) ;
24412465 }
24422466
24432467 private handleIntelliSenseResult ( intelliSenseResult : IntelliSenseResult ) : void {
@@ -4085,6 +4109,20 @@ export class DefaultClient implements Client {
40854109 public getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined {
40864110 return this . copilotHoverProvider ;
40874111 }
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+ }
40884126}
40894127
40904128function getLanguageServerFileName ( ) : string {
@@ -4200,4 +4238,5 @@ class NullClient implements Client {
42004238 getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
42014239 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
42024240 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4241+ filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
42034242}
0 commit comments