Skip to content
Draft
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
8 changes: 8 additions & 0 deletions src/builtin-addons/core/template-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
isScopedAngleTagName,
isSpecialHelperStringPositionalParam,
isFirstParamOfOnModifier,
isAttributeValueConcatMustachePath,
} from '../../utils/ast-helpers';
import {
listComponents,
Expand Down Expand Up @@ -576,6 +577,13 @@ export default class TemplateCompletionProvider {
const yields = await this.getParentComponentYields(focusPath.parent);

completions.push(...yields);
} else if (isAttributeValueConcatMustachePath(focusPath)) {
const ignoredHelpers = ['helper', 'modifier', 'component'];
const items = await this.getMustachePathCandidates(root);
const localCandidates = await this.getLocalPathExpressionCandidates(uri, originalText);

completions.push(...items.filter((el) => el.detail === 'helper' && !ignoredHelpers.includes(el.label)));
completions.push(...localCandidates);
} else if (isAngleComponentPath(focusPath)) {
logDebugInfo('isAngleComponentPath');
// <Foo>
Expand Down
30 changes: 30 additions & 0 deletions src/utils/ast-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,36 @@ export function isScopedAngleTagName(path: ASTPath): boolean {
return !HTML_TAGS.includes(node.tag);
}

export function isAttributeValueConcatMustachePath(path: ASTPath): boolean {
const node = path.node as ASTv1.PathExpression;

if (!isPathExpression(node)) {
return false;
}

const parent = path.parent as ASTv1.MustacheStatement;

if (!hasNodeType(parent, 'MustacheStatement')) {
return false;
}

if (parent.path !== node) {
return false;
}

const parentPath = path.parentPath;

if (!parentPath) {
return false;
}

if (!hasNodeType(parentPath.parent, 'ConcatStatement')) {
return false;
}

return true;
}

export function isAngleComponentPath(path: ASTPath): boolean {
const node = path.node as unknown as ASTv1.ElementNode;

Expand Down
138 changes: 138 additions & 0 deletions test/__snapshots__/integration-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,75 @@ Object {
}
`;

exports[`integration async fs enabled: false Able to provide autocomplete information for MustacheStatements inside ConcatStatements support helper names autocomplete inside class attribute values 1`] = `
Object {
"addonsMeta": Array [],
"registry": Object {
"component": Object {
"hello": Array [
"app/components/hello/index.hbs",
],
},
"helper": Object {
"bar": Array [
"app/helpers/bar.js",
],
"baz": Array [
"app/helpers/baz.ts",
],
},
},
"response": Array [
Object {
"data": Object {
"files": Array [
"app/helpers/bar.js",
],
},
"detail": "helper",
"kind": 3,
"label": "bar",
"textEdit": Object {
"newText": "bar",
"range": Object {
"end": Object {
"character": 19,
"line": 0,
},
"start": Object {
"character": 18,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/helpers/baz.ts",
],
},
"detail": "helper",
"kind": 3,
"label": "baz",
"textEdit": Object {
"newText": "baz",
"range": Object {
"end": Object {
"character": 19,
"line": 0,
},
"start": Object {
"character": 18,
"line": 0,
},
},
},
},
],
}
`;

exports[`integration async fs enabled: false Able to provide autocomplete information for angle component arguments names support template-only collocated components arguments extraction 1`] = `
Object {
"addonsMeta": Array [],
Expand Down Expand Up @@ -4206,6 +4275,75 @@ Object {
}
`;

exports[`integration async fs enabled: true Able to provide autocomplete information for MustacheStatements inside ConcatStatements support helper names autocomplete inside class attribute values 1`] = `
Object {
"addonsMeta": Array [],
"registry": Object {
"component": Object {
"hello": Array [
"app/components/hello/index.hbs",
],
},
"helper": Object {
"bar": Array [
"app/helpers/bar.js",
],
"baz": Array [
"app/helpers/baz.ts",
],
},
},
"response": Array [
Object {
"data": Object {
"files": Array [
"app/helpers/bar.js",
],
},
"detail": "helper",
"kind": 3,
"label": "bar",
"textEdit": Object {
"newText": "bar",
"range": Object {
"end": Object {
"character": 19,
"line": 0,
},
"start": Object {
"character": 18,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/helpers/baz.ts",
],
},
"detail": "helper",
"kind": 3,
"label": "baz",
"textEdit": Object {
"newText": "baz",
"range": Object {
"end": Object {
"character": 19,
"line": 0,
},
"start": Object {
"character": 18,
"line": 0,
},
},
},
},
],
}
`;

exports[`integration async fs enabled: true Able to provide autocomplete information for angle component arguments names support template-only collocated components arguments extraction 1`] = `
Object {
"addonsMeta": Array [],
Expand Down
26 changes: 26 additions & 0 deletions test/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,32 @@ describe('integration', function () {
});
});

describe('Able to provide autocomplete information for MustacheStatements inside ConcatStatements', () => {
it('support helper names autocomplete inside class attribute values', async () => {
const result = await getResult(
CompletionRequest.method,
connection,
{
app: {
helpers: {
'bar.js': '',
'baz.ts': '',
},
components: {
hello: {
'index.hbs': '<div class="foo {{b">a</div>',
},
},
},
},
'app/components/hello/index.hbs',
{ line: 0, character: 19 }
);

expect(result).toMatchSnapshot();
});
});

describe('Able to provide autocomplete information for local context access', () => {
it('support collocated components', async () => {
const result = await getResult(
Expand Down