Skip to content

Commit ef24c6e

Browse files
committed
Do not use half-formatted goals when copying to comment.
1 parent e54702e commit ef24c6e

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

infoview/goal.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,21 @@ interface GoalProps {
77
plainGoals: PlainGoal;
88
}
99

10+
export function getGoals(plainGoals: PlainGoal): string[] {
11+
if (plainGoals.goals) return plainGoals.goals
12+
const goals: string[] = [];
13+
const r = /```lean\n([^`]*)```/g
14+
let match: RegExpExecArray
15+
const unformatted = plainGoals.rendered;
16+
do {
17+
match = r.exec(unformatted)
18+
if (match) {
19+
goals.push(match[1])
20+
}
21+
} while (match)
22+
return goals;
23+
}
24+
1025
function emphasizeMessage(goal: string): string {
1126
return goal
1227
.replace(/([^`~@$%^&*()-=+\[{\]}\\|;:",.\/\s]+)([¹²³-]*)/g, '<span class="goal-inaccessible">$1$2</span>')
@@ -21,19 +36,7 @@ export function Goal({plainGoals}: GoalProps): JSX.Element {
2136
const [filterIndex, setFilterIndex] = React.useState<number>(config.filterIndex ?? -1);
2237
if (!plainGoals) return null;
2338

24-
let goals = plainGoals.goals;
25-
if (!goals) {
26-
goals = [];
27-
const r = /```lean\n([^`]*)```/g
28-
let match: RegExpExecArray
29-
const unformatted = plainGoals.rendered;
30-
do {
31-
match = r.exec(unformatted)
32-
if (match) {
33-
goals.push(match[1])
34-
}
35-
} while (match)
36-
}
39+
let goals = getGoals(plainGoals);
3740

3841
if (!(reFilters.length === 0 || filterIndex === -1)) {
3942
goals = goals.map((g) =>

infoview/info.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { copyToCommentEvent, copyToComment, pauseEvent, continueEvent, toggleUpdating, serverRestarted, allMessagesEvent, requestPlainGoal, reveal, progressEvent } from './server';
33
import { LocationContext, ConfigContext } from '.';
4-
import { Goal } from './goal';
4+
import { getGoals, Goal } from './goal';
55
import { Messages, processMessages, ProcessedMessage, getMessagesFor } from './messages';
66
import { basename, useEvent } from './util';
77
import { CopyToCommentIcon, PinnedIcon, PinIcon, ContinueIcon, PauseIcon, RefreshIcon, GoToFileIcon } from './svg_icons';
@@ -120,7 +120,9 @@ export function Info(props: InfoProps): JSX.Element {
120120
const {loc, goal, error, loading, messages} = stateRef.current;
121121

122122
function copyGoalToComment() {
123-
if (goal?.rendered) void copyToComment(goal.rendered);
123+
if (goal) {
124+
void copyToComment(getGoals(goal).join('\n\n'));
125+
}
124126
}
125127

126128
// If we are the cursor infoview, then we should subscribe to

0 commit comments

Comments
 (0)