Skip to content

Commit a6b643b

Browse files
First pass at updating codebase to more consistently have function docs (#4271)
* improve documenting comments in util.ts and workflow.ts * add command comments in triple.ts * telemetry.ts comment updates * shlex.ts * schema.ts * more comment updates for function docs * missed some files
1 parent 266060f commit a6b643b

13 files changed

Lines changed: 725 additions & 71 deletions

src/coverage.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();
88

99
const log = logging.createLogger('ctest-coverage');
1010

11+
/**
12+
* Processes coverage information files and updates the provided test run with coverage data.
13+
*
14+
* @param run - The test run to update with coverage data.
15+
* @param coverageInfoFiles - An array of file paths to coverage information files.
16+
* @param coverageData - A WeakMap to store the coverage data, mapping `vscode.FileCoverage` to an array of `vscode.FileCoverageDetail`.
17+
*
18+
* This function reads each coverage information file, parses its contents, and extracts coverage data for lines, branches, and functions.
19+
* It then creates `vscode.FileCoverage` objects and populates them with the extracted data, including branch coverage and function declarations.
20+
* The coverage data is stored in the provided `coverageData` WeakMap and added to the test run.
21+
*
22+
* If a coverage information file cannot be opened, a warning is logged and the file is skipped.
23+
*/
1124
export async function handleCoverageInfoFiles(run: vscode.TestRun, coverageInfoFiles: string[], coverageData: WeakMap<vscode.FileCoverage, vscode.FileCoverageDetail[]>) {
1225
for (const coverageInfoFile of coverageInfoFiles) {
1326
let contents: Uint8Array;

src/debug/cmakeDebugger/cmakeDebuggerTelemetry.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ export enum DebugOrigin {
55
originatedFromCommand = "command"
66
}
77

8+
/**
9+
* Logs telemetry data for the CMake debugger.
10+
*
11+
* @param origin - The origin of the telemetry event.
12+
* @param debugType - The type of debugging event.
13+
*/
814
export function logCMakeDebuggerTelemetry(origin: string, debugType: string) {
915
telemetry.logEvent("cmakeDebugger", {
1016
origin,

src/debug/cmakeDebugger/debuggerConfigureDriver.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ export interface DebuggerInformation {
88
debuggerStoppedDueToPreconditions(message: string): void;
99
}
1010

11+
/**
12+
* Generates a unique pipe name for the CMake debugger.
13+
*
14+
* On Windows, the pipe name is in the format:
15+
* `\\.\pipe\cmake-debugger-pipe\{UUID}`
16+
*
17+
* On other platforms, the pipe name is in the format:
18+
* `/tmp/cmake-debugger-pipe-{UUID}`
19+
*
20+
* @returns The unique pipe name for the CMake debugger.
21+
*/
1122
export function getDebuggerPipeName(): string {
1223
if (process.platform === 'win32') {
1324
return `\\\\.\\\\pipe\\\\cmake-debugger-pipe\\\\${uuidv4()}`;

src/debug/cmakeDebugger/debuggerScriptDriver.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ const localize: nls.LocalizeFunc = nls.loadMessageBundle();
1313
const cmakeLogger = logging.createLogger('cmake');
1414
const scriptLogger = logging.createLogger('cmake-script');
1515

16+
/**
17+
* Executes a CMake script with the debugger.
18+
*
19+
* @param scriptPath - The path to the CMake script to execute.
20+
* @param scriptArgs - An array of arguments to pass to the script.
21+
* @param scriptEnv - A map of environment variables to set for the script.
22+
* @param debuggerInformation - Information required to set up the debugger.
23+
* @returns A promise that resolves when the script execution is complete.
24+
* @throws Will throw an error if the script execution fails.
25+
*/
1626
export async function executeScriptWithDebugger(scriptPath: string, scriptArgs: string[], scriptEnv: Map<string, string>, debuggerInformation: DebuggerInformation): Promise<void> {
1727
const outputConsumer: CMakeOutputConsumer = new CMakeOutputConsumer("", scriptLogger);
1828

src/debug/debugger.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ export enum ConsoleTypes {
7575
newExternalWindow = 'newExternalWindow'
7676
}
7777

78+
/**
79+
* Creates a GDB debug configuration for VSCode.
80+
*
81+
* @param debuggerPath - The path to the GDB debugger executable.
82+
* @param target - The executable target to be debugged.
83+
* @returns A promise that resolves to a VSCode debug configuration object.
84+
* @throws An error if GDB is not found in the provided path or the default search path.
85+
*/
7886
async function createGDBDebugConfiguration(debuggerPath: string, target: ExecutableTarget): Promise<VSCodeDebugConfiguration> {
7987
if (!await checkDebugger(debuggerPath)) {
8088
debuggerPath = 'gdb';
@@ -102,6 +110,14 @@ async function createGDBDebugConfiguration(debuggerPath: string, target: Executa
102110
};
103111
}
104112

113+
/**
114+
* Creates a LLDB debug configuration for VSCode.
115+
*
116+
* @param debuggerPath - The path to the LLDB debugger executable.
117+
* @param target - The executable target to be debugged.
118+
* @returns A promise that resolves to a VSCode debug configuration object.
119+
* @throws An error if the debugger is not found in the specified path.
120+
*/
105121
async function createLLDBDebugConfiguration(debuggerPath: string, target: ExecutableTarget): Promise<VSCodeDebugConfiguration> {
106122
if (!await checkDebugger(debuggerPath)) {
107123
throw new Error(localize('gdb.not.found', 'Unable to find GDB in default search path and {0}.', debuggerPath));
@@ -119,6 +135,12 @@ async function createLLDBDebugConfiguration(debuggerPath: string, target: Execut
119135
};
120136
}
121137

138+
/**
139+
* Creates a Visual Studio Code debug configuration for an MSVC (Microsoft Visual C++) executable target.
140+
*
141+
* @param target - The executable target for which to create the debug configuration.
142+
* @returns A `VSCodeDebugConfiguration` object configured for debugging the specified target.
143+
*/
122144
function createMsvcDebugConfiguration(target: ExecutableTarget): VSCodeDebugConfiguration {
123145
return {
124146
type: 'cppvsdbg',
@@ -150,6 +172,17 @@ const debuggerGenerators: DebuggerGenerators = {
150172
}
151173
};
152174

175+
/**
176+
* Searches for the compiler path in the provided CMake cache.
177+
*
178+
* This function iterates over a predefined list of programming languages
179+
* (CXX, C, CUDA) and checks if the corresponding compiler path is present
180+
* in the cache. If found, it returns the compiler path as a string.
181+
* If no compiler path is found for any of the languages, it returns null.
182+
*
183+
* @param cache - The CMake cache to search for the compiler path.
184+
* @returns The compiler path as a string if found, otherwise null.
185+
*/
153186
function searchForCompilerPathInCache(cache: CMakeCache): string | null {
154187
const languages = ['CXX', 'C', 'CUDA'];
155188
for (const lang of languages) {
@@ -162,6 +195,16 @@ function searchForCompilerPathInCache(cache: CMakeCache): string | null {
162195
return null;
163196
}
164197

198+
/**
199+
* Retrieves the debug configuration from the CMake cache for a given target and platform.
200+
* @param cache - The CMake cache containing build configuration information.
201+
* @param target - The executable target for which the debug configuration is being retrieved.
202+
* @param platform - The platform for which the debug configuration is being retrieved (e.g., 'darwin', 'win32').
203+
* @param modeOverride - Optional override for the MI mode (e.g., 'gdb', 'lldb').
204+
* @param debuggerPathOverride - Optional override for the debugger path.
205+
* @returns A promise that resolves to a VSCode debug configuration or null if no suitable configuration is found.
206+
* @throws An error if no compiler is found in the cache.
207+
*/
165208
export async function getDebugConfigurationFromCache(cache: CMakeCache, target: ExecutableTarget, platform: string, modeOverride?: MIModes, debuggerPathOverride?: string): Promise<VSCodeDebugConfiguration | null> {
166209
const entry = cache.get('CMAKE_LINKER');
167210
if (entry !== null && !modeOverride && !debuggerPathOverride) {

src/languageServices/languageServiceData.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ export class LanguageServiceData implements vscode.HoverProvider, vscode.Complet
5858
this.modules = JSON.parse(await this.getFile("modules.json", locale));
5959
}
6060

61+
/**
62+
* Provides completion suggestions based on the current word and the type of language construct.
63+
*
64+
* @param currentWord - The current word being typed by the user.
65+
* @param data - The data containing commands, modules, or variables for completion suggestions.
66+
* @param type - The type of language construct (Command, Module, or Variable).
67+
* @param beforeCurrentWord - Optional. The text before the current word, used to determine the appropriate snippet format.
68+
* @returns An array of `vscode.CompletionItem` objects representing the completion suggestions.
69+
*/
6170
private getCompletionSuggestionsHelper(currentWord: string, data: Commands | Modules | Variables, type: LanguageType, beforeCurrentWord?: string): vscode.CompletionItem[] {
6271
function moduleInsertText(module: string, beforeCurrentWord?: string): vscode.SnippetString {
6372
if (beforeCurrentWord) {

src/schema.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ import * as path from 'path';
44
import { fs } from '@cmt/pr';
55
import { thisExtensionPath } from '@cmt/util';
66

7+
/**
8+
* Loads and compiles a JSON schema from the specified file path.
9+
* @param filepath The path to the JSON schema file. Can be an absolute path or relative to the extension's root directory.
10+
* @returns A promise that resolves to a ValidateFunction, which can be used to validate JSON data against the schema.
11+
*/
712
export async function loadSchema(filepath: string): Promise<ValidateFunction> {
813
const schema_path = path.isAbsolute(filepath) ? filepath : path.join(thisExtensionPath(), filepath);
914
const schema_data = JSON.parse((await fs.readFile(schema_path)).toString());

src/shlex.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@ export interface ShlexOptions {
22
mode: 'windows' | 'posix';
33
}
44

5+
/**
6+
* Splits a string into an iterable of tokens, similar to how a shell would parse arguments.
7+
* Handles quoting and escaping according to the specified mode ('windows' or 'posix').
8+
* @param str The string to split into tokens.
9+
* @param opt Optional options for splitting. If not provided, defaults to the platform-specific mode ('windows' or 'posix').
10+
* @returns An iterable of tokens.
11+
*/
512
export function* split(str: string, opt?: ShlexOptions): Iterable<string> {
613
opt = opt || {
714
mode: process.platform === 'win32' ? 'windows' : 'posix'
@@ -70,6 +77,13 @@ export function* split(str: string, opt?: ShlexOptions): Iterable<string> {
7077
}
7178
}
7279

80+
/**
81+
* Quotes a string for safe use in a shell command.
82+
* If the string contains special characters, it will be wrapped in double quotes and any existing double quotes will be escaped.
83+
* @param str The string to quote.
84+
* @param opt Optional options for quoting. If not provided, defaults to the platform-specific mode ('windows' or 'posix').
85+
* @returns The quoted string.
86+
*/
7387
export function quote(str: string, opt?: ShlexOptions): string {
7488
opt = opt || {
7589
mode: process.platform === 'win32' ? 'windows' : 'posix'

src/telemetry.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export class ExperimentationTelemetry implements IExperimentationTelemetry {
6161
let initializationPromise: Promise<IExperimentationService> | undefined;
6262
let experimentationTelemetry: ExperimentationTelemetry | undefined;
6363

64+
/**
65+
* Activates the telemetry service for the extension.
66+
* Initializes the experimentation service and telemetry reporter.
67+
* @param extensionContext The extension context provided by VS Code.
68+
*/
6469
export function activate(extensionContext: vscode.ExtensionContext): void {
6570
try {
6671
if (extensionContext) {
@@ -76,6 +81,11 @@ export function activate(extensionContext: vscode.ExtensionContext): void {
7681
}
7782
}
7883

84+
/**
85+
* Sends telemetry data when the extension is opened.
86+
* Adds the target population to the telemetry properties and logs the event.
87+
* @param telemetryProperties The properties to include in the telemetry event.
88+
*/
7989
export function sendOpenTelemetry(telemetryProperties: Properties): void {
8090
const targetPopulation: TargetPopulation = util.getCmakeToolsTargetPopulation();
8191
switch (targetPopulation) {
@@ -94,10 +104,18 @@ export function sendOpenTelemetry(telemetryProperties: Properties): void {
94104
logEvent('open', telemetryProperties);
95105
}
96106

107+
/**
108+
* Gets the experimentation service instance.
109+
* @returns A promise that resolves to the experimentation service instance, or undefined if not initialized.
110+
*/
97111
export function getExperimentationService(): Promise<IExperimentationService | undefined> | undefined {
98112
return initializationPromise;
99113
}
100114

115+
/**
116+
* Deactivates the telemetry service for the extension.
117+
* Waits for the initialization promise to resolve and disposes of the telemetry reporter.
118+
*/
101119
export async function deactivate(): Promise<void> {
102120
if (initializationPromise) {
103121
try {
@@ -111,6 +129,12 @@ export async function deactivate(): Promise<void> {
111129
}
112130
}
113131

132+
/**
133+
* Logs a telemetry event with the specified name, properties, and measures.
134+
* @param eventName The name of the event to log.
135+
* @param properties Optional properties to include in the telemetry event.
136+
* @param measures Optional measures to include in the telemetry event.
137+
*/
114138
export function logEvent(eventName: string, properties?: Properties, measures?: Measures): void {
115139
const sendTelemetry = () => {
116140
if (experimentationTelemetry) {
@@ -131,6 +155,12 @@ export function logEvent(eventName: string, properties?: Properties, measures?:
131155

132156
const appInsightsKey: string =
133157
"0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255";
158+
159+
/**
160+
* Retrieves package information for the extension.
161+
* This includes the name, version, and Application Insights key.
162+
* @returns An object containing the package information.
163+
*/
134164
function getPackageInfo(): IPackageInfo {
135165
const packageJSON: util.PackageJSON = util.thisExtensionPackage();
136166
return {

src/triple.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ export interface TargetTriple {
77
libc: string;
88
}
99

10+
/**
11+
* Finds the target triple from a given line of text.
12+
* The target triple is a string that identifies the target architecture, vendor, and operating system.
13+
* @param line The line of text to search for the target triple.
14+
* @returns The target triple if found, or null if not found.
15+
*/
1016
export function findTargetTriple(line: string): string | null {
1117
const target_triple_re = /^Target:\s+(.*)/;
1218
const target_triple_match = target_triple_re.exec(line);
@@ -111,6 +117,12 @@ const TriplePossibleLibC: { key: string; regexp: RegExp }[] = [
111117
// otherwise system libc
112118
];
113119

120+
/**
121+
* Computes the target triple string from a TargetTriple object.
122+
* The target triple string identifies the target architecture, vendor, operating system, ABI, and libc.
123+
* @param target The TargetTriple object containing the target information.
124+
* @returns The computed target triple string.
125+
*/
114126
export function computeTargetTriple(target: TargetTriple): string {
115127
let triple = target.targetArch;
116128
if (target.vendors.length > 0) {
@@ -127,6 +139,12 @@ export function computeTargetTriple(target: TargetTriple): string {
127139
return triple;
128140
}
129141

142+
/**
143+
* Parses a target triple string into a TargetTriple object.
144+
* The target triple string identifies the target architecture, vendor, operating system, ABI, and libc.
145+
* @param triple The target triple string to parse.
146+
* @returns A TargetTriple object with the parsed information, or undefined if parsing fails.
147+
*/
130148
export function parseTargetTriple(triple: string): TargetTriple | undefined {
131149
const triples = triple.split("-");
132150
let foundArch = 'unknown';
@@ -197,6 +215,11 @@ export function parseTargetTriple(triple: string): TargetTriple | undefined {
197215
};
198216
}
199217

218+
/**
219+
* Extracts the major version from a semantic version string.
220+
* @param semver The semantic version string.
221+
* @returns The major version as a string.
222+
*/
200223
export function majorVersionSemver(semver: string): string {
201224
const major_version_re = /^(\d+)./;
202225
const major_version_match = major_version_re.exec(semver);
@@ -206,6 +229,11 @@ export function majorVersionSemver(semver: string): string {
206229
return '';
207230
}
208231

232+
/**
233+
* Extracts the minor version from a semantic version string.
234+
* @param semver The semantic version string.
235+
* @returns The minor version as a string.
236+
*/
209237
export function minorVersionSemver(semver: string): string {
210238
const minor_version_re = /^(\d+).(\d+)/;
211239
const minor_version_match = minor_version_re.exec(semver);

0 commit comments

Comments
 (0)