-
Notifications
You must be signed in to change notification settings - Fork 3
/
declarations.ts
51 lines (43 loc) · 1.79 KB
/
declarations.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { SentenceTextRange } from "../../node/container/sentenceEnv";
import { ____Declaration } from "../../node/el/controls/declaration";
export class Declarations {
public db: Map<string, ____Declaration> = new Map();
public filterByRange(sentenceTextRange: SentenceTextRange): Declarations {
const declarations = new Declarations();
for (const declaration of this.db.values()) {
if (
declaration.scope.some(range => (
(
(range.start.sentenceIndex < sentenceTextRange.start.sentenceIndex)
|| (
(range.start.sentenceIndex === sentenceTextRange.start.sentenceIndex)
&& (range.start.textOffset <= sentenceTextRange.start.textOffset)
)
)
&& (
(sentenceTextRange.end.sentenceIndex < range.end.sentenceIndex)
|| (
(sentenceTextRange.end.sentenceIndex === range.end.sentenceIndex)
&& (sentenceTextRange.end.textOffset <= range.end.textOffset)
)
)
))
) {
declarations.add(declaration);
}
}
return declarations;
}
public values(): ____Declaration[] {
return [...this.db.values()].sort((a, b) => -(a.attr.name.length - b.attr.name.length));
}
public add(declaration: ____Declaration): void {
this.db.set(declaration.attr.declarationID, declaration);
}
get length(): number {
return this.db.size;
}
public get(declarationID: string): ____Declaration {
return this.db.get(declarationID) as ____Declaration;
}
}