@@ -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
@@ -39,13 +44,29 @@ export class UnusedAnchorsValidator implements AdditionalValidator {
3944 document . positionAt ( aToken . offset ) ,
4045 document . positionAt ( aToken . offset + aToken . source . length )
4146 ) ;
42- const warningDiagnostic = Diagnostic . create ( range , `Unused anchor "${ aToken . source } "` , DiagnosticSeverity . Hint , 0 ) ;
47+ const warningDiagnostic = Diagnostic . create (
48+ range ,
49+ `Unused anchor "${ aToken . source } "` ,
50+ DiagnosticSeverity . Information ,
51+ 0
52+ ) ;
4353 warningDiagnostic . tags = [ DiagnosticTag . Unnecessary ] ;
4454 result . push ( warningDiagnostic ) ;
4555 }
4656 }
4757 }
4858
59+ unIdentifiedAlias . forEach ( ( node ) => {
60+ const nodeRange = node . range ;
61+ if ( nodeRange ) {
62+ const startOffset = nodeRange [ 0 ] ;
63+ const endOffset = nodeRange [ 1 ] ;
64+ const range = Range . create ( document . positionAt ( startOffset ) , document . positionAt ( endOffset ) ) ;
65+ const warningDiagnostic = Diagnostic . create ( range , `Unresolved alias "${ node } "` , DiagnosticSeverity . Information , 0 ) ;
66+ warningDiagnostic . tags = [ DiagnosticTag . Unnecessary ] ;
67+ result . push ( warningDiagnostic ) ;
68+ }
69+ } ) ;
4970 return result ;
5071 }
5172 private getAnchorNode ( parentNode : YamlNode , node : Node ) : CST . SourceToken | undefined {
0 commit comments