(mappingNode *ast.MappingNode, line, character int)
| 203 | } |
| 204 | |
| 205 | func fragmentReference(mappingNode *ast.MappingNode, line, character int) (*ast.AnchorNode, []*ast.AliasNode) { |
| 206 | anchors, aliases := findFragments(mappingNode, []*ast.AnchorNode{}, []*ast.AliasNode{}) |
| 207 | anchorName := fragmentName(anchors, aliases, line, character) |
| 208 | if anchorName != nil { |
| 209 | var anchor *ast.AnchorNode |
| 210 | matchingAliases := []*ast.AliasNode{} |
| 211 | startLine, endLine := fragmentRange(anchors, *anchorName, line, character) |
| 212 | if startLine != nil { |
| 213 | for i := range anchors { |
| 214 | p := anchors[i].GetToken().Position |
| 215 | if p.Line == startLine.Line && p.Column <= startLine.Column { |
| 216 | // keep iterating so the closest match is always being updated and assigned |
| 217 | anchor = anchors[i] |
| 218 | } |
| 219 | } |
| 220 | for i := range aliases { |
| 221 | if aliases[i].Value.GetToken().Value != *anchorName { |
| 222 | continue |
| 223 | } |
| 224 | if endLine == nil { |
| 225 | p := aliases[i].GetToken().Position |
| 226 | if (startLine.Line == p.Line && startLine.Column < p.Column) || startLine.Line < p.Line { |
| 227 | matchingAliases = append(matchingAliases, aliases[i]) |
| 228 | } |
| 229 | } else { |
| 230 | p := aliases[i].GetToken().Position |
| 231 | if startLine.Line < p.Line { |
| 232 | if p.Line < endLine.Line { |
| 233 | matchingAliases = append(matchingAliases, aliases[i]) |
| 234 | } else if p.Line == endLine.Line && p.Column < endLine.Column { |
| 235 | matchingAliases = append(matchingAliases, aliases[i]) |
| 236 | } |
| 237 | } else if startLine.Line == p.Line { |
| 238 | if startLine.Column < p.Column { |
| 239 | if p.Line == endLine.Line && p.Column < endLine.Column { |
| 240 | matchingAliases = append(matchingAliases, aliases[i]) |
| 241 | } else if p.Line < endLine.Line { |
| 242 | matchingAliases = append(matchingAliases, aliases[i]) |
| 243 | } |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | } else if endLine == nil { |
| 249 | // anchor not defined anywhere, add all the aliases with the matching name |
| 250 | for i := range aliases { |
| 251 | if aliases[i].Value.GetToken().Value == *anchorName { |
| 252 | matchingAliases = append(matchingAliases, aliases[i]) |
| 253 | } |
| 254 | } |
| 255 | } else { |
| 256 | // valid anchor found but defined after the alias that the cursor is on |
| 257 | for i := range aliases { |
| 258 | t := aliases[i].Value.GetToken() |
| 259 | if t.Value == *anchorName { |
| 260 | if t.Position.Line < endLine.Line { |
| 261 | matchingAliases = append(matchingAliases, aliases[i]) |
| 262 | } else if t.Position.Line == endLine.Line && t.Position.Column < endLine.Column { |
no test coverage detected