Skip to content

Commit

Permalink
Some of the test refactoring and readable baselining (#56075)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheetalkamat authored Oct 12, 2023
1 parent a8546ce commit feeb30d
Show file tree
Hide file tree
Showing 333 changed files with 37,576 additions and 24,250 deletions.
25 changes: 14 additions & 11 deletions src/jsTyping/jsTyping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import {
Version,
versionMajorMinor,
} from "./_namespaces/ts";
import {
stringifyIndented,
} from "./_namespaces/ts.server";

export interface TypingResolutionHost {
directoryExists(path: string): boolean;
Expand Down Expand Up @@ -174,7 +177,7 @@ export function discoverTypings(
}

// A typing name to typing file path mapping
const inferredTypings = new Map<string, string>();
const inferredTypings = new Map<string, string | false>();

// Only infer typings for .js and .jsx files
fileNames = mapDefined(fileNames, fileName => {
Expand Down Expand Up @@ -211,37 +214,37 @@ export function discoverTypings(
);
addInferredTypings(module, "Inferred typings from unresolved imports");
}
// Remove typings that the user has added to the exclude list
for (const excludeTypingName of exclude) {
const didDelete = inferredTypings.delete(excludeTypingName);
if (didDelete && log) log(`Typing for ${excludeTypingName} is in exclude list, will be ignored.`);
}

// Add the cached typing locations for inferred typings that are already installed
packageNameToTypingLocation.forEach((typing, name) => {
const registryEntry = typesRegistry.get(name);
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
if (inferredTypings.get(name) === false && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
inferredTypings.set(name, typing.typingLocation);
}
});

// Remove typings that the user has added to the exclude list
for (const excludeTypingName of exclude) {
const didDelete = inferredTypings.delete(excludeTypingName);
if (didDelete && log) log(`Typing for ${excludeTypingName} is in exclude list, will be ignored.`);
}

const newTypingNames: string[] = [];
const cachedTypingPaths: string[] = [];
inferredTypings.forEach((inferred, typing) => {
if (inferred !== undefined) {
if (inferred) {
cachedTypingPaths.push(inferred);
}
else {
newTypingNames.push(typing);
}
});
const result = { cachedTypingPaths, newTypingNames, filesToWatch };
if (log) log(`Result: ${JSON.stringify(result)}`);
if (log) log(`Finished typings discovery:${stringifyIndented(result)}`);
return result;

function addInferredTyping(typingName: string) {
if (!inferredTypings.has(typingName)) {
inferredTypings.set(typingName, undefined!); // TODO: GH#18217
inferredTypings.set(typingName, false);
}
}
function addInferredTypings(typingNames: readonly string[], message: string) {
Expand Down
16 changes: 16 additions & 0 deletions src/jsTyping/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,19 @@ export function nowString() {
const d = new Date();
return `${d.getHours().toString().padStart(2, "0")}:${d.getMinutes().toString().padStart(2, "0")}:${d.getSeconds().toString().padStart(2, "0")}.${d.getMilliseconds().toString().padStart(3, "0")}`;
}

const indentStr = "\n ";

/** @internal */
export function indent(str: string): string {
return indentStr + str.replace(/\n/g, indentStr);
}

/**
* Put stringified JSON on the next line, indented.
*
* @internal
*/
export function stringifyIndented(json: {}): string {
return indent(JSON.stringify(json, undefined, 2));
}
4 changes: 0 additions & 4 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2640,10 +2640,6 @@ export class AutoImportProviderProject extends Project {
return PackageJsonAutoImportPreference.Off;
}

override getTypeAcquisition(): TypeAcquisition {
return { enable: false };
}

/** @internal */
override getSymlinkCache() {
return this.hostProject.getSymlinkCache();
Expand Down
2 changes: 1 addition & 1 deletion src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export function formatMessage<T extends protocol.Message>(msg: T, logger: Logger

const json = JSON.stringify(msg);
if (verboseLogging) {
logger.info(`${msg.type}:${indent(JSON.stringify(msg, undefined, " "))}`);
logger.info(`${msg.type}:${stringifyIndented(msg)}`);
}

const len = byteLength(json, "utf8");
Expand Down
16 changes: 0 additions & 16 deletions src/server/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,3 @@ export function removeSorted<T>(array: SortedArray<T>, remove: T, compare: Compa
array.splice(removeIndex, 1);
}
}

const indentStr = "\n ";

/** @internal */
export function indent(str: string): string {
return indentStr + str.replace(/\n/g, indentStr);
}

/**
* Put stringified JSON on the next line, indented.
*
* @internal
*/
export function stringifyIndented(json: {}): string {
return indentStr + JSON.stringify(json);
}
Loading

0 comments on commit feeb30d

Please sign in to comment.