Keen Yee Liau b48cc6ead5 feat(language-service): introduce hybrid visitor to locate AST node (#38540)
This commit introduces two visitors, one for Template AST and the other
for Expression AST to allow us to easily find the node that most closely
corresponds to a given cursor position.

This is crucial because many language service APIs take in a `position`
parameter, and the information returned depends on how well we can find
a good candidate node.

In View Engine implementation of language service, the search for the node
and the processing of information to return the result are strongly coupled.
This makes the code hard to understand and hard to debug because the stack
trace is often littered with layers of visitor calls.

With this new feature, we could test the "searching" part separately and
colocate all the logic (aka hacks) that's required to retrieve an accurate
span for a given node.

Right now, only the most "narrow" node is returned by the main exported
function `findNodeAtPosition`. If needed, we could expose the entire AST
path, or expose other methods to provide more context for a node.

Note that due to limitations in the template AST interface, there are
a few known cases where microsyntax spans are not recorded properly.
This will be dealt with in a follow-up PR.

PR Close #38540
2020-08-24 09:24:18 -07:00

34 lines
919 B
Python

load("//tools:defaults.bzl", "jasmine_node_test", "ts_library")
ts_library(
name = "test_lib",
testonly = True,
srcs = glob(["*.ts"]),
deps = [
"//packages/compiler",
"//packages/language-service/ivy",
"@npm//typescript",
],
)
jasmine_node_test(
name = "test",
data = [
# Note that we used to depend on the npm_package of common, core, and
# forms, but this is no longer the case. We did it for View Engine
# because we wanted to load the flat dts, which is only available in the
# npm_package. Ivy does not currently produce flat dts, so we might
# as well just depend on the outputs of ng_module.
"//packages/common",
"//packages/core",
"//packages/forms",
"//packages/language-service/test:project",
],
tags = [
"ivy-only",
],
deps = [
":test_lib",
],
)