8000 fix(language-service): Do not provide element completions in end tag … · angular/angular@0e82d42 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0e82d42

Browse files
committed
fix(language-service): Do not provide element completions in end tag (#60616)
Element completions should not be provided when the position is in the end tag or between the start and end tags. fixes angular/vscode-ng-language-service#2157 PR Close #60616
1 parent 8d183ae commit 0e82d42

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

packages/language-service/src/completions.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,14 @@ export class CompletionBuilder<N extends TmplAstNode | AST> {
904904
// Nothing to do without an element to process.
905905
return undefined;
906906
}
907+
if (
908+
element.endSourceSpan &&
909+
isWithin(this.position, element.endSourceSpan) &&
910+
// start and end spans are the same for self closing tags
911+
element.endSourceSpan.start !== element.startSourceSpan.start
912+
) {
913+
return undefined;
914+
}
907915

908916
let replacementSpan: ts.TextSpan | undefined = undefined;
909917
if (

packages/language-service/test/completions_spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,27 @@ describe('completions', () => {
970970
expectContain(completions, DisplayInfoKind.EVENT, ['(click)']);
971971
});
972972

973+
it('should return event completion for self closing tag', () => {
974+
const {templateFile} = setup(`<br />`, ``);
975+
templateFile.moveCursorToText(`<br ¦`);
976+
const completions = templateFile.getCompletionsAtPosition();
977+
expectContain(completions, DisplayInfoKind.EVENT, ['(click)']);
978+
});
979+
980+
it('should not return element completions in end tag', () => {
981+
const {templateFile} = setup(`<button ></button>`, ``);
982+
templateFile.moveCursorToText(`</¦button>`);
983+
const completions = templateFile.getCompletionsAtPosition();
984+
expect(completions).not.toBeDefined();
985+
});
986+
987+
it('should not return element completions in between start and end tag', () => {
988+
const {templateFile} = setup(`<button></button>`, ``);
989+
templateFile.moveCursorToText(`<button>¦</button>`);
990+
const completions = templateFile.getCompletionsAtPosition();
991+
expect(completions).not.toBeDefined();
992+
});
993+
973994
it('should return event completion with empty parens', () => {
974995
const {templateFile} = setup(`<button ()></button>`, ``);
975996
templateFile.moveCursorToText(`<button (¦)>`);

0 commit comments

Comments
 (0)
0