Skip to content

Commit

Permalink
Merge pull request #646 from coq-community/reset-command
Browse files Browse the repository at this point in the history
Plug reset command
  • Loading branch information
rtetley authored Oct 3, 2023
2 parents e83e3a3 + b576b9a commit 92eeb56
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 12 deletions.
4 changes: 4 additions & 0 deletions client/goal-view-ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ const app = () => {
}
);
break;
case 'reset':
setMessages([]);
setGoals(null);
break;
}
}, []);

Expand Down
5 changes: 5 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@
}
],
"commands": [
{
"command": "extension.coq.reset",
"category": "Coq",
"title": "Reset"
},
{
"command": "extension.coq.displayGoals",
"category": "Coq",
Expand Down
19 changes: 19 additions & 0 deletions client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {workspace, window, commands, ExtensionContext,

import {
LanguageClientOptions,
RequestType,
ServerOptions,
TextDocumentIdentifier,
} from 'vscode-languageclient/node';

import Client from './client';
Expand All @@ -23,6 +25,8 @@ import SearchViewProvider from './panels/SearchViewProvider';
import {
MoveCursorNotification,
ProofViewNotification,
ResetCoqRequest,
ResetCoqResponse,
SearchCoqResult
} from './protocol/types';
import {
Expand Down Expand Up @@ -138,6 +142,21 @@ export function activate(context: ExtensionContext) {
searchProvider.launchQuery(queryText, type);
};

registerVscoqTextCommand('reset', (editor) => {
const uri = editor.document.uri;
const textDocument = TextDocumentIdentifier.create(uri.toString());
const params: ResetCoqRequest = {textDocument};
const req = new RequestType<ResetCoqRequest, ResetCoqResponse, void>("vscoq/resetCoq");
Client.writeToVscoq2Channel(uri.toString());
client.sendRequest(req, params).then(
(res) => {
GoalPanel.resetGoalPanel();
},
(err) => {
window.showErrorMessage(err);
}
);
});
registerVscoqTextCommand('query.search', (editor) => launchQuery(editor, "search"));
registerVscoqTextCommand('query.about', (editor) => launchQuery(editor, "about"));
registerVscoqTextCommand('query.check', (editor) => launchQuery(editor, "check"));
Expand Down
19 changes: 18 additions & 1 deletion client/src/panels/GoalPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ export default class GoalPanel {
}
}

// /////////////////////////////////////////////////////////////////////////////
// Change the display setting
//
// /////////////////////////////////////////////////////////////////////////////
public static resetGoalPanel() {

if(GoalPanel.currentPanel) {
Client.writeToVscoq2Channel("[GoalPanel] Resetting goal panel");
GoalPanel.currentPanel._reset();
}

}

// /////////////////////////////////////////////////////////////////////////////
// Create the goal panel if it doesn't exit and then
// handle a proofview notification
Expand All @@ -132,8 +145,12 @@ export default class GoalPanel {

}

private _reset() {
this._panel.webview.postMessage({ "command": "reset"});
};

private _handleProofViewResponseOrNotification(pv: ProofViewNotification) {
this._panel.webview.postMessage({ "command": "renderProofView", "proofView": pv });
this._panel.webview.postMessage({ "command": "renderProofView", "proofView": pv });
};

/**
Expand Down
6 changes: 6 additions & 0 deletions client/src/protocol/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,9 @@ export interface DocumentStateRequest {
export interface DocumentStateResponse {
document: string;
}

export interface ResetCoqRequest {
textDocument: TextDocumentIdentifier;
}

export interface ResetCoqResponse {};
17 changes: 9 additions & 8 deletions language-server/dm/documentManager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,6 @@ let get_messages st pos =
| Some (_oloc,msg) -> (DiagnosticSeverity.Error, pp_of_coqpp msg) :: feedback
| None -> feedback

let reset { uri; opts; init_vs; document; execution_state } =
let text = RawDocument.text @@ Document.raw_document document in
Vernacstate.unfreeze_full_state init_vs;
let document = Document.create_document init_vs.synterp text in
ExecutionManager.destroy execution_state;
let execution_state, feedback = ExecutionManager.init init_vs in
{ uri; opts; init_vs; document; execution_state; observe_id = None }, [inject_em_event feedback]

let interpret_to ~stateful ~background state id : (state * event Sel.Event.t list) =
match Document.get_sentence state.document id with
| None -> (state, []) (* TODO error? *)
Expand Down Expand Up @@ -253,6 +245,15 @@ let init init_vs ~opts uri ~text =
let st = { uri; opts; init_vs; document; execution_state; observe_id = None } in
validate_document st, [inject_em_event feedback]

let reset { uri; opts; init_vs; document; execution_state } =
let text = RawDocument.text @@ Document.raw_document document in
Vernacstate.unfreeze_full_state init_vs;
let document = Document.create_document init_vs.synterp text in
ExecutionManager.destroy execution_state;
let execution_state, feedback = ExecutionManager.init init_vs in
let st = { uri; opts; init_vs; document; execution_state; observe_id = None } in
validate_document st, [inject_em_event feedback]

let apply_text_edits state edits =
let document = Document.apply_text_edits state.document edits in
let shift_diagnostics_locs exec_st (range, new_text) =
Expand Down
2 changes: 1 addition & 1 deletion language-server/protocol/extProtocol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ module Request = struct
module ResetParams = struct

type t = {
uri : DocumentUri.t;
textDocument : TextDocumentIdentifier.t;
} [@@deriving yojson]

end
Expand Down
10 changes: 8 additions & 2 deletions language-server/vscoqtop/lspManager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,18 @@ let textDocumentCompletion id params =
Error(message), []

let coqtopResetCoq id params =
let Request.Client.ResetParams.{ uri } = params in
let Request.Client.ResetParams.{ textDocument = { uri } } = params in
let st = Hashtbl.find states (DocumentUri.to_path uri) in
let st, events = Dm.DocumentManager.reset st in
let (st, events') =
if !check_mode = Settings.Mode.Continuous then
Dm.DocumentManager.interpret_in_background st
else
(st, [])
in
Hashtbl.replace states (DocumentUri.to_path uri) st;
update_view uri st;
Ok(()), (uri,events) |> inject_dm_events
Ok(()), (uri,events@events') |> inject_dm_events

let coqtopInterpretToEnd params =
let Notification.Client.InterpretToEndParams.{ textDocument = { uri } } = params in
Expand Down

0 comments on commit 92eeb56

Please sign in to comment.