Skip to content

Commit

Permalink
address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbrow committed Sep 8, 2023
1 parent 3354709 commit 8198993
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
40 changes: 20 additions & 20 deletions Extension/src/LanguageServer/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let intervalTimer: NodeJS.Timer;
let codeActionProvider: vscode.Disposable;
export const intelliSenseDisabledError: string = "Do not activate the extension when IntelliSense is disabled.";

type VcpkgDatabase = { [key: string]: string[] }; // Stored as <header file entry> -> [<port name>]
type VcpkgDatabase = Record<string, string[]>; // Stored as <header file entry> -> [<port name>]
let vcpkgDbPromise: Promise<VcpkgDatabase>;
async function initVcpkgDatabase(): Promise<VcpkgDatabase> {
const database: VcpkgDatabase = {};
Expand Down Expand Up @@ -98,7 +98,7 @@ async function lookupIncludeInVcpkg(document: vscode.TextDocument, line: number)
if (!matches || !matches.length || !matches.groups) {
return [];
}
const missingHeader: string = matches.groups['includeFile'].replace(/\//g, '\\');
const missingHeader: string = matches.groups.includeFile.replace(/\//g, '\\');

let portsWithHeader: string[] | undefined;
const vcpkgDb: VcpkgDatabase = await vcpkgDbPromise;
Expand All @@ -117,20 +117,20 @@ function isMissingIncludeDiagnostic(diagnostic: vscode.Diagnostic): boolean {
}

function sendActivationTelemetry(): void {
const activateEvent: { [key: string]: string } = {};
const activateEvent: Record<string, string> = {};
// Don't log telemetry for machineId if it's a special value used by the dev host: someValue.machineid
if (vscode.env.machineId !== "someValue.machineId") {
const machineIdPersistentState: PersistentState<string | undefined> = new PersistentState<string | undefined>("CPP.machineId", undefined);
if (!machineIdPersistentState.Value) {
activateEvent["newMachineId"] = vscode.env.machineId;
activateEvent.newMachineId = vscode.env.machineId;
} else if (machineIdPersistentState.Value !== vscode.env.machineId) {
activateEvent["newMachineId"] = vscode.env.machineId;
activateEvent["oldMachineId"] = machineIdPersistentState.Value;
activateEvent.newMachineId = vscode.env.machineId;
activateEvent.oldMachineId = machineIdPersistentState.Value;
}
machineIdPersistentState.Value = vscode.env.machineId;
}
if (vscode.env.uiKind === vscode.UIKind.Web) {
activateEvent["WebUI"] = "1";
activateEvent.WebUI = "1";
}
telemetry.logLanguageServerEvent("Activate", activateEvent);
}
Expand Down Expand Up @@ -258,14 +258,14 @@ export function updateLanguageConfigurations(): void {
async function onDidChangeSettings(event: vscode.ConfigurationChangeEvent): Promise<void> {
const client: Client = clients.getDefaultClient();
if (client instanceof DefaultClient) {
const defaultClient: DefaultClient = <DefaultClient>client;
const changedDefaultClientSettings: { [key: string]: string } = await defaultClient.onDidChangeSettings(event);
const defaultClient: DefaultClient = client as DefaultClient;
const changedDefaultClientSettings: Record<string, string> = await defaultClient.onDidChangeSettings(event);
clients.forEach(client => {
if (client !== defaultClient) {
void client.onDidChangeSettings(event).catch(logAndReturn.undefined);
}
});
const newUpdateChannel: string = changedDefaultClientSettings['updateChannel'];
const newUpdateChannel: string = changedDefaultClientSettings.updateChannel;
if (newUpdateChannel || event.affectsConfiguration("extensions.autoUpdate")) {
UpdateInsidersAccess();
}
Expand Down Expand Up @@ -478,7 +478,7 @@ async function onSwitchHeaderSource(): Promise<void> {
let targetFileNameReplaced: boolean = false;
clients.forEach(client => {
if (!targetFileNameReplaced && client.RootRealPath && client.RootPath !== client.RootRealPath
&& targetFileName.indexOf(client.RootRealPath) === 0) {
&& targetFileName.startsWith(client.RootRealPath)) {
targetFileName = client.RootPath + targetFileName.substring(client.RootRealPath.length);
targetFileNameReplaced = true;
}
Expand Down Expand Up @@ -551,7 +551,7 @@ async function installCompiler(sender?: any): Promise<void> {
break;
case "darwin": {
const title = localize('install.compiler.mac.title', 'The clang compiler will now be installed');
const detail = localize('install.compiler.mac.detail', 'You may need to type your password in the terminal window that will appear to authorize the installation.');
const detail = localize('install.compiler.mac.detail', 'You may be prompted to type your password in the terminal window that will appear to authorize the installation.');
const response = await vscode.window.showInformationMessage(title, { modal: true, detail }, ok);
if (response === ok) {
const terminal = vscode.window.createTerminal('Install C++ Compiler');
Expand Down Expand Up @@ -585,7 +585,7 @@ async function installCompiler(sender?: any): Promise<void> {
})();
if (installCommand) {
const title = localize('install.compiler.linux.title', 'The gcc compiler will now be installed');
const detail = localize('install.compiler.linux.detail', 'You may need to type your password in the terminal window that will appear to authorize the installation.');
const detail = localize('install.compiler.linux.detail', 'You may be prompted to type your password in the terminal window that will appear to authorize the installation.');
const response = await vscode.window.showInformationMessage(title, { modal: true, detail }, ok);
if (response === ok) {
const terminal = vscode.window.createTerminal('Install C++ Compiler');
Expand Down Expand Up @@ -733,7 +733,7 @@ async function onDisableAllTypeCodeAnalysisProblems(code: string, identifiersAnd

async function onCopyDeclarationOrDefinition(args?: any): Promise<void> {
const sender: any | undefined = util.isString(args?.sender) ? args.sender : args;
const properties: { [key: string]: string } = {
const properties: Record<string, string> = {
sender: util.getSenderType(sender)
};
telemetry.logLanguageServerEvent('CopyDeclDefn', properties);
Expand All @@ -742,7 +742,7 @@ async function onCopyDeclarationOrDefinition(args?: any): Promise<void> {

async function onCreateDeclarationOrDefinition(args?: any): Promise<void> {
const sender: any | undefined = util.isString(args?.sender) ? args.sender : args;
const properties: { [key: string]: string } = {
const properties: Record<string, string> = {
sender: util.getSenderType(sender)
};
telemetry.logLanguageServerEvent('CreateDeclDefn', properties);
Expand Down Expand Up @@ -936,7 +936,7 @@ function reportMacCrashes(): void {
const home: string = os.homedir();
const crashFolder: string = path.resolve(home, "Library/Logs/DiagnosticReports");
fs.stat(crashFolder, (err) => {
const crashObject: { [key: string]: string } = {};
const crashObject: Record<string, string> = {};
if (err?.code) {
// If the directory isn't there, we have a problem...
crashObject["fs.stat: err.code"] = err.code;
Expand Down Expand Up @@ -980,12 +980,12 @@ let previousMacCrashData: string;
let previousMacCrashCount: number = 0;

function logMacCrashTelemetry(data: string): void {
const crashObject: { [key: string]: string } = {};
const crashCountObject: { [key: string]: number } = {};
crashObject["CrashingThreadCallStack"] = data;
const crashObject: Record<string, string> = {};
const crashCountObject: Record<string, number> = {};
crashObject.CrashingThreadCallStack = data;
previousMacCrashCount = data === previousMacCrashData ? previousMacCrashCount + 1 : 0;
previousMacCrashData = data;
crashCountObject["CrashCount"] = previousMacCrashCount;
crashCountObject.CrashCount = previousMacCrashCount;
telemetry.logLanguageServerEvent("MacCrash", crashObject, crashCountObject);
}

Expand Down
30 changes: 15 additions & 15 deletions Extension/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ export function getIntelliSenseProgress(): number {
export function setProgress(progress: number): void {
if (extensionContext && getProgress() < progress) {
void extensionContext.globalState.update(installProgressStr, progress);
const telemetryProperties: { [key: string]: string } = {};
const telemetryProperties: Record<string, string> = {};
let progressName: string | undefined;
switch (progress) {
case 0: progressName = "install started"; break;
Expand All @@ -274,7 +274,7 @@ export function setProgress(progress: number): void {
case progressParseRootSuccess: progressName = "parse root succeeded"; break;
}
if (progressName) {
telemetryProperties['progress'] = progressName;
telemetryProperties.progress = progressName;
}
Telemetry.logDebuggerEvent("progress", telemetryProperties);
}
Expand All @@ -283,13 +283,13 @@ export function setProgress(progress: number): void {
export function setIntelliSenseProgress(progress: number): void {
if (extensionContext && getIntelliSenseProgress() < progress) {
void extensionContext.globalState.update(intelliSenseProgressStr, progress);
const telemetryProperties: { [key: string]: string } = {};
const telemetryProperties: Record<string, string> = {};
let progressName: string | undefined;
switch (progress) {
case progressIntelliSenseNoSquiggles: progressName = "IntelliSense no squiggles"; break;
}
if (progressName) {
telemetryProperties['progress'] = progressName;
telemetryProperties.progress = progressName;
}
Telemetry.logDebuggerEvent("progress", telemetryProperties);
}
Expand Down Expand Up @@ -337,7 +337,7 @@ export function isOptionalArrayOfString(input: any): input is string[] | undefin
return input === undefined || isArrayOfString(input);
}

export function resolveCachePath(input: string | undefined, additionalEnvironment: { [key: string]: string | string[] }): string {
export function resolveCachePath(input: string | undefined, additionalEnvironment: Record<string, string | string[]>): string {
let resolvedPath: string = "";
if (!input || input.trim() === "") {
// If no path is set, return empty string to language service process, where it will set the default path as
Expand Down Expand Up @@ -368,7 +368,7 @@ export function findExePathInArgs(args: string[]): string | undefined {

// Pass in 'arrayResults' if a string[] result is possible and a delimited string result is undesirable.
// The string[] result will be copied into 'arrayResults'.
export function resolveVariables(input: string | undefined, additionalEnvironment?: { [key: string]: string | string[] }, arrayResults?: string[]): string {
export function resolveVariables(input: string | undefined, additionalEnvironment?: Record<string, string | string[]>, arrayResults?: string[]): string {
if (!input) {
return "";
}
Expand All @@ -384,7 +384,7 @@ export function resolveVariables(input: string | undefined, additionalEnvironmen
// Replace environment and configuration variables.
const regexp: () => RegExp = () => /\$\{((env|config|workspaceFolder|file|fileDirname|fileBasenameNoExtension|execPath|pathSeparator)(\.|:))?(.*?)\}/g;
let ret: string = input;
const cycleCache: Set<string> = new Set();
const cycleCache = new Set<string>();
while (!cycleCache.has(ret)) {
cycleCache.add(ret);
ret = ret.replace(regexp(), (match: string, ignored1: string, varType: string, ignored2: string, name: string) => {
Expand Down Expand Up @@ -443,7 +443,7 @@ export function resolveVariables(input: string | undefined, additionalEnvironmen
return resolveHome(ret);
}

export function resolveVariablesArray(variables: string[] | undefined, additionalEnvironment?: { [key: string]: string | string[] }): string[] {
export function resolveVariablesArray(variables: string[] | undefined, additionalEnvironment?: Record<string, string | string[]>): string[] {
let result: string[] = [];
if (variables) {
variables.forEach(variable => {
Expand All @@ -462,7 +462,7 @@ export function resolveHome(filePath: string): string {

export function asFolder(uri: vscode.Uri): string {
let result: string = uri.toString();
if (result.charAt(result.length - 1) !== '/') {
if (!result.endsWith('/')) {
result += '/';
}
return result;
Expand Down Expand Up @@ -864,7 +864,7 @@ export function removePotentialPII(str: string): string {
const words: string[] = str.split(" ");
let result: string = "";
for (const word of words) {
if (word.indexOf(".") === -1 && word.indexOf("/") === -1 && word.indexOf("\\") === -1 && word.indexOf(":") === -1) {
if (!word.includes(".") && !word.includes("/") && !word.includes("\\") && !word.includes(":")) {
result += word + " ";
} else {
result += "? ";
Expand Down Expand Up @@ -921,7 +921,7 @@ export function createTempFileWithPostfix(postfix: string): Promise<tmp.FileResu
if (err) {
return reject(err);
}
return resolve(<tmp.FileResult>{ name: path, fd: fd, removeCallback: cleanupCallback });
return resolve({ name: path, fd: fd, removeCallback: cleanupCallback } as tmp.FileResult);
});
});
}
Expand Down Expand Up @@ -1183,7 +1183,7 @@ export function getSenderType(sender?: any): string {
} else if (isUri(sender)) {
return 'contextMenu';
} else if (sender?.sender) {
return sender.sender; // The walkthrough buttons send an object with a 'sender' property.
return sender.sender; // The walkthrough buttons send an object with a 'sender' property.
}
return 'commandPalette';
}
Expand Down Expand Up @@ -1310,15 +1310,15 @@ export function getCacheStoragePath(): string {
switch (os.platform()) {
case 'win32':
defaultCachePath = "Microsoft\\vscode-cpptools\\";
pathEnvironmentVariable = process.env["LOCALAPPDATA"];
pathEnvironmentVariable = process.env.LOCALAPPDATA;
break;
case 'darwin':
defaultCachePath = "Library/Caches/vscode-cpptools/";
pathEnvironmentVariable = os.homedir();
break;
default: // Linux
defaultCachePath = "vscode-cpptools/";
pathEnvironmentVariable = process.env["XDG_CACHE_HOME"];
pathEnvironmentVariable = process.env.XDG_CACHE_HOME;
if (!pathEnvironmentVariable) {
pathEnvironmentVariable = os.homedir();
}
Expand Down Expand Up @@ -1351,7 +1351,7 @@ export function getUniqueWorkspaceStorageName(workspaceFolder: vscode.WorkspaceF
}

export function isCodespaces(): boolean {
return !!process.env["CODESPACES"];
return !!process.env.CODESPACES;
}

// Sequentially Resolve Promises.
Expand Down

0 comments on commit 8198993

Please sign in to comment.