Skip to content

Commit fbf8135

Browse files
authored
Trigger reparsing when files.encoding setting changes (#13047)
1 parent d7ee241 commit fbf8135

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ import { DataBinding } from './dataBinding';
5858
import { cachedEditorConfigSettings, getEditorConfigSettings } from './editorConfig';
5959
import { CppSourceStr, clients, configPrefix, updateLanguageConfigurations, usesCrashHandler, watchForCrashes } from './extension';
6060
import { LocalizeStringParams, getLocaleId, getLocalizedString } from './localization';
61-
import { PersistentFolderState, PersistentWorkspaceState } from './persistentState';
61+
import { PersistentFolderState, PersistentState, PersistentWorkspaceState } from './persistentState';
6262
import { RequestCancelled, ServerCancelled, createProtocolFilter } from './protocolFilter';
6363
import * as refs from './references';
6464
import { 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
568578
const PreInitializationRequest: RequestType<void, string, void> = new RequestType<void, string, void>('cpptools/preinitialize');
569579
const InitializationRequest: RequestType<CppInitializationParams, void, void> = new RequestType<CppInitializationParams, void, void>('cpptools/initialize');
@@ -642,6 +652,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType<number> = new Notifi
642652
const DoxygenCommentGeneratedNotification: NotificationType<GenerateDoxygenCommentResult> = new NotificationType<GenerateDoxygenCommentResult>('cpptools/insertDoxygenComment');
643653
const CanceledReferencesNotification: NotificationType<void> = new NotificationType<void>('cpptools/canceledReferences');
644654
const IntelliSenseResultNotification: NotificationType<IntelliSenseResult> = new NotificationType<IntelliSenseResult>('cpptools/intelliSenseResult');
655+
const FilesEncodingChangedNotification: NotificationType<FilesEncodingChanged> = new NotificationType<FilesEncodingChanged>('cpptools/filesEncodingChanged');
645656

646657
let 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

824836
export 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

40904128
function 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
}

Extension/src/LanguageServer/settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ export interface WorkspaceFolderSettingsParams {
131131
filesExclude: Excludes;
132132
filesAutoSaveAfterDelay: boolean;
133133
filesEncoding: string;
134+
filesEncodingChanged: boolean;
134135
searchExclude: Excludes;
135136
editorAutoClosingBrackets: string;
136137
editorInlayHintsEnabled: boolean;
@@ -141,6 +142,7 @@ export interface WorkspaceFolderSettingsParams {
141142
export interface SettingsParams {
142143
filesAssociations: Associations;
143144
workspaceFallbackEncoding: string;
145+
workspaceFallbackEncodingChanged: boolean;
144146
maxConcurrentThreads: number | null;
145147
maxCachedProcesses: number | null;
146148
maxMemory: number | null;

0 commit comments

Comments
 (0)