From ab7bebfd7caca28b9902e4a86eca74b03795b03c Mon Sep 17 00:00:00 2001 From: Sean McManus Date: Fri, 13 Dec 2024 17:41:18 -0800 Subject: [PATCH 1/4] Fix space around binary operator translation. (#13057) * Fix space around binary operator translation. --- Extension/i18n/chs/package.i18n.json | 4 ++-- Extension/package.nls.json | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Extension/i18n/chs/package.i18n.json b/Extension/i18n/chs/package.i18n.json index c1c7f42e82..48b573e65b 100644 --- a/Extension/i18n/chs/package.i18n.json +++ b/Extension/i18n/chs/package.i18n.json @@ -160,7 +160,7 @@ "c_cpp.configuration.vcFormat.space.removeBeforeSemicolon.description": "将移除每个分号前的空格。", "c_cpp.configuration.vcFormat.space.insertAfterSemicolon.description": "在每个分号后面插入一个空格。", "c_cpp.configuration.vcFormat.space.removeAroundUnaryOperator.description": "移除一元运算符和操作数之间的空格。", - "c_cpp.configuration.vcFormat.space.aroundBinaryOperator.description": "二进制运算符周围的空格。", + "c_cpp.configuration.vcFormat.space.aroundBinaryOperator.description": "二元运算符周围的空格。", "c_cpp.configuration.vcFormat.space.aroundAssignmentOperator.description": "赋值运算符周围的空格。", "c_cpp.configuration.vcFormat.space.pointerReferenceAlignment.description": "指针和引用运算符周围的空格。", "c_cpp.configuration.vcFormat.space.pointerReferenceAlignment.left.description": "指针和引用运算符左对齐。", @@ -449,4 +449,4 @@ "c_cpp.configuration.refactoring.includeHeader.never.description": "从不包含头文件。", "c_cpp.languageModelTools.configuration.displayName": "C/C++ 配置", "c_cpp.languageModelTools.configuration.userDescription": "活动 C 或 C++ 文件的配置,例如语言标准版本和目标平台。" -} \ No newline at end of file +} diff --git a/Extension/package.nls.json b/Extension/package.nls.json index 92908ad506..f59f981345 100644 --- a/Extension/package.nls.json +++ b/Extension/package.nls.json @@ -410,7 +410,12 @@ "c_cpp.configuration.vcFormat.space.removeBeforeSemicolon.description": "Spaces are removed before every semicolon.", "c_cpp.configuration.vcFormat.space.insertAfterSemicolon.description": "A space is inserted after every semicolon.", "c_cpp.configuration.vcFormat.space.removeAroundUnaryOperator.description": "Spaces between unary operators and operands are removed.", - "c_cpp.configuration.vcFormat.space.aroundBinaryOperator.description": "Spaces around binary operators.", + "c_cpp.configuration.vcFormat.space.aroundBinaryOperator.description": { + "message": "Spaces around binary operators.", + "comment": [ + "The term \"binary operators\" refers to operators that takes two operands and not operators on binary numbers." + ] + }, "c_cpp.configuration.vcFormat.space.aroundAssignmentOperator.description": "Spaces around assignment operators.", "c_cpp.configuration.vcFormat.space.pointerReferenceAlignment.description": "Spaces around pointer and reference operators.", "c_cpp.configuration.vcFormat.space.pointerReferenceAlignment.left.description": "Pointer and reference operators are aligned to the left.", From d7ee24158f548b249fd3a9e0fa1897b2b238de41 Mon Sep 17 00:00:00 2001 From: Emmanuel Ferdman Date: Sat, 14 Dec 2024 04:25:29 +0200 Subject: [PATCH 2/4] Update `extension.test.ts` reference (#13040) --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 92d7a69446..8acc52bac2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ * [Build and debug the extension](Documentation/Building%20the%20Extension.md). * File an [issue](https://github.com/Microsoft/vscode-cpptools/issues) and a [pull request](https://github.com/Microsoft/vscode-cpptools/pulls) with the change and we will review it. * If the change affects functionality, add a line describing the change to [**CHANGELOG.md**](Extension/CHANGELOG.md). -* Try and add a test in [**test/extension.test.ts**](Extension/test/unitTests/extension.test.ts). +* Try and add a test in [**test/extension.test.ts**](Extension/test/scenarios/SingleRootProject/tests/extension.test.ts). * Run tests via opening the [**Extension**](https://github.com/Microsoft/vscode-cpptools/tree/main/Extension) folder in Visual Studio Code, selecting the "Launch Tests" configuration in the Debug pane, and choosing "Start Debugging". ## About the Code From fbf81359df67eb3d88607a779e3d087399e2a5b6 Mon Sep 17 00:00:00 2001 From: Colen Garoutte-Carson <49173979+Colengms@users.noreply.github.com> Date: Mon, 16 Dec 2024 14:46:09 -0800 Subject: [PATCH 3/4] Trigger reparsing when `files.encoding` setting changes (#13047) --- Extension/src/LanguageServer/client.ts | 51 +++++++++++++++++++++--- Extension/src/LanguageServer/settings.ts | 2 + 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index 8ee0e22f6a..d1f0cb8c90 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -58,7 +58,7 @@ import { DataBinding } from './dataBinding'; import { cachedEditorConfigSettings, getEditorConfigSettings } from './editorConfig'; import { CppSourceStr, clients, configPrefix, updateLanguageConfigurations, usesCrashHandler, watchForCrashes } from './extension'; import { LocalizeStringParams, getLocaleId, getLocalizedString } from './localization'; -import { PersistentFolderState, PersistentWorkspaceState } from './persistentState'; +import { PersistentFolderState, PersistentState, PersistentWorkspaceState } from './persistentState'; import { RequestCancelled, ServerCancelled, createProtocolFilter } from './protocolFilter'; import * as refs from './references'; import { CppSettings, OtherSettings, SettingsParams, WorkspaceFolderSettingsParams } from './settings'; @@ -564,6 +564,16 @@ export interface ProjectContextResult { fileContext: FileContextResult; } +interface FolderFilesEncodingChanged { + uri: string; + filesEncoding: string; +} + +interface FilesEncodingChanged { + workspaceFallbackEncoding?: string; + foldersFilesEncoding: FolderFilesEncodingChanged[]; +} + // Requests const PreInitializationRequest: RequestType = new RequestType('cpptools/preinitialize'); const InitializationRequest: RequestType = new RequestType('cpptools/initialize'); @@ -642,6 +652,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType = new Notifi const DoxygenCommentGeneratedNotification: NotificationType = new NotificationType('cpptools/insertDoxygenComment'); const CanceledReferencesNotification: NotificationType = new NotificationType('cpptools/canceledReferences'); const IntelliSenseResultNotification: NotificationType = new NotificationType('cpptools/intelliSenseResult'); +const FilesEncodingChangedNotification: NotificationType = new NotificationType('cpptools/filesEncodingChanged'); let failureMessageShown: boolean = false; @@ -819,6 +830,7 @@ export interface Client { getIncludes(maxDepth: number): Promise; getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise; getProjectContext(uri: vscode.Uri): Promise; + filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void; } export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client { @@ -1367,7 +1379,13 @@ export class DefaultClient implements Client { DefaultClient.isStarted.resolve(); } - private getWorkspaceFolderSettings(workspaceFolderUri: vscode.Uri | undefined, settings: CppSettings, otherSettings: OtherSettings): WorkspaceFolderSettingsParams { + private getWorkspaceFolderSettings(workspaceFolderUri: vscode.Uri | undefined, workspaceFolder: vscode.WorkspaceFolder | undefined, settings: CppSettings, otherSettings: OtherSettings): WorkspaceFolderSettingsParams { + const filesEncoding: string = otherSettings.filesEncoding; + let filesEncodingChanged: boolean = false; + if (workspaceFolder) { + const lastFilesEncoding: PersistentFolderState = new PersistentFolderState("CPP.lastFilesEncoding", "", workspaceFolder); + filesEncodingChanged = lastFilesEncoding.Value !== filesEncoding; + } const result: WorkspaceFolderSettingsParams = { uri: workspaceFolderUri?.toString(), intelliSenseEngine: settings.intelliSenseEngine, @@ -1464,7 +1482,8 @@ export class DefaultClient implements Client { doxygenSectionTags: settings.doxygenSectionTags, filesExclude: otherSettings.filesExclude, filesAutoSaveAfterDelay: otherSettings.filesAutoSaveAfterDelay, - filesEncoding: otherSettings.filesEncoding, + filesEncoding: filesEncoding, + filesEncodingChanged: filesEncodingChanged, searchExclude: otherSettings.searchExclude, editorAutoClosingBrackets: otherSettings.editorAutoClosingBrackets, editorInlayHintsEnabled: otherSettings.editorInlayHintsEnabled, @@ -1480,10 +1499,10 @@ export class DefaultClient implements Client { const workspaceFolderSettingsParams: WorkspaceFolderSettingsParams[] = []; if (vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0) { for (const workspaceFolder of vscode.workspace.workspaceFolders) { - workspaceFolderSettingsParams.push(this.getWorkspaceFolderSettings(workspaceFolder.uri, new CppSettings(workspaceFolder.uri), new OtherSettings(workspaceFolder.uri))); + workspaceFolderSettingsParams.push(this.getWorkspaceFolderSettings(workspaceFolder.uri, workspaceFolder, new CppSettings(workspaceFolder.uri), new OtherSettings(workspaceFolder.uri))); } } else { - workspaceFolderSettingsParams.push(this.getWorkspaceFolderSettings(this.RootUri, workspaceSettings, workspaceOtherSettings)); + workspaceFolderSettingsParams.push(this.getWorkspaceFolderSettings(this.RootUri, undefined, workspaceSettings, workspaceOtherSettings)); } return workspaceFolderSettingsParams; } @@ -1498,9 +1517,13 @@ export class DefaultClient implements Client { if (this.currentCopilotHoverEnabled && workspaceSettings.copilotHover !== this.currentCopilotHoverEnabled.Value) { void util.promptForReloadWindowDueToSettingsChange(); } + const workspaceFallbackEncoding: string = workspaceOtherSettings.filesEncoding; + const lastWorkspaceFallbackEncoding: PersistentState = new PersistentState("CPP.lastWorkspaceFallbackEncoding", ""); + const workspaceFallbackEncodingChanged = lastWorkspaceFallbackEncoding.Value !== workspaceFallbackEncoding; return { filesAssociations: workspaceOtherSettings.filesAssociations, - workspaceFallbackEncoding: workspaceOtherSettings.filesEncoding, + workspaceFallbackEncoding: workspaceFallbackEncoding, + workspaceFallbackEncodingChanged: workspaceFallbackEncodingChanged, maxConcurrentThreads: workspaceSettings.maxConcurrentThreads, maxCachedProcesses: workspaceSettings.maxCachedProcesses, maxMemory: workspaceSettings.maxMemory, @@ -2438,6 +2461,7 @@ export class DefaultClient implements Client { this.languageClient.onNotification(ReportCodeAnalysisTotalNotification, (e) => this.updateCodeAnalysisTotal(e)); this.languageClient.onNotification(DoxygenCommentGeneratedNotification, (e) => void this.insertDoxygenComment(e)); this.languageClient.onNotification(CanceledReferencesNotification, this.serverCanceledReferences); + this.languageClient.onNotification(FilesEncodingChangedNotification, (e) => this.filesEncodingChanged(e)); } private handleIntelliSenseResult(intelliSenseResult: IntelliSenseResult): void { @@ -4085,6 +4109,20 @@ export class DefaultClient implements Client { public getCopilotHoverProvider(): CopilotHoverProvider | undefined { return this.copilotHoverProvider; } + + public filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void { + if (filesEncodingChanged.workspaceFallbackEncoding !== undefined) { + const lastWorkspaceFallbackEncoding: PersistentState = new PersistentState("CPP.lastWorkspaceFallbackEncoding", ""); + lastWorkspaceFallbackEncoding.Value = filesEncodingChanged.workspaceFallbackEncoding; + } + for (const folderFilesEncoding of filesEncodingChanged.foldersFilesEncoding) { + const workspaceFolder: vscode.WorkspaceFolder | undefined = vscode.workspace.getWorkspaceFolder(vscode.Uri.parse(folderFilesEncoding.uri)); + if (workspaceFolder !== undefined) { + const lastFilesEncoding: PersistentFolderState = new PersistentFolderState("CPP.lastFilesEncoding", "", workspaceFolder); + lastFilesEncoding.Value = folderFilesEncoding.filesEncoding; + } + } + } } function getLanguageServerFileName(): string { @@ -4200,4 +4238,5 @@ class NullClient implements Client { getIncludes(maxDepth: number): Promise { return Promise.resolve({} as GetIncludesResult); } getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise { return Promise.resolve({} as ChatContextResult); } getProjectContext(uri: vscode.Uri): Promise { return Promise.resolve({} as ProjectContextResult); } + filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void { } } diff --git a/Extension/src/LanguageServer/settings.ts b/Extension/src/LanguageServer/settings.ts index a33a4b8030..fb96b2afab 100644 --- a/Extension/src/LanguageServer/settings.ts +++ b/Extension/src/LanguageServer/settings.ts @@ -131,6 +131,7 @@ export interface WorkspaceFolderSettingsParams { filesExclude: Excludes; filesAutoSaveAfterDelay: boolean; filesEncoding: string; + filesEncodingChanged: boolean; searchExclude: Excludes; editorAutoClosingBrackets: string; editorInlayHintsEnabled: boolean; @@ -141,6 +142,7 @@ export interface WorkspaceFolderSettingsParams { export interface SettingsParams { filesAssociations: Associations; workspaceFallbackEncoding: string; + workspaceFallbackEncodingChanged: boolean; maxConcurrentThreads: number | null; maxCachedProcesses: number | null; maxMemory: number | null; From afb208dabbe747706b1c9b95b9f21a0aa39f5f00 Mon Sep 17 00:00:00 2001 From: Luca <681992+lukka@users.noreply.github.com> Date: Tue, 17 Dec 2024 14:30:51 -0800 Subject: [PATCH 4/4] get isense client by uri (#13059) --- Extension/src/LanguageServer/client.ts | 9 +++++---- Extension/src/LanguageServer/copilotProviders.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Extension/src/LanguageServer/client.ts b/Extension/src/LanguageServer/client.ts index d1f0cb8c90..47e5d28219 100644 --- a/Extension/src/LanguageServer/client.ts +++ b/Extension/src/LanguageServer/client.ts @@ -527,6 +527,7 @@ interface DidChangeActiveEditorParams { } interface GetIncludesParams { + fileUri: string; maxDepth: number; } @@ -827,7 +828,7 @@ export interface Client { setShowConfigureIntelliSenseButton(show: boolean): void; addTrustedCompiler(path: string): Promise; getCopilotHoverProvider(): CopilotHoverProvider | undefined; - getIncludes(maxDepth: number): Promise; + getIncludes(uri: vscode.Uri, maxDepth: number): Promise; getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise; getProjectContext(uri: vscode.Uri): Promise; filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void; @@ -2291,8 +2292,8 @@ export class DefaultClient implements Client { * the UI results and always re-requests (no caching). */ - public async getIncludes(maxDepth: number): Promise { - const params: GetIncludesParams = { maxDepth: maxDepth }; + public async getIncludes(uri: vscode.Uri, maxDepth: number): Promise { + const params: GetIncludesParams = { fileUri: uri.toString(), maxDepth }; await this.ready; return this.languageClient.sendRequest(IncludesRequest, params); } @@ -4235,7 +4236,7 @@ class NullClient implements Client { setShowConfigureIntelliSenseButton(show: boolean): void { } addTrustedCompiler(path: string): Promise { return Promise.resolve(); } getCopilotHoverProvider(): CopilotHoverProvider | undefined { return undefined; } - getIncludes(maxDepth: number): Promise { return Promise.resolve({} as GetIncludesResult); } + getIncludes(uri: vscode.Uri, maxDepth: number): Promise { return Promise.resolve({} as GetIncludesResult); } getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise { return Promise.resolve({} as ChatContextResult); } getProjectContext(uri: vscode.Uri): Promise { return Promise.resolve({} as ProjectContextResult); } filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void { } diff --git a/Extension/src/LanguageServer/copilotProviders.ts b/Extension/src/LanguageServer/copilotProviders.ts index a78fdfa5b6..ce232865fa 100644 --- a/Extension/src/LanguageServer/copilotProviders.ts +++ b/Extension/src/LanguageServer/copilotProviders.ts @@ -10,7 +10,7 @@ import * as util from '../common'; import * as logger from '../logger'; import * as telemetry from '../telemetry'; import { GetIncludesResult } from './client'; -import { getActiveClient } from './extension'; +import { getClients } from './extension'; import { getCompilerArgumentFilterMap, getProjectContext } from './lmTool'; nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); @@ -46,7 +46,7 @@ export async function registerRelatedFilesProvider(): Promise { const telemetryProperties: Record = {}; const telemetryMetrics: Record = {}; try { - const getIncludesHandler = async () => (await getIncludes(1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? []; + const getIncludesHandler = async () => (await getIncludes(uri, 1))?.includedFiles.map(file => vscode.Uri.file(file)) ?? []; const getTraitsHandler = async () => { const projectContext = await getProjectContext(uri, context); @@ -157,10 +157,10 @@ export async function registerRelatedFilesProvider(): Promise { } } -async function getIncludes(maxDepth: number): Promise { - const activeClient = getActiveClient(); - const includes = await activeClient.getIncludes(maxDepth); - const wksFolder = activeClient.RootUri?.toString(); +async function getIncludes(uri: vscode.Uri, maxDepth: number): Promise { + const client = getClients().getClientFor(uri); + const includes = await client.getIncludes(uri, maxDepth); + const wksFolder = client.RootUri?.toString(); if (!wksFolder) { return includes;