Files
languageservices/actions-expressions/src/completion/descriptionDictionary.ts
T
2023-01-11 10:59:06 -08:00

33 lines
956 B
TypeScript

import {Dictionary} from "../data/dictionary";
import {ExpressionData, Kind, Pair} from "../data/expressiondata";
export type DescriptionPair = Pair & {description?: string};
export function isDescriptionDictionary(x: ExpressionData): x is DescriptionDictionary {
return x.kind === Kind.Dictionary && x instanceof DescriptionDictionary;
}
export class DescriptionDictionary extends Dictionary {
private readonly descriptions = new Map<string, string>();
constructor(...pairs: DescriptionPair[]) {
super();
for (const p of pairs) {
this.add(p.key, p.value, p.description);
}
}
override add(key: string, value: ExpressionData, description?: string): void {
super.add(key, value);
if (description) {
this.descriptions.set(key, description);
}
}
override pairs(): DescriptionPair[] {
const pairs = super.pairs();
return pairs.map(p => ({...p, description: this.descriptions.get(p.key)}));
}
}