diff --git a/CHANGES.md b/CHANGES.md index 5cd2ed0b7..542da3648 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,6 +19,8 @@ - Show goals on click by default, allow users to configure the behavior to follow cursor in different ways (@ejgallego, #116, fixes #89) + - Show file position in goal buffer, use collapsible elements for + goal list (@ejgallego, #115, fixes #109) # coq-lsp 0.1.0: Memory ----------------------- diff --git a/controller/coq_lsp.ml b/controller/coq_lsp.ml index 0fa9c222e..bb0605522 100644 --- a/controller/coq_lsp.ml +++ b/controller/coq_lsp.ml @@ -331,7 +331,16 @@ let do_goals ofmt ~id params = let uri, point = get_docTextPosition params in let doc = Hashtbl.find doc_table uri in let goals = Fleche.Info.LC.goals ~doc ~point goals_mode in - let result = `List (mk_goals goals) in + let result = + `Assoc + [ ( "textDocument" + , `Assoc [ ("uri", `String uri); ("version", `Int doc.version) ] ) + ; ( "position" + , `Assoc [ ("line", `Int (fst point)); ("character", `Int (snd point)) ] + ) + ; ("goals", `List (mk_goals goals)) + ] + in let msg = LSP.mk_reply ~id ~result in LIO.send_json ofmt msg diff --git a/editor/code/media/styles.css b/editor/code/media/styles.css index ddf907dc9..691842541 100644 --- a/editor/code/media/styles.css +++ b/editor/code/media/styles.css @@ -1,6 +1,6 @@ body { - font-size:medium; - /* font-size: var(--vscode-editor-font-size); */ + font-size: var(--vscode-editor-font-size); + /* font-size: medium */ font-family: var(--vscode-editor-font-family); /* font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; */ } @@ -23,4 +23,9 @@ body { .sep, hr { color : var(--vscode-editorRuler-foreground); +} + +.goalDiv { + margin-left: 0.5ex; + margin-top: 0.5ex; } \ No newline at end of file diff --git a/editor/code/src/client.ts b/editor/code/src/client.ts index 376e1bd6c..c6cff42f0 100644 --- a/editor/code/src/client.ts +++ b/editor/code/src/client.ts @@ -50,7 +50,7 @@ export function panelFactory(context: ExtensionContext) { } export function activate(context: ExtensionContext): void { - window.showInformationMessage("Going to activate!"); + window.showInformationMessage("Coq LSP Extension: Going to activate!"); function coqCommand(command: string, fn: () => void) { let disposable = commands.registerCommand("coq-lsp." + command, fn); diff --git a/editor/code/src/goals.ts b/editor/code/src/goals.ts index d67ff2bee..57919e45c 100644 --- a/editor/code/src/goals.ts +++ b/editor/code/src/goals.ts @@ -1,3 +1,4 @@ +import { basename } from "path"; import { Webview, Position, Uri, WebviewPanel } from "vscode"; import { RequestType, TextDocumentIdentifier, VersionedTextDocumentIdentifier } from "vscode-languageclient"; import { LanguageClient } from "vscode-languageclient/node"; @@ -12,44 +13,47 @@ interface Goal { } interface GoalRequest { - textDocument: TextDocumentIdentifier, - position: Position + textDocument: TextDocumentIdentifier; + position: Position; } -// returns the HTML code of goals environment -function getGoalsEnvContent(goals: Goal[]) { - if (goals.length == 0) return "No goals"; +interface GoalAnswer { + textDocument: VersionedTextDocumentIdentifier; + position: Position; + goals : Goal[]; +} - return goals - .map((curGoal, itr) => { - return ( - '
' + - curGoal.hyps - .map((hyp) => { - return ( - `` + - `` + - `${hyp.ty}
` - ); - }) - .reduce((acc, cur) => acc + cur, "") + - "
" + - "
" + - `
` + - `` + - `` + - `${curGoal.ty}` + - `

` + - `
` - ); - }) - .reduce((acc, cur) => acc + cur, ""); +function htmlOfHyp(hyp : Hyp) { + let hypBody = + `` + + `` + + `${hyp.ty}
`; + + return `
${hypBody}
`; +} +function htmlOfGoal(goal : Goal, idx : number) { + let hyps = goal.hyps.map(htmlOfHyp).join(' '); + let goalBody = `
${goal.ty}
`; + let summary = `Goal ${idx}`; + return `
${summary}` + + `
${hyps}
${goalBody}
` + + `
`; +} + +// returns the HTML code of goals environment +function htmlOfGoals(goals: Goal[]) { + if (goals.length == 0) + return "No goals" + else + return goals.map(htmlOfGoal).join('
'); } // Returns the HTML code of the panel and the inset ccontent -function buildGoalsContent(goals: Goal[], styleUri: Uri) { +function buildGoalsContent(goals: GoalAnswer, styleUri: Uri) { // get the HTML code of goals environment - let codeEnvGoals: String = getGoalsEnvContent(goals); + let vsUri = Uri.parse(goals.textDocument.uri); + let uriBase = basename(vsUri.path); + let codeEnvGoals: String = htmlOfGoals(goals.goals); // Use #FA8072 color too? return ` @@ -62,9 +66,12 @@ function buildGoalsContent(goals: Goal[], styleUri: Uri) { Goals -

- ${codeEnvGoals} -

+
+ ${uriBase}:${goals.position.line}:${goals.position.character} +
+ ${codeEnvGoals} +
+
`; } @@ -84,7 +91,7 @@ class GoalView { this.sendGoalsRequest(uri, position); } - display(goals: Goal[]) { + display(goals: GoalAnswer) { this.view.html = buildGoalsContent(goals, this.styleUri); } @@ -92,7 +99,7 @@ class GoalView { sendGoalsRequest(uri: Uri, position: Position) { let doc = { uri: uri.toString() }; let cursor : GoalRequest = { textDocument: doc, position: position }; - const req = new RequestType("proof/goals"); + const req = new RequestType("proof/goals"); this.client.sendRequest(req, cursor).then( (goals) => this.display(goals), () => { diff --git a/etc/doc/PROTOCOL.md b/etc/doc/PROTOCOL.md index 9f55d4263..d9ada35cc 100644 --- a/etc/doc/PROTOCOL.md +++ b/etc/doc/PROTOCOL.md @@ -59,8 +59,9 @@ that none of them are stable yet: In order to display proof goals, `coq-lsp` supports the `proof/goals` request, parameters are: ```typescript -{ textDocument: uri -, position: Position +interface GoalRequest { + textDocument: TextDocumentIdentifier; + position: Position; } ``` @@ -70,21 +71,27 @@ interface Hyp { names: string; ty: string; } + interface Goal { ty: string; hyps: Hyp[]; } -interface CoqFileProgressParams { +interface GoalAnswer { + textDocument: VersionedTextDocumentIdentifier; + position: Position; + goals : Goal[]; +} ``` which can be then rendered by the client in way that is desired. -`proof/goals` was first used in the lambdapi-lsp server implementation, and we adapted it. +`proof/goals` was first used in the lambdapi-lsp server implementation, and we adapted it to `coq-lsp`. #### Changelog +- v2: include position and document in the request response - v1: initial version, imported from lambdapi-lsp ### File checking progress