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,13 +6,13 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {AST, Attribute, BoundDirectivePropertyAst, BoundEventAst, CompileTypeSummary, CssSelector, DirectiveAst, ElementAst, SelectorMatcher, TemplateAstPath, findNode, tokenReference} from '@angular/compiler';
|
||||
import {AST, Attribute, BoundDirectivePropertyAst, BoundEventAst, CompileTypeSummary, CssSelector, DirectiveAst, ElementAst, SelectorMatcher, TemplateAstPath, tokenReference} from '@angular/compiler';
|
||||
|
||||
import {AstResult} from './common';
|
||||
import {getExpressionScope} from './expression_diagnostics';
|
||||
import {getExpressionSymbol} from './expressions';
|
||||
import {Definition, DirectiveKind, Span, Symbol} from './types';
|
||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, inSpan, offsetSpan, spanOf} from './utils';
|
||||
import {diagnosticInfoFromTemplateInfo, findTemplateAstAt, getPathToNodeAtPosition, inSpan, offsetSpan, spanOf} from './utils';
|
||||
|
||||
export interface SymbolInfo {
|
||||
symbol: Symbol;
|
||||
@ -144,7 +144,7 @@ export function locateSymbol(info: AstResult, position: number): SymbolInfo|unde
|
||||
|
||||
function findAttribute(info: AstResult, position: number): Attribute|undefined {
|
||||
const templatePosition = position - info.template.span.start;
|
||||
const path = findNode(info.htmlAst, templatePosition);
|
||||
const path = getPathToNodeAtPosition(info.htmlAst, templatePosition);
|
||||
return path.first(Attribute);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user