Skip to content

Commit feeb30d

Browse files
authored
Some of the test refactoring and readable baselining (#56075)
1 parent a8546ce commit feeb30d

File tree

333 files changed

+37576
-24250
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

333 files changed

+37576
-24250
lines changed

src/jsTyping/jsTyping.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import {
3030
Version,
3131
versionMajorMinor,
3232
} from "./_namespaces/ts";
33+
import {
34+
stringifyIndented,
35+
} from "./_namespaces/ts.server";
3336

3437
export interface TypingResolutionHost {
3538
directoryExists(path: string): boolean;
@@ -174,7 +177,7 @@ export function discoverTypings(
174177
}
175178

176179
// A typing name to typing file path mapping
177-
const inferredTypings = new Map<string, string>();
180+
const inferredTypings = new Map<string, string | false>();
178181

179182
// Only infer typings for .js and .jsx files
180183
fileNames = mapDefined(fileNames, fileName => {
@@ -211,37 +214,37 @@ export function discoverTypings(
211214
);
212215
addInferredTypings(module, "Inferred typings from unresolved imports");
213216
}
217+
// Remove typings that the user has added to the exclude list
218+
for (const excludeTypingName of exclude) {
219+
const didDelete = inferredTypings.delete(excludeTypingName);
220+
if (didDelete && log) log(`Typing for ${excludeTypingName} is in exclude list, will be ignored.`);
221+
}
222+
214223
// Add the cached typing locations for inferred typings that are already installed
215224
packageNameToTypingLocation.forEach((typing, name) => {
216225
const registryEntry = typesRegistry.get(name);
217-
if (inferredTypings.has(name) && inferredTypings.get(name) === undefined && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
226+
if (inferredTypings.get(name) === false && registryEntry !== undefined && isTypingUpToDate(typing, registryEntry)) {
218227
inferredTypings.set(name, typing.typingLocation);
219228
}
220229
});
221230

222-
// Remove typings that the user has added to the exclude list
223-
for (const excludeTypingName of exclude) {
224-
const didDelete = inferredTypings.delete(excludeTypingName);
225-
if (didDelete && log) log(`Typing for ${excludeTypingName} is in exclude list, will be ignored.`);
226-
}
227-
228231
const newTypingNames: string[] = [];
229232
const cachedTypingPaths: string[] = [];
230233
inferredTypings.forEach((inferred, typing) => {
231-
if (inferred !== undefined) {
234+
if (inferred) {
232235
cachedTypingPaths.push(inferred);
233236
}
234237
else {
235238
newTypingNames.push(typing);
236239
}
237240
});
238241
const result = { cachedTypingPaths, newTypingNames, filesToWatch };
239-
if (log) log(`Result: ${JSON.stringify(result)}`);
242+
if (log) log(`Finished typings discovery:${stringifyIndented(result)}`);
240243
return result;
241244

242245
function addInferredTyping(typingName: string) {
243246
if (!inferredTypings.has(typingName)) {
244-
inferredTypings.set(typingName, undefined!); // TODO: GH#18217
247+
inferredTypings.set(typingName, false);
245248
}
246249
}
247250
function addInferredTypings(typingNames: readonly string[], message: string) {

src/jsTyping/shared.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,19 @@ export function nowString() {
6565
const d = new Date();
6666
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")}`;
6767
}
68+
69+
const indentStr = "\n ";
70+
71+
/** @internal */
72+
export function indent(str: string): string {
73+
return indentStr + str.replace(/\n/g, indentStr);
74+
}
75+
76+
/**
77+
* Put stringified JSON on the next line, indented.
78+
*
79+
* @internal
80+
*/
81+
export function stringifyIndented(json: {}): string {
82+
return indent(JSON.stringify(json, undefined, 2));
83+
}

src/server/project.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2640,10 +2640,6 @@ export class AutoImportProviderProject extends Project {
26402640
return PackageJsonAutoImportPreference.Off;
26412641
}
26422642

2643-
override getTypeAcquisition(): TypeAcquisition {
2644-
return { enable: false };
2645-
}
2646-
26472643
/** @internal */
26482644
override getSymlinkCache() {
26492645
return this.hostProject.getSymlinkCache();

src/server/session.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ export function formatMessage<T extends protocol.Message>(msg: T, logger: Logger
323323

324324
const json = JSON.stringify(msg);
325325
if (verboseLogging) {
326-
logger.info(`${msg.type}:${indent(JSON.stringify(msg, undefined, " "))}`);
326+
logger.info(`${msg.type}:${stringifyIndented(msg)}`);
327327
}
328328

329329
const len = byteLength(json, "utf8");

src/server/utilities.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,19 +110,3 @@ export function removeSorted<T>(array: SortedArray<T>, remove: T, compare: Compa
110110
array.splice(removeIndex, 1);
111111
}
112112
}
113-
114-
const indentStr = "\n ";
115-
116-
/** @internal */
117-
export function indent(str: string): string {
118-
return indentStr + str.replace(/\n/g, indentStr);
119-
}
120-
121-
/**
122-
* Put stringified JSON on the next line, indented.
123-
*
124-
* @internal
125-
*/
126-
export function stringifyIndented(json: {}): string {
127-
return indentStr + JSON.stringify(json);
128-
}

0 commit comments

Comments
 (0)