mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 01:05:29 +00:00
Preparing for release with more logging and more safety checks
This commit is contained in:
parent
9660263dad
commit
41cce2121c
8 changed files with 50 additions and 37 deletions
|
@ -1,3 +1,9 @@
|
|||
// can you imagine that some people out there would import a whole library just for this?
|
||||
export type Pair<T, S> = {
|
||||
first: T,
|
||||
second: S
|
||||
}
|
||||
|
||||
type Node = {
|
||||
parents: Map<string, Pair<number, Node>>
|
||||
children: Map<string, Node>
|
||||
|
@ -10,6 +16,11 @@ export class Graph {
|
|||
return this.nodes.has(uri) ? this.nodes.get(uri).parents.size > 0 : false
|
||||
}
|
||||
|
||||
public get(uri: string): Node {
|
||||
if (!this.nodes.has(uri)) this.nodes.set(uri, {parents: new Map(), children: new Map()})
|
||||
return this.nodes.get(uri)
|
||||
}
|
||||
|
||||
public setParent(uri: string, parent: string, lineNum: number) {
|
||||
const par: Node = this.nodes.has(parent) ? this.nodes.get(parent) : {parents: new Map(), children: new Map()}
|
||||
if (this.nodes.has(uri)) {
|
||||
|
@ -17,21 +28,14 @@ export class Graph {
|
|||
node.parents.set(parent, {first: lineNum, second: par})
|
||||
par.children.set(uri, node)
|
||||
} else {
|
||||
const node: Node = {parents: new Map([par].map(p => [parent, {first: lineNum, second: p}]) as [string, Pair<number, Node>][]), children: new Map()}
|
||||
const node: Node = {
|
||||
parents: new Map([par].map(p => [parent, {first: lineNum, second: p}]) as [string, Pair<number, Node>][]),
|
||||
children: new Map()
|
||||
}
|
||||
|
||||
par.children.set(uri, node)
|
||||
this.nodes.set(uri, node)
|
||||
}
|
||||
this.nodes.set(parent, par)
|
||||
}
|
||||
|
||||
public get(uri: string): Node {
|
||||
if (!this.nodes.has(uri)) this.nodes.set(uri, {parents: new Map(), children: new Map()})
|
||||
return this.nodes.get(uri)
|
||||
}
|
||||
}
|
||||
|
||||
// can you imagine that some people out there would import a whole library just for this?
|
||||
export type Pair<T, S> = {
|
||||
first: T,
|
||||
second: S
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue