Skip to content

Commit

Permalink
More logging + the fix, I think
Browse files Browse the repository at this point in the history
  • Loading branch information
NullVoxPopuli committed Oct 24, 2024
1 parent 27f8e00 commit a9570a8
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/utils/addon-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from './layout-helpers';
import { TextDocument } from 'vscode-languageserver-textdocument';
import * as path from 'path';
import { log, logInfo, logError, safeStringify } from './logger';
import { log, logInfo, logError, safeStringify, instrumentTime } from './logger';
import Server from '../server';
import ASTPath from './../glimmer-utils';
import DAGMap from 'dag-map';
Expand Down Expand Up @@ -188,7 +188,13 @@ function requireUncached(module: string) {
}

export async function collectProjectProviders(root: string, addons: string[]): Promise<ProjectProviders> {
const time = instrumentTime(`collectProjectProviders(${root})`);

time.log(`Starting`);
const [projectAddonsRoots, projectInRepoAddonsRoots] = await Promise.all([getProjectAddonsRoots(root), getProjectInRepoAddonsRoots(root)]);

time.log(`found roots`);

const roots = addons
.concat([root])
.concat(projectAddonsRoots, projectInRepoAddonsRoots)
Expand Down Expand Up @@ -226,6 +232,8 @@ export async function collectProjectProviders(root: string, addons: string[]): P
}
}

time.log(`found ELS addons`);

const result: {
definitionProviders: DefinitionResolveFunction[];
referencesProviders: ReferenceResolveFunction[];
Expand Down Expand Up @@ -332,6 +340,8 @@ export async function collectProjectProviders(root: string, addons: string[]): P
}
});

time.log(`finished crawling dagMap`);

return result;
}

Expand Down
44 changes: 44 additions & 0 deletions src/utils/layout-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ import { clean, coerce, valid } from 'semver';
import { BaseProject } from '../base-project';
import { fsProvider } from '../fs-provider';
import walkAsync from './walk-async';
import { instrumentTime } from './logger';

// const GLOBAL_REGISTRY = ['primitive-name'][['relatedFiles']];

// Don't traverse dependencies we've already seen.
// correct package graph can sort of throw us in to cycles if we don't keep track of this.
const SEEN = new Set<string>();

export const ADDON_CONFIG_KEY = 'ember-language-server';

export async function asyncFilter<T>(arr: T[], predicate: (value: unknown) => Promise<boolean | undefined>): Promise<T[]> {
Expand Down Expand Up @@ -196,6 +201,16 @@ export function cached(_proto: unknown, prop: string, desc: PropertyDescriptor)

async function getRecursiveInRepoAddonRoots(root: string, roots: string[]) {
const packageData = await asyncGetPackageJSON(root);

// names are required for packages
if (!packageData.name) return [];

if (SEEN.has(packageData.name)) {
return [];
}

SEEN.add(packageData.name);

const emberAddonPaths: string[] = (packageData['ember-addon'] && packageData['ember-addon'].paths) || [];

if (roots.length) {
Expand All @@ -213,6 +228,15 @@ async function getRecursiveInRepoAddonRoots(root: string, roots: string[]) {
for (const validRoot of validPaths) {
const packInfo = await asyncGetPackageJSON(validRoot);

// names are required for packages
if (!packInfo.name) continue;

if (SEEN.has(packInfo.name)) {
continue;
}

SEEN.add(packInfo.name);

// we don't need to go deeper if package itself not an ember-addon or els-extension
if (!isEmberAddon(packInfo) && !hasEmberLanguageServerExtension(packInfo)) {
continue;
Expand All @@ -234,8 +258,12 @@ async function getRecursiveInRepoAddonRoots(root: string, roots: string[]) {
}

export async function getProjectInRepoAddonsRoots(root: string): Promise<string[]> {
const time = instrumentTime(`getProjectInRepoAddonsRoots(${root})`);

const roots: string[] = await getRecursiveInRepoAddonRoots(root, []);

time.log(`finished getRecursiveInRepoAddonRoots`);

return Array.from(new Set(roots));
}

Expand Down Expand Up @@ -274,8 +302,16 @@ export async function isGlimmerXProject(root: string) {
}

export async function getProjectAddonsRoots(root: string, resolvedItems: string[] = [], packageFolderName = 'node_modules') {
const time = instrumentTime(`getProjectInRepoAddonsRoots(${root})`);

const pack = await asyncGetPackageJSON(root);

if (!pack.name) return [];

if (SEEN.has(pack.name)) return [];

SEEN.add(pack.name);

if (resolvedItems.length) {
if (!isEmberAddon(pack)) {
return [];
Expand Down Expand Up @@ -304,6 +340,12 @@ export async function getProjectAddonsRoots(root: string, resolvedItems: string[
for (const rootItem of roots) {
const packInfo = packages[roots.indexOf(rootItem)];

if (!packInfo.name) continue;

if (SEEN.has(packInfo.name)) continue;

SEEN.add(packInfo.name);

// we don't need to go deeper if package itself not an ember-addon or els-extension
if (!isEmberAddon(packInfo) && !hasEmberLanguageServerExtension(packInfo)) {
continue;
Expand All @@ -321,6 +363,8 @@ export async function getProjectAddonsRoots(root: string, resolvedItems: string[
}
}

time.log(`Finished looping over ${roots.length} roots`);

return recursiveRoots;
}

Expand Down
18 changes: 18 additions & 0 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ export function logInfo(str: string) {
}
}

export function instrumentTime(label: string) {
let last = Date.now();

return {
reset: () => {
last = Date.now();
},
log: (msg: string) => {
const now = Date.now();
const diff = now - last;

last = now;

logInfo(`[${label}] +${diff}ms :: ${msg}`);
},
};
}

export function setConsole(item: RemoteConsole | null) {
remoteConsole = item;
}
Expand Down

0 comments on commit a9570a8

Please sign in to comment.