Skip to content

Commit

Permalink
fix all found deviations in tests with async fs (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
lifeart authored Oct 5, 2021
1 parent 053839f commit c9ec38b
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 50 deletions.
3 changes: 3 additions & 0 deletions src/fs-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ export default class FSProvider {
const entry = URI.isUri(uri) ? URI.parse(uri as DocumentUri).fsPath : uri;
const item = fs.readFileSync(entry, null);

// need this lines to debug slowness issues
// await new Promise((resolve) => setTimeout(resolve, 200));

return item.toString('utf8');
}
// logger api
Expand Down
8 changes: 4 additions & 4 deletions src/project-roots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,22 +86,22 @@ export default class ProjectRoots {
ignore: ['**/.git/**', '**/bower_components/**', '**/dist/**', '**/node_modules/**', '**/tmp/**'],
});

roots.forEach(async (rootPath: string) => {
for (const rootPath of roots) {
const filePath = path.join(workspaceRoot, rootPath);
const fullPath = path.dirname(filePath);

if (filePath.endsWith('package.json')) {
try {
if (await isGlimmerXProject(fullPath)) {
this.onProjectAdd(fullPath);
await this.onProjectAdd(fullPath);
}
} catch (e) {
logError(e);
}
} else {
this.onProjectAdd(fullPath);
await this.onProjectAdd(fullPath);
}
});
}
}

