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

[code] Add keybindings for sentenceNext / sentencePrevious #718

Merged
merged 2 commits into from
May 17, 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
8 changes: 7 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@
- new VSCode commands to allow to move one sentence backwards /
forward, this is particularly useful when combined with lazy
checking mode (@ejgallego, #671, fixes #263, fixes #580)
- VSCode commands `coq-lsp.sentenceNext` / `coq-lsp.sentencePrevious`
are now bound by default to `Alt + N` / `Alt + P` keybindings
(@ejgallego, #718)
- change diagnostic `extra` field to `data`, so we now conform to the
LSP spec, include the data only when the `send_diags_extra_data`
server-side option is enabled (@ejgallego, #670)
Expand Down Expand Up @@ -135,8 +138,11 @@
the scheduler for the visible area of the document; combined with
the new lazy checking mode, this provides checking on scroll, a
feature inspired from Isabelle IDE (@ejgallego, #717)
- Have VSCode wait for full LSP client shutdown on server restart
- Have VSCode wait for full LSP client shutdown on server
restart. This fixes some bugs on extension restart (finally!)
(@ejgallgo, #719)
- Center the view if cursor goes out of scope in
`sentenceNext/sentencePrevious` (@ejgallego, #718)

# coq-lsp 0.1.8.1: Spring fix
-----------------------------
Expand Down
14 changes: 13 additions & 1 deletion editor/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"title": "Coq LSP: try to jump to next Coq sentence"
},
{
"command": "coq-lsp.sentenceBack",
"command": "coq-lsp.sentencePrevious",
"title": "Coq LSP: try to jump to previous Coq sentence"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also whilst we are here, let's change these to Try same here and above.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or alternatively drop the try and just start with Jump.

Copy link
Owner Author

Choose a reason for hiding this comment

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

The thing is that the command really "tries" to jump, it can fail often.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Let's continue discussion on #699 , I'll be merge it before next release.

},
{
Expand All @@ -125,6 +125,18 @@
"key": "alt+enter",
"mac": "meta+enter",
"when": "editorTextFocus && (editorLangId == coq || editorTextFocus && editorLangId == markdown)"
},
{
"command": "coq-lsp.sentenceNext",
"key": "Alt+N",
"mac": "cmd+N",
"when": "editorTextFocus && (editorLangId == coq || editorTextFocus && editorLangId == markdown)"
},
{
"command": "coq-lsp.sentencePrevious",
"key": "Alt+P",
"mac": "cmd+P",
"when": "editorTextFocus && (editorLangId == coq || editorTextFocus && editorLangId == markdown)"
}
],
"viewsContainers": {
Expand Down
4 changes: 2 additions & 2 deletions editor/code/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { CoqLspClientConfig, CoqLspServerConfig, CoqSelector } from "./config";
import { InfoPanel, goalReq } from "./goals";
import { FileProgressManager } from "./progress";
import { coqPerfData, PerfDataView } from "./perf";
import { sentenceNext, sentenceBack } from "./edit";
import { sentenceNext, sentencePrevious } from "./edit";
import { HeatMap, HeatMapConfig } from "./heatmap";
import { debounce, throttle } from "throttle-debounce";

Expand Down Expand Up @@ -461,7 +461,7 @@ export function activateCoqLSP(
coqEditorCommand("save", saveDocument);

coqEditorCommand("sentenceNext", sentenceNext);
coqEditorCommand("sentenceBack", sentenceBack);
coqEditorCommand("sentencePrevious", sentencePrevious);

coqEditorCommand("heatmap.toggle", heatMapToggle);

Expand Down
24 changes: 20 additions & 4 deletions editor/code/src/edit.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
// Edition facilities for Coq files
import { TextEditor, Position, Range, Selection } from "vscode";
import {
TextEditor,
Position,
Range,
Selection,
TextEditorRevealType,
} from "vscode";

export function sentenceBack(editor: TextEditor) {
function setSelection(editor: TextEditor, newCursor: Position) {
editor.selection = new Selection(newCursor, newCursor);

// Is there not a better way?
editor.revealRange(
new Range(newCursor, newCursor),
TextEditorRevealType.InCenterIfOutsideViewport
);
}

export function sentencePrevious(editor: TextEditor) {
// Slice from the beginning of the document
let cursor = editor.selection.active;
let range = new Range(editor.document.positionAt(0), cursor);
Expand All @@ -19,7 +35,7 @@ export function sentenceBack(editor: TextEditor) {
index = text.lastIndexOf(match) + match.length;
}
let newCursor = editor.document.positionAt(index);
editor.selection = new Selection(newCursor, newCursor);
setSelection(editor, newCursor);
}
}

Expand All @@ -40,6 +56,6 @@ export function sentenceNext(editor: TextEditor) {
let newCursor = editor.document.positionAt(
editor.document.offsetAt(cursor) + index
);
editor.selection = new Selection(newCursor, newCursor);
setSelection(editor, newCursor);
}
}
8 changes: 6 additions & 2 deletions etc/doc/USER_MANUAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ facilities. In VSCode, these settings can be usually displayed in the
### Goal display

By default, `coq-lsp` will follow cursor and show goals at cursor
position. This can be tweaked in options. There are commands to move
one Coq sentence forward / backwards.
position. This can be tweaked in options.

The `coq-lsp.sentenceNext` and `coq-lsp.sentencePrevious` commands will
try to move the cursor one Coq sentence forward / backwards. These
commands are bound by default to `Alt + N` / `Alt + P` (`Cmd` on
MacOS).

### Incremental proof edition

Expand Down
Loading