Skip to content
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
2 changes: 2 additions & 0 deletions lean4-infoview-api/src/infoviewApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ export type ContextMenuEntry =
| 'copyMessage'
| 'goToPinnedLocation'
| 'goToMessageLocation'
| 'hideTraceSearch'
| 'showTraceSearch'
| 'displayTargetBeforeAssumptions'
| 'displayAssumptionsBeforeTarget'
| 'hideTypeAssumptions'
Expand Down
59 changes: 38 additions & 21 deletions lean4-infoview/src/infoview/messages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,49 @@ const MessageView = React.memo(({ uri, diag }: MessageViewProps) => {
[uri, diag.fullRange, diag.range],
)

const cc = React.useContext(CapabilityContext)
const serverSupportsTraceSearch = cc?.experimental?.rpcProvider?.highlightMatchesProvider !== undefined
const [msg, setMsg] = React.useState<TaggedText<HighlightedMsgEmbed>>(diag.message)
const isMessageWithTraceSearch = serverSupportsTraceSearch && isTraceMessage(msg)
const [isSearchWidgetDisplayed, setSearchWidgetDisplayed] = React.useState(false)
const [traceSearchMessage, setTraceSearchMessage] = React.useState('')

const messageId = React.useId()
useEvent(
ec.events.clickedContextMenu,
async _ => void ec.revealLocation(loc),
[loc],
`goToMessageLocation:${messageId}`,
)
useEvent(
ec.events.clickedContextMenu,
async _ => {
const context: { [k: string]: any } = {}
const useContextMenuEvent = (
name: string,
action: () => void,
isEnabled: boolean,
dependencies?: React.DependencyList,
) => {
if (isEnabled) {
context[name + 'Id'] = messageId
}
useEvent(ec.events.clickedContextMenu, _ => action(), dependencies, `${name}:${messageId}`)
}
useContextMenuEvent('goToMessageLocation', () => void ec.revealLocation(loc), true, [loc])
useContextMenuEvent(
'copyMessage',
() => {
if (node.current) {
void ec.api.copyToClipboard(node.current.innerText)
}
},
true,
[loc],
`copyMessage:${messageId}`,
)

const cc = React.useContext(CapabilityContext)
const serverSupportsTraceSearch = cc?.experimental?.rpcProvider?.highlightMatchesProvider !== undefined
const [msg, setMsg] = React.useState<TaggedText<HighlightedMsgEmbed>>(diag.message)
const [isSearchWidgetDisplayed, setSearchWidgetDisplayed] = React.useState(false)
const [traceSearchMessage, setTraceSearchMessage] = React.useState('')
useContextMenuEvent(
'hideTraceSearch',
() => setSearchWidgetDisplayed(false),
isMessageWithTraceSearch && isSearchWidgetDisplayed,
[],
)
useContextMenuEvent(
'showTraceSearch',
() => setSearchWidgetDisplayed(true),
isMessageWithTraceSearch && !isSearchWidgetDisplayed,
[],
)

const rs = useRpcSessionAtPos(startPos)

Expand All @@ -107,10 +127,7 @@ const MessageView = React.memo(({ uri, diag }: MessageViewProps) => {
}, [rs, traceSearchMessage, diag.message])

return (
<Details
initiallyOpen
data-vscode-context={JSON.stringify({ goToMessageLocationId: messageId, copyMessageId: messageId })}
>
<Details initiallyOpen data-vscode-context={JSON.stringify(context)}>
<span className={severityClass}>
{title}
<span className="fr" onClick={e => e.preventDefault()}>
Expand All @@ -121,7 +138,7 @@ const MessageView = React.memo(({ uri, diag }: MessageViewProps) => {
}}
title="Go to source location of message"
></a>
{serverSupportsTraceSearch && isTraceMessage(msg) && (
{isMessageWithTraceSearch && (
<a
className={
'link pointer mh2 dim codicon ' +
Expand Down
36 changes: 33 additions & 3 deletions vscode-lean4/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,18 @@
"title": "Go to Source Location of Message",
"description": "This command is an implementation detail of the 'Go to Source Location of Message' context menu option in the infoview."
},
{
"command": "lean4.infoview.hideTraceSearch",
"category": "Lean 4: InfoView",
"title": "Hide Search",
"description": "This command is an implementation detail of the 'Hide Search' context menu option in the infoview."
},
{
"command": "lean4.infoview.showTraceSearch",
"category": "Lean 4: InfoView",
"title": "Show Search",
"description": "This command is an implementation detail of the 'Show Search' context menu option in the infoview."
},
{
"command": "lean4.infoview.displayTargetBeforeAssumptions",
"category": "Lean 4: InfoView",
Expand Down Expand Up @@ -979,6 +991,14 @@
"command": "lean4.infoview.goToMessageLocation",
"when": "false"
},
{
"command": "lean4.infoview.hideTraceSearch",
"when": "false"
},
{
"command": "lean4.infoview.showTraceSearch",
"when": "false"
},
{
"command": "lean4.infoview.displayTargetBeforeAssumptions",
"when": "false"
Expand Down Expand Up @@ -1366,20 +1386,30 @@
"when": "webviewId == 'lean4_infoview' && goToMessageLocationId",
"group": "0_term@3"
},
{
"command": "lean4.infoview.hideTraceSearch",
"when": "webviewId == 'lean4_infoview' && hideTraceSearchId",
"group": "0_term@4"
},
{
"command": "lean4.infoview.showTraceSearch",
"when": "webviewId == 'lean4_infoview' && showTraceSearchId",
"group": "0_term@5"
},
{
"command": "lean4.infoview.select",
"when": "webviewId == 'lean4_infoview' && selectableLocationId",
"group": "0_term@4"
"group": "0_term@6"
},
{
"command": "lean4.infoview.unselect",
"when": "webviewId == 'lean4_infoview' && unselectableLocationId",
"group": "0_term@5"
"group": "0_term@7"
},
{
"command": "lean4.infoview.unselectAll",
"when": "webviewId == 'lean4_infoview' && selectedLocationsId",
"group": "0_term@6"
"group": "0_term@8"
},
{
"command": "lean4.infoview.pin",
Expand Down
12 changes: 12 additions & 0 deletions vscode-lean4/src/infoview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,18 @@ export class InfoProvider implements Disposable {
id: args.goToMessageLocationId,
}),
),
commands.registerCommand('lean4.infoview.hideTraceSearch', args =>
this.webviewPanel?.api.clickedContextMenu({
entry: 'hideTraceSearch',
id: args.hideTraceSearchId,
}),
),
commands.registerCommand('lean4.infoview.showTraceSearch', args =>
this.webviewPanel?.api.clickedContextMenu({
entry: 'showTraceSearch',
id: args.showTraceSearchId,
}),
),
commands.registerCommand('lean4.infoview.displayTargetBeforeAssumptions', args =>
this.webviewPanel?.api.clickedContextMenu({
entry: 'displayTargetBeforeAssumptions',
Expand Down
Loading