You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there is no mechanism to efficiently refer to specific node in syntax tree for the need of unit test. For example to create Diagnostic.highlights and attach them to a specific node in a syntax tree within diagnostic formatters unit tests. The absence of such a feature makes it cumbersome to identify and highlight syntax nodes for diagnostic or verification purposes.
Introduce a NodeLocator struct to facilitate the process. Below is a proposed implementation idea:
/// Refers to the first node in a syntax tree after `marker` that satisfies `match`.
///
/// For example, if you have
/// ```swift
/// var x: Int
/// 1️⃣func foo() {}
/// ```
///
/// Then `NodeLocator(marker: "1️⃣")` refers to the `CodeBlockItemSyntax` that
/// contains the function declaration and
/// `NodeLocator(marker: "1️⃣", matches: { $0.is(FunctionDeclSyntax.self) })`
/// refers to the function within.
structNodeLocator{letmarker:Stringletmatch:(Syntax)->Bool={ _ intrue}func findNode(in tree:Syntax)->Syntax?{
// TODO: Implement
}}
Note
Before starting implementation, let's discuss this approach here.
This feature could be a significant step towards enabling more precise and easier-to-write unit tests, especially those involving diagnostic highlights.
The text was updated successfully, but these errors were encountered:
For the current needs, I've implemented unit tests to examine how the range of source code to highlight is calculated. The relevant tests can be found here:
Description
Currently, there is no mechanism to efficiently refer to specific node in syntax tree for the need of unit test. For example to create
Diagnostic.highlights
and attach them to a specific node in a syntax tree within diagnostic formatters unit tests. The absence of such a feature makes it cumbersome to identify and highlight syntax nodes for diagnostic or verification purposes.Proposed Solution by @ahoppen:
Introduce a
NodeLocator
struct to facilitate the process. Below is a proposed implementation idea:Note
Before starting implementation, let's discuss this approach here.
This feature could be a significant step towards enabling more precise and easier-to-write unit tests, especially those involving diagnostic highlights.
The text was updated successfully, but these errors were encountered: