Fixed line numbers for diagnostics. Also added a starter graph class so that i can traverse the include tree

This commit is contained in:
Noah Santschi-Cooney 2018-07-31 20:57:23 +01:00
parent 6a484de93e
commit e2d7f8ea3d
No known key found for this signature in database
GPG key ID: 3B22282472C8AE48
2 changed files with 35 additions and 2 deletions

26
server/src/graph.ts Normal file
View file

@ -0,0 +1,26 @@
type Node = {
parents: Map<string, Node>
children: Map<string, Node>
}
export class Graph {
public nodes: Map<string, Node> = new Map()
public hasParents(uri: string): boolean {
return this.nodes.has(uri) ? this.nodes.get(uri).parents.size > 0 : false
}
public setParent(uri: string, parent: string) {
const par: Node = this.nodes.has(parent) ? this.nodes.get(parent) : {parents: new Map(), children: new Map()}
if (this.nodes.has(uri)) {
const node = this.nodes.get(uri)
node.parents.set(parent, par)
par.children.set(uri, node)
} else {
const node: Node = {parents: new Map([par].map(p => [parent, p]) as [string, Node][]), children: new Map()}
par.children.set(uri, node)
this.nodes.set(uri, node)
}
this.nodes.set(parent, par)
}
}