@@ -16,6 +16,7 @@ export class UnusedAnchorsValidator implements AdditionalValidator {
1616 const result = [ ] ;
1717 const anchors = new Set < Scalar | YAMLMap | YAMLSeq > ( ) ;
1818 const usedAnchors = new Set < Node > ( ) ;
19+ const unIdentifiedAlias = new Set < Node > ( ) ;
1920 const anchorParent = new Map < Scalar | YAMLMap | YAMLSeq , Node | Pair > ( ) ;
2021
2122 visit ( yamlDoc . internalDocument , ( key , node , path ) => {
@@ -27,7 +28,11 @@ export class UnusedAnchorsValidator implements AdditionalValidator {
2728 anchorParent . set ( node , path [ path . length - 1 ] as Node ) ;
2829 }
2930 if ( isAlias ( node ) ) {
30- usedAnchors . add ( node . resolve ( yamlDoc . internalDocument ) ) ;
31+ if ( ! node . resolve ( yamlDoc . internalDocument ) ) {
32+ unIdentifiedAlias . add ( node ) ;
33+ } else {
34+ usedAnchors . add ( node . resolve ( yamlDoc . internalDocument ) ) ;
35+ }
3136 }
3237 } ) ;
3338
@@ -46,6 +51,17 @@ export class UnusedAnchorsValidator implements AdditionalValidator {
4651 }
4752 }
4853
54+ unIdentifiedAlias . forEach ( ( node ) => {
55+ const nodeRange = node . range ;
56+ if ( nodeRange ) {
57+ const startOffset = nodeRange [ 0 ] ;
58+ const endOffset = nodeRange [ 1 ] ;
59+ const range = Range . create ( document . positionAt ( startOffset ) , document . positionAt ( endOffset ) ) ;
60+ const warningDiagnostic = Diagnostic . create ( range , `Unresolved alias "${ node } "` , DiagnosticSeverity . Hint , 0 ) ;
61+ warningDiagnostic . tags = [ DiagnosticTag . Unnecessary ] ;
62+ result . push ( warningDiagnostic ) ;
63+ }
64+ } ) ;
4965 return result ;
5066 }
5167 private getAnchorNode ( parentNode : YamlNode , node : Node ) : CST . SourceToken | undefined {
0 commit comments