Skip to content

Commit 1c9e275

Browse files
authored
Merge branch 'main' into dependabot/npm_and_yarn/Extension/nanoid-3.3.8
2 parents ee2db63 + 84b92dc commit 1c9e275

File tree

4 files changed

+66
-18
lines changed

4 files changed

+66
-18
lines changed

Extension/src/LanguageServer/client.ts

Lines changed: 50 additions & 10 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';
@@ -527,6 +527,7 @@ interface DidChangeActiveEditorParams {
527527
}
528528

529529
interface 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
568579
const PreInitializationRequest: RequestType<void, string, void> = new RequestType<void, string, void>('cpptools/preinitialize');
569580
const InitializationRequest: RequestType<CppInitializationParams, void, void> = new RequestType<CppInitializationParams, void, void>('cpptools/initialize');
@@ -642,6 +653,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType<number> = new Notifi
642653
const DoxygenCommentGeneratedNotification: NotificationType<GenerateDoxygenCommentResult> = new NotificationType<GenerateDoxygenCommentResult>('cpptools/insertDoxygenComment');
643654
const CanceledReferencesNotification: NotificationType<void> = new NotificationType<void>('cpptools/canceledReferences');
644655
const IntelliSenseResultNotification: NotificationType<IntelliSenseResult> = new NotificationType<IntelliSenseResult>('cpptools/intelliSenseResult');
656+
const FilesEncodingChangedNotification: NotificationType<FilesEncodingChanged> = new NotificationType<FilesEncodingChanged>('cpptools/filesEncodingChanged');
645657

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

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

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

Extension/src/LanguageServer/copilotProviders.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import * as util from '../common';
1010
import * as logger from '../logger';
1111
import * as telemetry from '../telemetry';
1212
import { GetIncludesResult } from './client';
13-
import { getActiveClient } from './extension';
13+
import { getClients } from './extension';
1414
import { getCompilerArgumentFilterMap, getProjectContext } from './lmTool';
1515

1616
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
@@ -46,7 +46,7 @@ export async function registerRelatedFilesProvider(): Promise<void> {
4646
const telemetryProperties: Record<string, string> = {};
4747
const telemetryMetrics: Record<string, number> = {};
4848
try {
49-
const getIncludesHandler = async () => (await getIncludes(1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [];
49+
const getIncludesHandler = async () => (await getIncludes(uri, 1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? [];
5050
const getTraitsHandler = async () => {
5151
const projectContext = await getProjectContext(uri, context);
5252

@@ -157,10 +157,10 @@ export async function registerRelatedFilesProvider(): Promise<void> {
157157
}
158158
}
159159

160-
async function getIncludes(maxDepth: number): Promise<GetIncludesResult> {
161-
const activeClient = getActiveClient();
162-
const includes = await activeClient.getIncludes(maxDepth);
163-
const wksFolder = activeClient.RootUri?.toString();
160+
async function getIncludes(uri: vscode.Uri, maxDepth: number): Promise<GetIncludesResult> {
161+
const client = getClients().getClientFor(uri);
162+
const includes = await client.getIncludes(uri, maxDepth);
163+
const wksFolder = client.RootUri?.toString();
164164

165165
if (!wksFolder) {
166166
return includes;

Extension/src/LanguageServer/references.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as telemetry from '../telemetry';
1313
import { DefaultClient } from './client';
1414
import { PersistentState } from './persistentState';
1515
import { FindAllRefsView } from './referencesView';
16+
import { CppSettings } from './settings';
1617

1718
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })();
1819
const localize: nls.LocalizeFunc = nls.loadMessageBundle();
@@ -469,19 +470,24 @@ export class ReferencesManager {
469470
}
470471

471472
if (this.referencesStartedWhileTagParsing) {
473+
const showLog: boolean = util.getNumericLoggingLevel(new CppSettings().loggingLevel) >= 3;
472474
const msg: string = localize("some.references.may.be.missing", "[Warning] Some references may be missing, because workspace parsing was incomplete when {0} was started.",
473475
referencesCommandModeToString(this.client.ReferencesCommandMode));
474476
if (this.client.ReferencesCommandMode === ReferencesCommandMode.Peek) {
475477
if (this.referencesChannel) {
476478
this.referencesChannel.appendLine(msg);
477479
this.referencesChannel.appendLine("");
478-
this.referencesChannel.show(true);
480+
if (showLog) {
481+
this.referencesChannel.show(true);
482+
}
479483
}
480484
} else if (this.client.ReferencesCommandMode === ReferencesCommandMode.Find) {
481485
const logChannel: vscode.OutputChannel = logger.getOutputChannel();
482486
logChannel.appendLine(msg);
483487
logChannel.appendLine("");
484-
logChannel.show(true);
488+
if (showLog) {
489+
logChannel.show(true);
490+
}
485491
}
486492
}
487493

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)