async initialize(workspaceRoot: string) {
Expand Down
16 changes: 7 additions & 9 deletions src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ export class Project extends BaseProject {
enableEagerRegistryInitialization: true,
};
async init(server: Server) {
this.providers.initFunctions.forEach((initFn) => {
for (const initFn of this.providers.initFunctions) {
try {
const initResult = initFn(server, this);
const initResult = await initFn(server, this);

if (typeof initResult === 'function') {
this.destructors.push(initResult);
Expand All @@ -202,11 +202,11 @@ export class Project extends BaseProject {
this.initIssues.push(e.toString());
this.initIssues.push(e.stack);
}
});
}

this.builtinProviders.initFunctions.forEach((initFn) => {
for (const initFn of this.builtinProviders.initFunctions) {
try {
const initResult = initFn(server, this);
const initResult = await initFn(server, this);

if (typeof initResult === 'function') {
this.destructors.push(initResult);
Expand All @@ -216,13 +216,11 @@ export class Project extends BaseProject {
this.initIssues.push(e.toString());
this.initIssues.push(e.stack);
}
});
}

if (this.flags.enableEagerRegistryInitialization) {
// prefer explicit registry tree building
await findTestsForProject(this);
await findAppItemsForProject(this);
await findAddonItemsForProject(this);
await Promise.all([findTestsForProject(this), findAppItemsForProject(this), findAddonItemsForProject(this)]);
}

if (this.providers.info.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default class Server {
};

this.executors['els.provideDiagnostics'] = async (_, __, [document]: [TextDocument]) => {
return this.runAddonLinters(document);
return await this.runAddonLinters(document);
};

this.executors['els.getProjectRegistry'] = async (_, __, [filePath]: [string]) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/definition-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export async function pathsToLocationsWithPosition(paths: string[], findMe: stri
return Location.create(URI.file(fileName).toString(), Range.create(startLine, startCharacter, startLine, startCharacter + findMe.length));
});

return Promise.all(results);
return await Promise.all(results);
}

export function getAbstractParts(root: string, prefix: string, collection: string, name: string) {
Expand Down
48 changes: 24 additions & 24 deletions test/__snapshots__/fixture-based-integration-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -644,9 +644,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "test-route",
"label": "angle-completion",
"textEdit": Object {
"newText": "test-route",
"newText": "angle-completion",
"range": Object {
"end": Object {
"character": 12,
Expand All @@ -662,9 +662,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "nested.nested-route",
"label": "application",
"textEdit": Object {
"newText": "nested.nested-route",
"newText": "application",
"range": Object {
"end": Object {
"character": 12,
Expand All @@ -680,9 +680,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "angle-completion",
"label": "definition",
"textEdit": Object {
"newText": "angle-completion",
"newText": "definition",
"range": Object {
"end": Object {
"character": 12,
Expand All @@ -698,9 +698,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "application",
"label": "inrepo-addon-completion",
"textEdit": Object {
"newText": "application",
"newText": "inrepo-addon-completion",
"range": Object {
"end": Object {
"character": 12,
Expand All @@ -716,9 +716,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "definition",
"label": "test-route",
"textEdit": Object {
"newText": "definition",
"newText": "test-route",
"range": Object {
"end": Object {
"character": 12,
Expand All @@ -734,9 +734,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "inrepo-addon-completion",
"label": "nested.nested-route",
"textEdit": Object {
"newText": "inrepo-addon-completion",
"newText": "nested.nested-route",
"range": Object {
"end": Object {
"character": 12,
Expand All @@ -757,9 +757,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "test-route",
"label": "angle-completion",
"textEdit": Object {
"newText": "test-route",
"newText": "angle-completion",
"range": Object {
"end": Object {
"character": 23,
Expand All @@ -775,9 +775,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "nested.nested-route",
"label": "application",
"textEdit": Object {
"newText": "nested.nested-route",
"newText": "application",
"range": Object {
"end": Object {
"character": 23,
Expand All @@ -793,9 +793,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "angle-completion",
"label": "definition",
"textEdit": Object {
"newText": "angle-completion",
"newText": "definition",
"range": Object {
"end": Object {
"character": 23,
Expand All @@ -811,9 +811,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "application",
"label": "inrepo-addon-completion",
"textEdit": Object {
"newText": "application",
"newText": "inrepo-addon-completion",
"range": Object {
"end": Object {
"character": 23,
Expand All @@ -829,9 +829,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "definition",
"label": "test-route",
"textEdit": Object {
"newText": "definition",
"newText": "test-route",
"range": Object {
"end": Object {
"character": 23,
Expand All @@ -847,9 +847,9 @@ Array [
Object {
"detail": "route",
"kind": 17,
"label": "inrepo-addon-completion",
"label": "nested.nested-route",
"textEdit": Object {
"newText": "inrepo-addon-completion",
"newText": "nested.nested-route",
"range": Object {
"end": Object {
"character": 23,
Expand Down
36 changes: 26 additions & 10 deletions test/__snapshots__/integration-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2186,9 +2186,9 @@ exports[`integration async fs enabled: false Diffent commands handle "els.getPro
Object {
"component": Object {
"hello": Array [
"tests/integration/components/hello-test.js",
"app/components/hello/index.hbs",
"app/components/hello/index.js",
"tests/integration/components/hello-test.js",
],
},
}
Expand All @@ -2198,9 +2198,9 @@ exports[`integration async fs enabled: false Diffent commands handle "els.getRel
Object {
"component": Object {
"hello": Array [
"tests/integration/components/hello-test.js",
"app/components/hello/component.js",
"app/components/hello/template.hbs",
"tests/integration/components/hello-test.js",
],
},
}
Expand All @@ -2218,9 +2218,9 @@ exports[`integration async fs enabled: false Diffent commands handle "els.getRel
Object {
"component": Object {
"hello": Array [
"tests/integration/components/hello-test.js",
"app/components/hello/index.hbs",
"app/components/hello/index.js",
"tests/integration/components/hello-test.js",
],
},
}
Expand Down Expand Up @@ -2428,8 +2428,8 @@ Object {
"registry": Object {
"component": Object {
"darling": Array [
"tests/integration/components/darling/component-test.js",
"app/components/darling.ts",
"tests/integration/components/darling/component-test.js",
],
"hello": Array [
"app/components/hello.hbs",
Expand Down Expand Up @@ -2460,8 +2460,8 @@ Object {
"registry": Object {
"component": Object {
"darling": Array [
"tests/integration/components/darling/component-test.js",
"app/components/darling.ts",
"tests/integration/components/darling/component-test.js",
],
"hello": Array [
"app/components/hello.ts",
Expand Down Expand Up @@ -3262,6 +3262,13 @@ Object {
},
],
"registry": Object {
"component": Object {
"bar": Array [
"lib/biz/addon/templates/components/bar.hbs",
"../lib/foo/addon/templates/components/bar.hbs",
"../lib/foo/app/components/bar.js",
],
},
"routePath": Object {
"hello": Array [
"app/templates/hello.hbs",
Expand Down Expand Up @@ -4995,9 +5002,9 @@ exports[`integration async fs enabled: true Diffent commands handle "els.getProj
Object {
"component": Object {
"hello": Array [
"tests/integration/components/hello-test.js",
"app/components/hello/index.hbs",
"app/components/hello/index.js",
"tests/integration/components/hello-test.js",
],
},
}
Expand All @@ -5007,9 +5014,9 @@ exports[`integration async fs enabled: true Diffent commands handle "els.getRela
Object {
"component": Object {
"hello": Array [
"tests/integration/components/hello-test.js",
"app/components/hello/component.js",
"app/components/hello/template.hbs",
"tests/integration/components/hello-test.js",
],
},
}
Expand All @@ -5027,9 +5034,9 @@ exports[`integration async fs enabled: true Diffent commands handle "els.getRela
Object {
"component": Object {
"hello": Array [
"tests/integration/components/hello-test.js",
"app/components/hello/index.hbs",
"app/components/hello/index.js",
"tests/integration/components/hello-test.js",
],
},
}
Expand Down Expand Up @@ -5151,6 +5158,9 @@ Object {
],
"registry": Object {
"component": Object {
"bar": Array [
"lib/biz/addon/components/bar.js",
],
"darling": Array [
"app/components/darling/index.js",
],
Expand Down Expand Up @@ -5192,8 +5202,8 @@ Object {
"registry": Object {
"component": Object {
"darling": Array [
"tests/integration/components/darling/component-test.js",
"app/components/darling.ts",
"tests/integration/components/darling/component-test.js",
],
"hello": Array [
"app/components/hello.hbs",
Expand All @@ -5210,8 +5220,8 @@ Object {
"registry": Object {
"component": Object {
"darling": Array [
"tests/integration/components/darling/component-test.js",
"app/components/darling.ts",
"tests/integration/components/darling/component-test.js",
],
"hello": Array [
"app/components/hello.ts",
Expand Down Expand Up @@ -5413,6 +5423,12 @@ Object {
},
],
"registry": Object {
"component": Object {
"bar": Array [
"lib/biz/addon/components/bar.js",
"../lib/foo/addon/components/bar.js",
],
},
"helper": Object {
"blah": Array [
"tests/helpers/blah.js",
Expand Down
4 changes: 3 additions & 1 deletion test/test_helpers/integration-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,11 @@ async function registerProject(connection: MessageConnection, normalizedPath: st
arguments: [normalizedPath],
};

return (await connection.sendRequest(ExecuteCommandRequest.type, params)) as {
const data = (await connection.sendRequest(ExecuteCommandRequest.type, params)) as {
registry: Registry;
};

return data;
}

export async function setServerConfig(connection: MessageConnection, config = { local: { addons: [], ignoredProjects: [] } }) {
Expand Down

0 comments on commit c9ec38b

Please sign in to comment.