Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting proof view #773

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/goal-view-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@
"preview": "vite preview"
},
"dependencies": {
"@react-hook/resize-observer": "^1.2.6",
"@vscode/codicons": "^0.0.32",
"@vscode/webview-ui-toolkit": "^1.2.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-icons": "^4.7.1"
"react-hook": "^0.0.1",
"react-icons": "^4.7.1",
"uuidv4": "^6.2.13"
},
"devDependencies": {
"@types/react": "^17.0.33",
Expand Down
7 changes: 5 additions & 2 deletions client/goal-view-ui/src/components/atoms/Goal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {FunctionComponent} from 'react';

import classes from './PpString.module.css';
import { PpString } from '../../types';
import { fragmentOfPpString } from '../../utilities/pp';
import PpDisplay from '../../utilities/pp';

type GoalProps = {
goal: PpString,
Expand All @@ -14,7 +14,10 @@ const goal : FunctionComponent<GoalProps> = (props) => {

return (
<div className={classes.Goal}>
{fragmentOfPpString(goal, classes)}
<PpDisplay
pp={goal}
coqCss={classes}
/>
</div>
);
};
Expand Down
8 changes: 5 additions & 3 deletions client/goal-view-ui/src/components/atoms/Hypothesis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {FunctionComponent} from 'react';

import classes from './PpString.module.css';
import { Hyp } from '../../types';
import { fragmentOfPpString } from '../../utilities/pp';
import PpDisplay from '../../utilities/pp';

type HypothesisProps = {
content: Hyp;
Expand All @@ -14,8 +14,10 @@ const hypothesis: FunctionComponent<HypothesisProps> = (props) => {

return (
<div className={classes.Hypothesis}>
<span className={classes.Content}>{fragmentOfPpString(content, classes)}</span>
<br/>
<PpDisplay
pp={content}
coqCss={classes}
/>
</div>
);
};
Expand Down
7 changes: 5 additions & 2 deletions client/goal-view-ui/src/components/atoms/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {FunctionComponent} from 'react';

import classes from './PpString.module.css';
import { MessageSeverity, PpString } from '../../types';
import { fragmentOfPpString } from '../../utilities/pp';
import PpDisplay from '../../utilities/pp';

type MessageProps = {
message: PpString,
Expand Down Expand Up @@ -35,7 +35,10 @@ const message : FunctionComponent<MessageProps> = (props) => {

return (
<span className={classNames.join(' ')}>
{fragmentOfPpString(message, classes)}
<PpDisplay
pp={message}
coqCss={classes}
/>
</span>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
font-weight: var(--vscode-editor-font-weight);
font-size: var(--vscode-editor-font-size);
display: flex;
white-space: pre-wrap;
}

.IdentifierBlock {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.View {
width: 100%;
}
4 changes: 3 additions & 1 deletion client/goal-view-ui/src/components/organisms/GoalTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
import GoalBlock from '../molecules/GoalBlock';
import { Goal } from '../../types';

import classes from './GoalTabs.module.css';

type GoalSectionProps = {
goals: Goal[];
};
Expand Down Expand Up @@ -54,7 +56,7 @@ const goalSection: FunctionComponent<GoalSectionProps> = (props) => {
});

return (
<VSCodePanels>
<VSCodePanels className={classes.View}>
{goalPanelTabs}
{goalPanelViews}
</VSCodePanels>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
flex-direction: column;
width: 100%;
overflow: auto;
}

.View {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const proofViewPage: FunctionComponent<ProofViewPageProps> = (props) => {
];

const views = [
<VSCodePanelView>
<VSCodePanelView className={classes.View}>
<GoalSection
key={"goals"}
goals={goals!.main}
Expand All @@ -55,7 +55,7 @@ const proofViewPage: FunctionComponent<ProofViewPageProps> = (props) => {
}
/>
</VSCodePanelView>,
<VSCodePanelView>
<VSCodePanelView className={classes.View}>
<GoalSection
key="shelved"
goals={goals!.shelved}
Expand All @@ -64,7 +64,7 @@ const proofViewPage: FunctionComponent<ProofViewPageProps> = (props) => {
emptyMessage='There are no shelved goals'
/>
</VSCodePanelView>,
<VSCodePanelView>
<VSCodePanelView className={classes.View}>
<GoalSection
key="givenup"
goals={goals!.givenUp}
Expand All @@ -76,7 +76,7 @@ const proofViewPage: FunctionComponent<ProofViewPageProps> = (props) => {
];

return (
<VSCodePanels>
<VSCodePanels className={classes.View}>
{tabs}
{views}
</VSCodePanels>
Expand Down
63 changes: 59 additions & 4 deletions client/goal-view-ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ type Nullable<T> = T | null;

export type PpTag = string;

export enum PpMode {
horizontal = "Pp_hbox",
vertical = "Pp_vbox",
hvBox = "Pp_hvbox",
hovBox = "Pp_hovbox"
}

export type BlockType =
| ["Pp_hbox"]
| ["Pp_vbox", integer]
| ["Pp_hvbox", integer]
| ["Pp_hovbox", integer];
| [PpMode.horizontal]
| [PpMode.vertical, integer]
| [PpMode.hvBox, integer]
| [PpMode.hovBox, integer];

export type PpBox = ["Ppcmd_box", BlockType, PpString];

export type PpString =
| ["Ppcmd_empty"]
Expand All @@ -21,6 +30,52 @@ export type PpString =

export type Hyp = PpString;

export type FlattenedPpString =
| ["Ppcmd_empty"]
| ["Ppcmd_string", string]
| ["Ppcmd_box", BlockType, PpString[]]
| ["Ppcmd_tag", PpTag, PpString]
| ["Ppcmd_print_break", integer, integer]
| ["Ppcmd_force_newline"]
| ["Ppcmd_comment", string[]];

export enum DisplayType {
box = "box",
term = "term",
break = "break"
}

export type BreakInfo = {
id: string,
offset: number
};

export interface Break {
id: string,
type: DisplayType.break,
offset: number,
mode: PpMode,
horizontalIndent: number,
indent: number,
shouldBreak: boolean,
}

export interface Term {
type: DisplayType.term,
classList: string[],
content: string,
}

export type BoxDisplay = Break | Term | Box | null;

export interface Box {
id: string,
type: DisplayType.box,
mode: PpMode,
indent: number,
boxChildren: BoxDisplay[]
}

export interface Goal {
id: string,
goal: PpString,
Expand Down
20 changes: 20 additions & 0 deletions client/goal-view-ui/src/utilities/Pp.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
.Container {
display:block;
width: 100%;
}

.Content {
white-space: pre;
}

.Box {
display: inline;
}

.Box + .Text {
vertical-align: bottom;
}

.Box + .Tag {
vertical-align: bottom;
}
58 changes: 58 additions & 0 deletions client/goal-view-ui/src/utilities/pp-box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React, {FunctionComponent, useEffect, useState, useLayoutEffect, useRef, ReactFragment} from 'react';
import {Box, DisplayType, BreakInfo} from '../types';
import PpBreak from './pp-break';
import classes from './Pp.module.css';

interface PpBoxProps extends Box {
coqCss: CSSModuleClasses,
breaks: BreakInfo[]
}

const PpBox: FunctionComponent<PpBoxProps> = (props) => {

const {mode, coqCss, id, indent, breaks, boxChildren} = props;

const inner = boxChildren.map(child => {
if(child) {
if (child.type === DisplayType.box) {
return (
<PpBox
type={child.type}
coqCss={coqCss}
id={child.id}
mode={child.mode}
indent={child.indent}
breaks={breaks}
boxChildren={child.boxChildren}
/>
);
} else if (child.type === DisplayType.break) {
const lineBreak = (breaks.find(br => br.id === child.id));
return (
<PpBreak
id={child.id}
offset={lineBreak ? lineBreak.offset : 0}
mode={mode}
horizontalIndent={child.horizontalIndent}
indent={indent}
lineBreak={lineBreak !== undefined}
/>
);
} else {
return (
<span className={child.classList.join(' ')}>
{child.content}
</span>
);
}
}
});

return (
<span id={id} className={classes.Box}>
{inner}
</span>
);
};

export default PpBox;
57 changes: 57 additions & 0 deletions client/goal-view-ui/src/utilities/pp-break.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, {FunctionComponent} from 'react';
import {PpMode} from '../types';

type PpBreakProps = {
id: string,
offset: number,
mode: PpMode,
horizontalIndent: number,
indent: number,
lineBreak: boolean,
};

const ppBreak: FunctionComponent<PpBreakProps> = (props) => {

const {mode, lineBreak, indent, horizontalIndent, id, offset} = props;
const style = {
marginLeft: offset
};

switch(mode) {
case PpMode.horizontal:
return <span id={id}>{" ".repeat(horizontalIndent)}</span>;
case PpMode.vertical:
return (
<span id={id}>
<br/>
<span style={style}>
{" ".repeat(indent ? indent : 0)}
</span>
</span>
);
case PpMode.hvBox:
if(lineBreak) {
<span id={id}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing return here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch ! I think handling hvBoxes correctly stilll needs a bit of work anyways !

<br/>
<span style={style}>
{" ".repeat(indent ? indent : 0)}
</span>
</span>;
}
return <span id={id}> </span>;
case PpMode.hovBox:
if(lineBreak) {
return (
<span id={id}>
<br/>
<span style={style}>
{" ".repeat(indent ? indent : 0)}
</span>
</span>
);
}
return <span id={id}> </span>;
}
};

export default ppBreak;
Loading
Loading