Skip to content

Commit

Permalink
Merge branch 'main' into handle-multiple-compile-commands
Browse files Browse the repository at this point in the history
  • Loading branch information
yiftahw authored Dec 18, 2024
2 parents 82d5c0b + afb208d commit c7a9c05
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Extension/i18n/chs/package.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "指针和引用运算符左对齐。",
Expand Down Expand Up @@ -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++ 文件的配置,例如语言标准版本和目标平台。"
}
}
7 changes: 6 additions & 1 deletion Extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
60 changes: 50 additions & 10 deletions Extension/src/LanguageServer/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -527,6 +527,7 @@ interface DidChangeActiveEditorParams {
}

interface GetIncludesParams {
fileUri: string;
maxDepth: number;
}

Expand Down Expand Up @@ -564,6 +565,16 @@ export interface ProjectContextResult {
fileContext: FileContextResult;
}

interface FolderFilesEncodingChanged {
uri: string;
filesEncoding: string;
}

interface FilesEncodingChanged {
workspaceFallbackEncoding?: string;
foldersFilesEncoding: FolderFilesEncodingChanged[];
}

// Requests
const PreInitializationRequest: RequestType<void, string, void> = new RequestType<void, string, void>('cpptools/preinitialize');
const InitializationRequest: RequestType<CppInitializationParams, void, void> = new RequestType<CppInitializationParams, void, void>('cpptools/initialize');
Expand Down Expand Up @@ -642,6 +653,7 @@ const ReportCodeAnalysisTotalNotification: NotificationType<number> = new Notifi
const DoxygenCommentGeneratedNotification: NotificationType<GenerateDoxygenCommentResult> = new NotificationType<GenerateDoxygenCommentResult>('cpptools/insertDoxygenComment');
const CanceledReferencesNotification: NotificationType<void> = new NotificationType<void>('cpptools/canceledReferences');
const IntelliSenseResultNotification: NotificationType<IntelliSenseResult> = new NotificationType<IntelliSenseResult>('cpptools/intelliSenseResult');
const FilesEncodingChangedNotification: NotificationType<FilesEncodingChanged> = new NotificationType<FilesEncodingChanged>('cpptools/filesEncodingChanged');

let failureMessageShown: boolean = false;

Expand Down Expand Up @@ -816,9 +828,10 @@ export interface Client {
setShowConfigureIntelliSenseButton(show: boolean): void;
addTrustedCompiler(path: string): Promise<void>;
getCopilotHoverProvider(): CopilotHoverProvider | undefined;
getIncludes(maxDepth: number): Promise<GetIncludesResult>;
getIncludes(uri: vscode.Uri, maxDepth: number): Promise<GetIncludesResult>;
getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise<ChatContextResult>;
getProjectContext(uri: vscode.Uri): Promise<ProjectContextResult>;
filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void;
}

export function createClient(workspaceFolder?: vscode.WorkspaceFolder): Client {
Expand Down Expand Up @@ -1367,7 +1380,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<string> = new PersistentFolderState<string>("CPP.lastFilesEncoding", "", workspaceFolder);
filesEncodingChanged = lastFilesEncoding.Value !== filesEncoding;
}
const result: WorkspaceFolderSettingsParams = {
uri: workspaceFolderUri?.toString(),
intelliSenseEngine: settings.intelliSenseEngine,
Expand Down Expand Up @@ -1464,7 +1483,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,
Expand All @@ -1480,10 +1500,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;
}
Expand All @@ -1498,9 +1518,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<string> = new PersistentState<string>("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,
Expand Down Expand Up @@ -2268,8 +2292,8 @@ export class DefaultClient implements Client {
* the UI results and always re-requests (no caching).
*/

public async getIncludes(maxDepth: number): Promise<GetIncludesResult> {
const params: GetIncludesParams = { maxDepth: maxDepth };
public async getIncludes(uri: vscode.Uri, maxDepth: number): Promise<GetIncludesResult> {
const params: GetIncludesParams = { fileUri: uri.toString(), maxDepth };
await this.ready;
return this.languageClient.sendRequest(IncludesRequest, params);
}
Expand Down Expand Up @@ -2438,6 +2462,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 {
Expand Down Expand Up @@ -4085,6 +4110,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<string> = new PersistentState<string>("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<string> = new PersistentFolderState<string>("CPP.lastFilesEncoding", "", workspaceFolder);
lastFilesEncoding.Value = folderFilesEncoding.filesEncoding;
}
}
}
}

function getLanguageServerFileName(): string {
Expand Down Expand Up @@ -4197,7 +4236,8 @@ class NullClient implements Client {
setShowConfigureIntelliSenseButton(show: boolean): void { }
addTrustedCompiler(path: string): Promise<void> { return Promise.resolve(); }
getCopilotHoverProvider(): CopilotHoverProvider | undefined { return undefined; }
getIncludes(maxDepth: number): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
getIncludes(uri: vscode.Uri, maxDepth: number): Promise<GetIncludesResult> { return Promise.resolve({} as GetIncludesResult); }
getChatContext(uri: vscode.Uri, token: vscode.CancellationToken): Promise<ChatContextResult> { return Promise.resolve({} as ChatContextResult); }
getProjectContext(uri: vscode.Uri): Promise<ProjectContextResult> { return Promise.resolve({} as ProjectContextResult); }
filesEncodingChanged(filesEncodingChanged: FilesEncodingChanged): void { }
}
12 changes: 6 additions & 6 deletions Extension/src/LanguageServer/copilotProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 })();
Expand Down Expand Up @@ -46,7 +46,7 @@ export async function registerRelatedFilesProvider(): Promise<void> {
const telemetryProperties: Record<string, string> = {};
const telemetryMetrics: Record<string, number> = {};
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);

Expand Down Expand Up @@ -157,10 +157,10 @@ export async function registerRelatedFilesProvider(): Promise<void> {
}
}

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

if (!wksFolder) {
return includes;
Expand Down
2 changes: 2 additions & 0 deletions Extension/src/LanguageServer/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export interface WorkspaceFolderSettingsParams {
filesExclude: Excludes;
filesAutoSaveAfterDelay: boolean;
filesEncoding: string;
filesEncodingChanged: boolean;
searchExclude: Excludes;
editorAutoClosingBrackets: string;
editorInlayHintsEnabled: boolean;
Expand All @@ -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;
Expand Down

0 comments on commit c7a9c05

Please sign in to comment.