Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

fix: remove multi-character triggerCharacters, yielded block completion #418

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
5 changes: 3 additions & 2 deletions src/builtin-addons/core/template-completion-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,14 +576,15 @@ export default class TemplateCompletionProvider {
const yields = await this.getParentComponentYields(focusPath.parent);

completions.push(...yields);
} else if (isAngleComponentPath(focusPath) && !isNamedBlockName(focusPath)) {
} else if (isAngleComponentPath(focusPath)) {
logDebugInfo('isAngleComponentPath');
// <Foo>
const candidates = await this.getAllAngleBracketComponents(root);
const scopedValues = this.getExtendedScopedValues(focusPath);
const yields = await this.getParentComponentYields(focusPath.parent);

logDebugInfo(candidates, scopedValues);
completions.push(...uniqBy([...candidates, ...scopedValues], 'label'));
completions.push(...uniqBy([...yields, ...candidates, ...scopedValues], 'label'));
} else if (isScopedAngleTagName(focusPath)) {
// {{#let foo as |bar|}} <bar..
const scopedValues = this.getExtendedScopedValues(focusPath);
Expand Down
2 changes: 1 addition & 1 deletion src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ export default class Server {
},
completionProvider: {
resolveProvider: true,
triggerCharacters: ['.', '::', '$', '=', '/', '{{', '(', '<', '@', 'this.', '<:', '"', "'"],
triggerCharacters: ['.', ':', '$', '=', '/', '{', '(', '<', '@', '"', "'", '#'],
},
},
};
Expand Down
206 changes: 194 additions & 12 deletions test/__snapshots__/integration-test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3471,18 +3471,17 @@ Object {
"resolveProvider": true,
"triggerCharacters": Array [
".",
"::",
":",
"$",
"=",
"/",
"{{",
"{",
"(",
"<",
"@",
"this.",
"<:",
"\\"",
"'",
"#",
],
},
"definitionProvider": true,
Expand Down Expand Up @@ -3753,7 +3752,99 @@ Array [
]
`;

exports[`integration async fs enabled: false autocomplete works for angle component slots 1`] = `
exports[`integration async fs enabled: false autocomplete includes yielded blocks in angle component completions 1`] = `
Array [
Object {
"detail": "Named block (Slot) for <Darling>",
"kind": 6,
"label": ":main",
"textEdit": Object {
"newText": ":main",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/components/hello.hbs",
],
},
"detail": "component",
"kind": 7,
"label": "Hello",
"textEdit": Object {
"newText": "Hello",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/components/darling.hbs",
],
},
"detail": "component",
"kind": 7,
"label": "Darling",
"textEdit": Object {
"newText": "Darling",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/components/world.hbs",
],
},
"detail": "component",
"kind": 7,
"label": "World",
"textEdit": Object {
"newText": "World",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
]
`;

exports[`integration async fs enabled: false autocomplete works for angle component yielded blocks 1`] = `
Array [
Object {
"detail": "Named block (Slot) for <Darling>",
Expand All @@ -3776,7 +3867,7 @@ Array [
]
`;

exports[`integration async fs enabled: false autocomplete works for multiple angle component slots 1`] = `
exports[`integration async fs enabled: false autocomplete works for multiple angle component yielded blocks 1`] = `
Array [
Object {
"detail": "Named block (Slot) for <Darling>",
Expand Down Expand Up @@ -7306,18 +7397,17 @@ Object {
"resolveProvider": true,
"triggerCharacters": Array [
".",
"::",
":",
"$",
"=",
"/",
"{{",
"{",
"(",
"<",
"@",
"this.",
"<:",
"\\"",
"'",
"#",
],
},
"definitionProvider": true,
Expand Down Expand Up @@ -7588,7 +7678,99 @@ Array [
]
`;

exports[`integration async fs enabled: true autocomplete works for angle component slots 1`] = `
exports[`integration async fs enabled: true autocomplete includes yielded blocks in angle component completions 1`] = `
Array [
Object {
"detail": "Named block (Slot) for <Darling>",
"kind": 6,
"label": ":main",
"textEdit": Object {
"newText": ":main",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/components/hello.hbs",
],
},
"detail": "component",
"kind": 7,
"label": "Hello",
"textEdit": Object {
"newText": "Hello",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/components/darling.hbs",
],
},
"detail": "component",
"kind": 7,
"label": "Darling",
"textEdit": Object {
"newText": "Darling",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
Object {
"data": Object {
"files": Array [
"app/components/world.hbs",
],
},
"detail": "component",
"kind": 7,
"label": "World",
"textEdit": Object {
"newText": "World",
"range": Object {
"end": Object {
"character": 10,
"line": 0,
},
"start": Object {
"character": 10,
"line": 0,
},
},
},
},
]
`;

exports[`integration async fs enabled: true autocomplete works for angle component yielded blocks 1`] = `
Array [
Object {
"detail": "Named block (Slot) for <Darling>",
Expand All @@ -7611,7 +7793,7 @@ Array [
]
`;

exports[`integration async fs enabled: true autocomplete works for multiple angle component slots 1`] = `
exports[`integration async fs enabled: true autocomplete works for multiple angle component yielded blocks 1`] = `
Array [
Object {
"detail": "Named block (Slot) for <Darling>",
Expand Down
24 changes: 22 additions & 2 deletions test/integration-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ describe('integration', function () {
});
});

it('autocomplete works for angle component slots', async () => {
it('autocomplete works for angle component yielded blocks', async () => {
const result = await getResult(
CompletionRequest.method,
connection,
Expand All @@ -1830,7 +1830,7 @@ describe('integration', function () {
expect(result.response).toMatchSnapshot();
});

it('autocomplete works for multiple angle component slots', async () => {
it('autocomplete works for multiple angle component yielded blocks', async () => {
const result = await getResult(
CompletionRequest.method,
connection,
Expand All @@ -1849,6 +1849,26 @@ describe('integration', function () {
expect(result.response).toMatchSnapshot();
});

it('autocomplete includes yielded blocks in angle component completions', async () => {
const result = await getResult(
CompletionRequest.method,
connection,
{
app: {
components: {
'hello.hbs': '<Darling><</Darling>',
'world.hbs': 'Hello World',
'darling.hbs': '{{yield to="main"}}',
},
},
},
'app/components/hello.hbs',
{ line: 0, character: 10 }
);

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

describe('Project class resolution, based on fs path and file structure', () => {
it('able to resolve main project if top-level addon is registered', async () => {
const files = {
Expand Down
Loading