fix(language-service): HTML path should include last node before cursor (#34440)
Given the following HTML and cursor position: ``` <div c|></div> ^ cursor is here ``` Note that the cursor is **after** the attribute `c`. Under the current implementation, only `Element` is included in the path. Instead, it should be `Element -> Attribute`. This bug occurs only for cases where the cursor is right after the Node, and it is because the `end` position of the span is excluded from the search. Instead, the `end` position should be included. PR Close #34440
This commit is contained in:

committed by
Kara Erickson

parent
28b4f4abce
commit
5df8a3ba95
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AST, AstPath, Attribute, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, Element, ElementAst, ImplicitReceiver, NAMED_ENTITIES, Node as HtmlAst, NullTemplateVisitor, ParseSpan, PropertyRead, TagContentType, TemplateBinding, Text, findNode, getHtmlTagDefinition} from '@angular/compiler';
|
||||
import {AST, AstPath, Attribute, BoundDirectivePropertyAst, BoundElementPropertyAst, BoundEventAst, BoundTextAst, Element, ElementAst, ImplicitReceiver, NAMED_ENTITIES, Node as HtmlAst, NullTemplateVisitor, ParseSpan, PropertyRead, TagContentType, TemplateBinding, Text, getHtmlTagDefinition} from '@angular/compiler';
|
||||
import {$$, $_, isAsciiLetter, isDigit} from '@angular/compiler/src/chars';
|
||||
|
||||
import {AstResult} from './common';
|
||||
@ -15,7 +15,7 @@ import {getExpressionCompletions} from './expressions';
|
||||
import {attributeNames, elementNames, eventNames, propertyNames} from './html_info';
|
||||
import {InlineTemplate} from './template';
|
||||
import * as ng from './types';
|
||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, getSelectors, hasTemplateReference, inSpan, spanOf} from './utils';
|
||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, getPathToNodeAtPosition, getSelectors, hasTemplateReference, inSpan, spanOf} from './utils';
|
||||
|
||||
const HIDDEN_HTML_ELEMENTS: ReadonlySet<string> =
|
||||
new Set(['html', 'script', 'noscript', 'base', 'body', 'title', 'head', 'link']);
|
||||
@ -121,7 +121,7 @@ export function getTemplateCompletions(
|
||||
const {htmlAst, template} = templateInfo;
|
||||
// The templateNode starts at the delimiter character so we add 1 to skip it.
|
||||
const templatePosition = position - template.span.start;
|
||||
const path = findNode(htmlAst, templatePosition);
|
||||
const path = getPathToNodeAtPosition(htmlAst, templatePosition);
|
||||
const mostSpecific = path.tail;
|
||||
if (path.empty || !mostSpecific) {
|
||||
result = elementCompletions(templateInfo);
|
||||
|
Reference in New Issue
Block a user