-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontext.ts
More file actions
32 lines (29 loc) · 1.32 KB
/
context.ts
File metadata and controls
32 lines (29 loc) · 1.32 KB
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
import { LJContext } from "../../../types/context";
import { LJDiagnostic, RefinementMismatchError } from "../../../types/diagnostics";
import { renderMainHeader } from "../sections";
import { renderContextAliases } from "./aliases";
import { renderContextGhosts } from "./ghosts";
import { renderContextVariables } from "./variables";
export type ContextSectionState = {
aliases: boolean;
ghosts: boolean;
vars: boolean;
}
export function renderContextView(context: LJContext, currentFile: string, sectionState: ContextSectionState, errorAtCursor?: RefinementMismatchError): string {
if (!context || !currentFile) return "";
const allVars = context.allVars || [];
const ghosts = context.ghosts?.filter(ghost => ghost.file === currentFile) || [];
const aliases = context.aliases || [];
const total = allVars.length + ghosts.length + aliases.length;
return /*html*/`
<div>
${renderMainHeader("", 'context')}
${total === 0
? '<p>No context information available at the cursor position</p>'
: `${renderContextAliases(aliases, sectionState.aliases)}
${renderContextGhosts(ghosts, sectionState.ghosts)}
${renderContextVariables(allVars, sectionState.vars, errorAtCursor)}
`}
</div>
`;
}