Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is order change and shouldnt have any impact as such on functionality a359540

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 {
Copy link
Member Author

@sheetalkamat sheetalkamat Oct 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldnt be needed since default typeAcquisition is always disabled ae1b510

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