Skip to content

Commit

Permalink
chore: remove multi-character triggerCharacters, yielded block comple…
Browse files Browse the repository at this point in the history
…tion (#418)

* fix: remove multi-character triggerCharacters

VSCode ignores these as they should be single characters only

* fix: include yielded blocks in angle bracket completion

Due to trigger characters being limited to a single character
the completion request is triggered when `<` is typed.
At that point both AngleBracketComponents and yielded blocks are relevant.
  • Loading branch information
camerondubas authored Oct 4, 2023
1 parent 9d8019b commit 467ab0d
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 17 deletions.
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

0 comments on commit 467ab0d

Please sign in to comment.