-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementing a collection of `ValidationContributor`s and adding them to the language service through `setValidationContributors` will allow to define custom validation rules.
- Loading branch information
Showing
6 changed files
with
97 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ASTNode } from "./languageTypes"; | ||
|
||
export function getPathSegments(path: string): string[] | null { | ||
const segments = path.split(/[/.]/); | ||
// Skip leading `/` or `.` | ||
if (!segments[0]) return segments.slice(1); | ||
return segments; | ||
} | ||
|
||
export function getNodeFromPath(root: ASTNode, path: string): ASTNode | null { | ||
let segments = getPathSegments(path); | ||
if (!segments) return null; | ||
if (segments.length === 1 && !segments[0]) return null; | ||
let currentNode = root; | ||
while (segments.length) { | ||
const segment = segments[0]; | ||
segments = segments?.slice(1); | ||
if (currentNode.type == "object") { | ||
const property = currentNode.properties.find((p) => p.keyNode.value == segment); | ||
if (property && !segments.length) return property; | ||
if (!property?.valueNode) return null; | ||
if (property.valueNode.type == "object") { | ||
currentNode = property.valueNode; | ||
} else { | ||
return null; | ||
} | ||
} | ||
} | ||
return currentNode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters