Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add support for multinamespaced components #212

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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/builtin-addons/core/template-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ export default class TemplateCompletionProvider {

if (this.hasNamespaceSupport) {
const registry = this.server.getRegistry(this.project.root);

completions.forEach((item) => {
const extraCompletions: CompletionItem[] = [];
const filteredCompletions = completions.filter((item) => {
if (item.detail === 'component') {
const paths = registry.component[normalizeToClassicComponent(item.label)] || [];
const roots = this.project.addonsMeta
Expand All @@ -356,13 +356,27 @@ export default class TemplateCompletionProvider {
.sort((a, b) => {
return b.root.length - a.root.length;
});
const closestRoot: null | string = roots.length ? roots[0].name : null;

if (closestRoot !== null) {
item.label = `${normalizeToAngleBracketComponent(closestRoot)}$${item.label}`;
roots.forEach((r) => {
extraCompletions.push({
...item,
...{
label: `${normalizeToAngleBracketComponent(r.name)}$${item.label}`,
},
});
});

if (roots.length) {
return false;
} else {
return true;
}
}

return true;
});

return [...filteredCompletions, ...extraCompletions];
}

return completions;
Expand Down
99 changes: 97 additions & 2 deletions test/__snapshots__/batman-fixture-based-integration-test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,100 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`With \`batman project\` initialized on server Completion request returns all angle-bracket components with same name from different namespaces 1`] = `
Array [
Object {
"detail": "component",
"kind": 7,
"label": "AnotherAwesomeComponent",
"textEdit": Object {
"newText": "AnotherAwesomeComponent",
"range": Object {
"end": Object {
"character": 1,
"line": 0,
},
"start": Object {
"character": 1,
"line": 0,
},
},
},
},
Object {
"detail": "component",
"kind": 7,
"label": "MyAwesomeComponent",
"textEdit": Object {
"newText": "MyAwesomeComponent",
"range": Object {
"end": Object {
"character": 1,
"line": 0,
},
"start": Object {
"character": 1,
"line": 0,
},
},
},
},
Object {
"detail": "component",
"kind": 7,
"label": "Nested::NestedComponent",
"textEdit": Object {
"newText": "Nested::NestedComponent",
"range": Object {
"end": Object {
"character": 1,
"line": 0,
},
"start": Object {
"character": 1,
"line": 0,
},
},
},
},
Object {
"detail": "component",
"kind": 7,
"label": "Boo$Bar",
"textEdit": Object {
"newText": "Boo$Bar",
"range": Object {
"end": Object {
"character": 1,
"line": 0,
},
"start": Object {
"character": 1,
"line": 0,
},
},
},
},
Object {
"detail": "component",
"kind": 7,
"label": "Foo$Bar",
"textEdit": Object {
"newText": "Foo$Bar",
"range": Object {
"end": Object {
"character": 1,
"line": 0,
},
"start": Object {
"character": 1,
"line": 0,
},
},
},
},
]
`;

exports[`With \`batman project\` initialized on server Completion request returns all angle-bracket in a element expression for in repo addons with batman syntax 1`] = `
Array [
Object {
Expand Down Expand Up @@ -36,7 +131,7 @@ Array [
"line": 0,
},
},
"uri": "/lib/foo/addon/templates/components/bar.hbs",
"uri": "/lib/boo/addon/templates/components/bar.hbs",
},
]
`;
Expand All @@ -54,7 +149,7 @@ Array [
"line": 0,
},
},
"uri": "/lib/foo/app/components/bar.js",
"uri": "/lib/foo/addon/components/bar.js",
},
]
`;
19 changes: 19 additions & 0 deletions test/batman-fixture-based-integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,25 @@ describe('With `batman project` initialized on server', () => {

expect(response).toMatchSnapshot();
});

it('returns all angle-bracket components with same name from different namespaces', async () => {
const applicationTemplatePath = path.join(__dirname, 'fixtures', 'batman', 'app', 'templates', 'same-component-name.hbs');
const params = {
textDocument: {
uri: URI.file(applicationTemplatePath).toString(),
},
position: {
line: 0,
character: 1,
},
};

openFile(connection, applicationTemplatePath);

const response = await connection.sendRequest(CompletionRequest.method, params);

expect(response).toMatchSnapshot();
});
});

describe('Definition request', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/batman/app/templates/batman-definition.hbs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<Foo$Bar />
<Boo$Bar />
1 change: 1 addition & 0 deletions test/fixtures/batman/app/templates/same-component-name.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Foo$Bar />
<Boo$Bar />
10 changes: 10 additions & 0 deletions test/fixtures/batman/lib/boo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-env node */
'use strict';

module.exports = {
name: 'boo',

isDevelopingAddon() {
return true;
}
};
9 changes: 9 additions & 0 deletions test/fixtures/batman/lib/boo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "boo",
"keywords": [
"ember-addon"
],
"dependencies": {

}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<MyAwesomeComponent />

<Boo$Bar />
3 changes: 0 additions & 3 deletions test/fixtures/batman/lib/foo/app/components/bar.js

This file was deleted.

3 changes: 2 additions & 1 deletion test/fixtures/batman/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
},
"ember-addon": {
"paths": [
"lib/foo"
"lib/foo",
"lib/boo"
]
}
}