dot-language-support
Advanced tools
Comparing version 1.1.8 to 1.1.9
import { SyntaxNode, Identifier, SyntaxKind, Graph, EdgeStatement, EdgeRhs, SourceFile, SubGraphStatement, NodeId, AttributeStatement, Statement, StatementOf, Token } from "./types"; | ||
export declare function checkSourceFile(file: SourceFile): void; | ||
export declare function findNodeAtOffset(root: SyntaxNode, offset: number): SyntaxNode | undefined; | ||
export declare function findNodeAtOffset(root: SyntaxNode, offset: number, inclusiveEnd?: boolean): SyntaxNode | undefined; | ||
export declare function getAllowedEdgeOperation(graph: Graph): SyntaxKind.DirectedEdgeOp | SyntaxKind.UndirectedEdgeOp; | ||
@@ -5,0 +5,0 @@ export declare function findAllEdges(node: SyntaxNode): EdgeRhs[]; |
@@ -26,20 +26,13 @@ "use strict"; | ||
} | ||
function rangeContainsOffset(range, offset) { | ||
return range.pos <= offset && offset <= range.end; | ||
function rangeContainsOffset(range, offset, inclusiveEnd) { | ||
return inclusiveEnd | ||
? range.pos <= offset && offset <= range.end | ||
: range.pos <= offset && offset < range.end; | ||
} | ||
function findNodeAtOffset(root, offset) { | ||
if (rangeContainsOffset(root, offset)) { | ||
let candidate = root; | ||
visitor_1.forEachChild(root, n => { | ||
const r = findNodeAtOffset(n, offset); | ||
if (r && (candidate.end - candidate.end) < (root.end - root.pos)) | ||
candidate = r; | ||
}, ns => { | ||
for (const n of ns) { | ||
const r = findNodeAtOffset(n, offset); | ||
if (r && (candidate.end - candidate.end) < (root.end - root.pos)) | ||
candidate = r; | ||
} | ||
}); | ||
return candidate; | ||
function findNodeAtOffset(root, offset, inclusiveEnd = false) { | ||
if (root.pos === offset && root.pos === root.end) | ||
return root; | ||
if (rangeContainsOffset(root, offset, inclusiveEnd)) { | ||
const narrowerChild = visitor_1.forEachChild(root, child => findNodeAtOffset(child, offset, inclusiveEnd)); | ||
return narrowerChild ? narrowerChild : root; | ||
} | ||
@@ -46,0 +39,0 @@ return undefined; |
@@ -16,6 +16,6 @@ "use strict"; | ||
const offset = doc.offsetAt(position); | ||
const node = checker_1.findNodeAtOffset(g, offset); | ||
const node = checker_1.findNodeAtOffset(g, offset, true); | ||
if (!node) | ||
return []; | ||
const prevNode = checker_1.findNodeAtOffset(g, node.pos - 1); | ||
const prevNode = checker_1.findNodeAtOffset(g, node.pos - 1, true); | ||
if (!prevNode) | ||
@@ -22,0 +22,0 @@ return []; |
{ | ||
"name": "dot-language-support", | ||
"version": "1.1.8", | ||
"version": "1.1.9", | ||
"description": "Parser and language service for graphviz (dot) files", | ||
@@ -5,0 +5,0 @@ "author": "Niklas Mollenhauer", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157695
4278