@@ -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' ;
@@ -527,6 +527,7 @@ interface DidChangeActiveEditorParams {
527527}
528528
529529interface GetIncludesParams {
530+ fileUri : string ;
530531 maxDepth : number ;
531532}
532533
@@ -564,6 +565,16 @@ export interface ProjectContextResult {
564565 fileContext : FileContextResult ;
565566}
566567
568+ interface FolderFilesEncodingChanged {
569+ uri : string ;
570+ filesEncoding : string ;
571+ }
572+
573+ interface FilesEncodingChanged {
574+ workspaceFallbackEncoding ?: string ;
575+ foldersFilesEncoding : FolderFilesEncodingChanged [ ] ;
576+ }
577+
567578// Requests
568579const PreInitializationRequest : RequestType < void , string , void > = new RequestType < void , string , void > ( 'cpptools/preinitialize' ) ;
569580const InitializationRequest : RequestType < CppInitializationParams , void , void > = new RequestType < CppInitializationParams , void , void > ( 'cpptools/initialize' ) ;
@@ -642,6 +653,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType<number> = new Notifi
642653const DoxygenCommentGeneratedNotification : NotificationType < GenerateDoxygenCommentResult > = new NotificationType < GenerateDoxygenCommentResult > ( 'cpptools/insertDoxygenComment' ) ;
643654const CanceledReferencesNotification : NotificationType < void > = new NotificationType < void > ( 'cpptools/canceledReferences' ) ;
644655const IntelliSenseResultNotification : NotificationType < IntelliSenseResult > = new NotificationType < IntelliSenseResult > ( 'cpptools/intelliSenseResult' ) ;
656+ const FilesEncodingChangedNotification : NotificationType < FilesEncodingChanged > = new NotificationType < FilesEncodingChanged > ( 'cpptools/filesEncodingChanged' ) ;
645657
646658let failureMessageShown : boolean = false ;
647659
@@ -816,9 +828,10 @@ export interface Client {
816828 setShowConfigureIntelliSenseButton ( show : boolean ) : void ;
817829 addTrustedCompiler ( path : string ) : Promise < void > ;
818830 getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined ;
819- getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > ;
831+ getIncludes ( uri : vscode . Uri , maxDepth : number ) : Promise < GetIncludesResult > ;
820832 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > ;
821833 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > ;
834+ filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void ;
822835}
823836
824837export function createClient ( workspaceFolder ?: vscode . WorkspaceFolder ) : Client {
@@ -1367,7 +1380,13 @@ export class DefaultClient implements Client {
13671380 DefaultClient . isStarted . resolve ( ) ;
13681381 }
13691382
1370- private getWorkspaceFolderSettings ( workspaceFolderUri : vscode . Uri | undefined , settings : CppSettings , otherSettings : OtherSettings ) : WorkspaceFolderSettingsParams {
1383+ private getWorkspaceFolderSettings ( workspaceFolderUri : vscode . Uri | undefined , workspaceFolder : vscode . WorkspaceFolder | undefined , settings : CppSettings , otherSettings : OtherSettings ) : WorkspaceFolderSettingsParams {
1384+ const filesEncoding : string = otherSettings . filesEncoding ;
1385+ let filesEncodingChanged : boolean = false ;
1386+ if ( workspaceFolder ) {
1387+ const lastFilesEncoding : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastFilesEncoding" , "" , workspaceFolder ) ;
1388+ filesEncodingChanged = lastFilesEncoding . Value !== filesEncoding ;
1389+ }
13711390 const result : WorkspaceFolderSettingsParams = {
13721391 uri : workspaceFolderUri ?. toString ( ) ,
13731392 intelliSenseEngine : settings . intelliSenseEngine ,
@@ -1464,7 +1483,8 @@ export class DefaultClient implements Client {
14641483 doxygenSectionTags : settings . doxygenSectionTags ,
14651484 filesExclude : otherSettings . filesExclude ,
14661485 filesAutoSaveAfterDelay : otherSettings . filesAutoSaveAfterDelay ,
1467- filesEncoding : otherSettings . filesEncoding ,
1486+ filesEncoding : filesEncoding ,
1487+ filesEncodingChanged : filesEncodingChanged ,
14681488 searchExclude : otherSettings . searchExclude ,
14691489 editorAutoClosingBrackets : otherSettings . editorAutoClosingBrackets ,
14701490 editorInlayHintsEnabled : otherSettings . editorInlayHintsEnabled ,
@@ -1480,10 +1500,10 @@ export class DefaultClient implements Client {
14801500 const workspaceFolderSettingsParams : WorkspaceFolderSettingsParams [ ] = [ ] ;
14811501 if ( vscode . workspace . workspaceFolders && vscode . workspace . workspaceFolders . length > 0 ) {
14821502 for ( const workspaceFolder of vscode . workspace . workspaceFolders ) {
1483- workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( workspaceFolder . uri , new CppSettings ( workspaceFolder . uri ) , new OtherSettings ( workspaceFolder . uri ) ) ) ;
1503+ workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( workspaceFolder . uri , workspaceFolder , new CppSettings ( workspaceFolder . uri ) , new OtherSettings ( workspaceFolder . uri ) ) ) ;
14841504 }
14851505 } else {
1486- workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( this . RootUri , workspaceSettings , workspaceOtherSettings ) ) ;
1506+ workspaceFolderSettingsParams . push ( this . getWorkspaceFolderSettings ( this . RootUri , undefined , workspaceSettings , workspaceOtherSettings ) ) ;
14871507 }
14881508 return workspaceFolderSettingsParams ;
14891509 }
@@ -1498,9 +1518,13 @@ export class DefaultClient implements Client {
14981518 if ( this . currentCopilotHoverEnabled && workspaceSettings . copilotHover !== this . currentCopilotHoverEnabled . Value ) {
14991519 void util . promptForReloadWindowDueToSettingsChange ( ) ;
15001520 }
1521+ const workspaceFallbackEncoding : string = workspaceOtherSettings . filesEncoding ;
1522+ const lastWorkspaceFallbackEncoding : PersistentState < string > = new PersistentState < string > ( "CPP.lastWorkspaceFallbackEncoding" , "" ) ;
1523+ const workspaceFallbackEncodingChanged = lastWorkspaceFallbackEncoding . Value !== workspaceFallbackEncoding ;
15011524 return {
15021525 filesAssociations : workspaceOtherSettings . filesAssociations ,
1503- workspaceFallbackEncoding : workspaceOtherSettings . filesEncoding ,
1526+ workspaceFallbackEncoding : workspaceFallbackEncoding ,
1527+ workspaceFallbackEncodingChanged : workspaceFallbackEncodingChanged ,
15041528 maxConcurrentThreads : workspaceSettings . maxConcurrentThreads ,
15051529 maxCachedProcesses : workspaceSettings . maxCachedProcesses ,
15061530 maxMemory : workspaceSettings . maxMemory ,
@@ -2268,8 +2292,8 @@ export class DefaultClient implements Client {
22682292 * the UI results and always re-requests (no caching).
22692293 */
22702294
2271- public async getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > {
2272- const params : GetIncludesParams = { maxDepth : maxDepth } ;
2295+ public async getIncludes ( uri : vscode . Uri , maxDepth : number ) : Promise < GetIncludesResult > {
2296+ const params : GetIncludesParams = { fileUri : uri . toString ( ) , maxDepth } ;
22732297 await this . ready ;
22742298 return this . languageClient . sendRequest ( IncludesRequest , params ) ;
22752299 }
@@ -2438,6 +2462,7 @@ export class DefaultClient implements Client {
24382462 this . languageClient . onNotification ( ReportCodeAnalysisTotalNotification , ( e ) => this . updateCodeAnalysisTotal ( e ) ) ;
24392463 this . languageClient . onNotification ( DoxygenCommentGeneratedNotification , ( e ) => void this . insertDoxygenComment ( e ) ) ;
24402464 this . languageClient . onNotification ( CanceledReferencesNotification , this . serverCanceledReferences ) ;
2465+ this . languageClient . onNotification ( FilesEncodingChangedNotification , ( e ) => this . filesEncodingChanged ( e ) ) ;
24412466 }
24422467
24432468 private handleIntelliSenseResult ( intelliSenseResult : IntelliSenseResult ) : void {
@@ -4085,6 +4110,20 @@ export class DefaultClient implements Client {
40854110 public getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined {
40864111 return this . copilotHoverProvider ;
40874112 }
4113+
4114+ public filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void {
4115+ if ( filesEncodingChanged . workspaceFallbackEncoding !== undefined ) {
4116+ const lastWorkspaceFallbackEncoding : PersistentState < string > = new PersistentState < string > ( "CPP.lastWorkspaceFallbackEncoding" , "" ) ;
4117+ lastWorkspaceFallbackEncoding . Value = filesEncodingChanged . workspaceFallbackEncoding ;
4118+ }
4119+ for ( const folderFilesEncoding of filesEncodingChanged . foldersFilesEncoding ) {
4120+ const workspaceFolder : vscode . WorkspaceFolder | undefined = vscode . workspace . getWorkspaceFolder ( vscode . Uri . parse ( folderFilesEncoding . uri ) ) ;
4121+ if ( workspaceFolder !== undefined ) {
4122+ const lastFilesEncoding : PersistentFolderState < string > = new PersistentFolderState < string > ( "CPP.lastFilesEncoding" , "" , workspaceFolder ) ;
4123+ lastFilesEncoding . Value = folderFilesEncoding . filesEncoding ;
4124+ }
4125+ }
4126+ }
40884127}
40894128
40904129function getLanguageServerFileName ( ) : string {
@@ -4197,7 +4236,8 @@ class NullClient implements Client {
41974236 setShowConfigureIntelliSenseButton ( show : boolean ) : void { }
41984237 addTrustedCompiler ( path : string ) : Promise < void > { return Promise . resolve ( ) ; }
41994238 getCopilotHoverProvider ( ) : CopilotHoverProvider | undefined { return undefined ; }
4200- getIncludes ( maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
4239+ getIncludes ( uri : vscode . Uri , maxDepth : number ) : Promise < GetIncludesResult > { return Promise . resolve ( { } as GetIncludesResult ) ; }
42014240 getChatContext ( uri : vscode . Uri , token : vscode . CancellationToken ) : Promise < ChatContextResult > { return Promise . resolve ( { } as ChatContextResult ) ; }
42024241 getProjectContext ( uri : vscode . Uri ) : Promise < ProjectContextResult > { return Promise . resolve ( { } as ProjectContextResult ) ; }
4242+ filesEncodingChanged ( filesEncodingChanged : FilesEncodingChanged ) : void { }
42034243}
0 commit comments