Skip to content

Commit

Permalink
fix(vim): Add infrastructure for additional mode context (#2362)
Browse files Browse the repository at this point in the history
Some prep work to address #2357 - this plumbs through some additional context for modes, so that we can display it in the status bar and elsewhere. This updates the `Mode` variant to be able to handle contextual state (and updates all the downstream dependencies).

With this change - we'll be able to integrate it with onivim/libvim#218 so we can add some operator pending info for #2357
  • Loading branch information
bryphe committed Aug 26, 2020
1 parent d2a5979 commit 354a87e
Show file tree
Hide file tree
Showing 64 changed files with 306 additions and 247 deletions.
4 changes: 2 additions & 2 deletions integration_test/ClipboardInsertModePasteEmptyTest.re
Expand Up @@ -10,13 +10,13 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

setClipboard(None);
Expand Down
4 changes: 2 additions & 2 deletions integration_test/ClipboardInsertModePasteMultiLineTest.re
Expand Up @@ -10,13 +10,13 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

setClipboard(Some("def\nghi"));
Expand Down
4 changes: 2 additions & 2 deletions integration_test/ClipboardInsertModePasteSingleLineTest.re
Expand Up @@ -10,13 +10,13 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

setClipboard(Some("def"));
Expand Down
2 changes: 1 addition & 1 deletion integration_test/ClipboardNormalModePasteTest.re
Expand Up @@ -19,7 +19,7 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// '*' test case
Expand Down
4 changes: 2 additions & 2 deletions integration_test/ClipboardYankTest.re
Expand Up @@ -37,15 +37,15 @@ runTest(~name="ClipboardYankTest", (dispatch, wait, runEffects) => {

dispatch(KeyboardInput({isText: true, input: "i"}));
wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

dispatch(KeyboardInput({isText: true, input: "abc"}));
dispatch(KeyboardInput({isText: false, input: "<esc>"}));
runEffects();

wait(~name="Mode switches back to normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

setClipboard(None);
Expand Down
2 changes: 1 addition & 1 deletion integration_test/EchoNotificationTest.re
Expand Up @@ -3,7 +3,7 @@ open Oni_IntegrationTestLib;

runTest(~name="EchoNotificationTest", (dispatch, wait, _runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(VimExecuteCommand("echo 'hi from test'"));
Expand Down
2 changes: 1 addition & 1 deletion integration_test/EditorFontFromPathTest.re
Expand Up @@ -16,7 +16,7 @@ runTest(
~name="EditorFontFromPath",
(_, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

print_endline("Using font: " ++ font);
Expand Down
2 changes: 1 addition & 1 deletion integration_test/EditorFontValidTest.re
Expand Up @@ -23,7 +23,7 @@ if (Revery.Environment.os !== Revery.Environment.Linux) {
~name="EditorFontValid",
(_, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

wait(
Expand Down
2 changes: 1 addition & 1 deletion integration_test/EditorUtf8Test.re
Expand Up @@ -7,7 +7,7 @@ open Feature_Editor;

runTestWithInput(~name="EditorUtf8Test", (input, dispatch, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let testFile = getAssetPath("utf8.txt");
Expand Down
2 changes: 1 addition & 1 deletion integration_test/ExtHostBufferOpenTest.re
Expand Up @@ -10,7 +10,7 @@ module TS = TextSynchronization;
runTestWithInput(
~name="ExtHostBufferOpen", (_input, dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// Wait until the extension is activated
Expand Down
2 changes: 1 addition & 1 deletion integration_test/ExtHostBufferUpdatesTest.re
Expand Up @@ -11,7 +11,7 @@ module TS = TextSynchronization;
runTestWithInput(
~name="ExtHostBufferUpdates", (input, dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// Wait until the extension is activated
Expand Down
2 changes: 1 addition & 1 deletion integration_test/ExtHostCompletionTest.re
Expand Up @@ -8,7 +8,7 @@ open Oni_IntegrationTestLib;
runTestWithInput(
~name="ExtHostCompletionTest", (input, dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// Wait until the extension is activated
Expand Down
2 changes: 1 addition & 1 deletion integration_test/ExtHostDefinitionTest.re
Expand Up @@ -9,7 +9,7 @@ open Feature_Editor;
runTestWithInput(
~name="ExtHostDefinitionTest", (input, dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// Wait until the extension is activated
Expand Down
2 changes: 1 addition & 1 deletion integration_test/FontSizeChangeTest.re
Expand Up @@ -4,7 +4,7 @@ open Oni_IntegrationTestLib;
// Validate that change the font size via config results in new metrics
runTest(~name="FontSizeChangeTest", (dispatch, wait, runEffects) => {
wait(~name="Mode switches back to normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

wait(~name="Set configuration to small font size", (state: State.t) => {
Expand Down
4 changes: 2 additions & 2 deletions integration_test/InputIgnoreTest.re
Expand Up @@ -7,13 +7,13 @@ module Log = (val Log.withNamespace("IntegrationTest.inputIgnore"));
// This test validates that certain keystrokes are ignored by our Vim layer
runTest(~name="InputIgnore test", (dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

dispatch(KeyboardInput({isText: false, input: "<D-A->"}));
Expand Down
4 changes: 2 additions & 2 deletions integration_test/InsertModeTest.re
Expand Up @@ -3,12 +3,12 @@ open Oni_IntegrationTestLib;

runTest(~name="InsertMode test", (dispatch, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);
});
6 changes: 3 additions & 3 deletions integration_test/KeySequenceJJTest.re
Expand Up @@ -13,7 +13,7 @@ runTest(
~name="KeySequenceJJTest",
(dispatch, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let input = key => {
Expand All @@ -31,14 +31,14 @@ runTest(

input("i");
wait(~name="Mode is now insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

input("j");
input("j");

wait(~name="Mode is back to normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);
// TODO: Figure out why this check is failing...
wait(~name="Validate buffer is empty", (state: State.t) => {
Expand Down
2 changes: 1 addition & 1 deletion integration_test/KeybindingsInvalidJsonTest.re
Expand Up @@ -10,7 +10,7 @@ runTest(
~name="KeybindingsInvalidJson",
(_dispatch, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let getErrorNotificationCount = (state: State.t) => {
Expand Down
2 changes: 1 addition & 1 deletion integration_test/LanguageCssTest.re
Expand Up @@ -9,7 +9,7 @@ open Feature_LanguageSupport;
runTestWithInput(
~name="LanguageCssTest", (input, dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

ExtensionHelpers.waitForExtensionToActivate(
Expand Down
2 changes: 1 addition & 1 deletion integration_test/LanguageTypeScriptTest.re
Expand Up @@ -6,7 +6,7 @@ open Feature_LanguageSupport;
runTestWithInput(
~name="LanguageTypeScriptTest", (input, dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

ExtensionHelpers.waitForExtensionToActivate(
Expand Down
2 changes: 1 addition & 1 deletion integration_test/LineEndingsCRLFTest.re
Expand Up @@ -5,7 +5,7 @@ open Oni_IntegrationTestLib;

runTest(~name="LineEndingsCRLFTest", (dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let testFile = getAssetPath("test.crlf");
Expand Down
2 changes: 1 addition & 1 deletion integration_test/LineEndingsLFTest.re
Expand Up @@ -5,7 +5,7 @@ open Oni_IntegrationTestLib;

runTest(~name="LineEndingsLFTest", (dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let testFile = getAssetPath("test.lf");
Expand Down
2 changes: 1 addition & 1 deletion integration_test/QuickOpenEventuallyCompletesTest.re
Expand Up @@ -3,7 +3,7 @@ open Oni_IntegrationTestLib;

runTest(~name="QuickOpen eventually completes", (dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

/* Switch to root directory */
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Regression1671Test.re
Expand Up @@ -8,7 +8,7 @@ runTestWithInput(
~name="Regression1671 - Opening new buffer loses changes in previous buffer",
(input, _dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

input(":e a-test-file");
Expand Down
2 changes: 1 addition & 1 deletion integration_test/Regression2349EnewTest.re
Expand Up @@ -3,7 +3,7 @@ open Oni_IntegrationTestLib;

runTest(~name="Regression: Command line no completions", (dispatch, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let initialEditorId = ref(None);
Expand Down
4 changes: 2 additions & 2 deletions integration_test/RegressionCommandLineNoCompletionTest.re
Expand Up @@ -3,13 +3,13 @@ open Oni_IntegrationTestLib;

runTest(~name="Regression: Command line no completions", (dispatch, wait, _) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: ":"}));

wait(~name="Mode switches to command line", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.CommandLine
Feature_Vim.mode(state.vim) == Vim.Mode.CommandLine
);

dispatch(KeyboardInput({isText: true, input: "e"}));
Expand Down
2 changes: 1 addition & 1 deletion integration_test/RegressionFileModifiedIndicationTest.re
Expand Up @@ -10,7 +10,7 @@ runTestWithInput(
~name="RegressionFileModifiedIndication",
(input, dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

let initialBuffer = Vim.Buffer.getCurrent();
Expand Down
2 changes: 1 addition & 1 deletion integration_test/SCMGitTest.re
Expand Up @@ -3,7 +3,7 @@ open Oni_IntegrationTestLib;

runTest(~name="SCMGitTest", (_dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// For now... just validate that the extension activated
Expand Down
4 changes: 2 additions & 2 deletions integration_test/SearchShowClearHighlightsTest.re
Expand Up @@ -7,14 +7,14 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

// Edit
dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

dispatch(KeyboardInput({isText: true, input: "a"}));
Expand Down
2 changes: 1 addition & 1 deletion integration_test/SyntaxHighlightTextMateTest.re
Expand Up @@ -5,7 +5,7 @@ open Oni_IntegrationTestLib;
// Validate that textmate highlight runs
runTest(~name="SyntaxHighlightTextMateTest", (dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);
wait(~name="Wait for syntax server", ~timeout=10.0, (state: State.t) => {
Feature_Syntax.isSyntaxServerRunning(state.syntaxHighlights)
Expand Down
2 changes: 1 addition & 1 deletion integration_test/SyntaxHighlightTreesitterTest.re
Expand Up @@ -12,7 +12,7 @@ runTest(
~name="SyntaxHighlightTreesitterTest",
(dispatch, wait, _runEffects) => {
wait(~name="Capture initial state", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

wait(~name="Wait for syntax server", ~timeout=10.0, (state: State.t) => {
Expand Down
4 changes: 2 additions & 2 deletions integration_test/TypingBatchedTest.re
Expand Up @@ -8,13 +8,13 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

/* Simulate multiple events getting dispatched before running effects */
Expand Down
4 changes: 2 additions & 2 deletions integration_test/TypingUnbatchedTest.re
Expand Up @@ -8,13 +8,13 @@ runTest(
~name="InsertMode test - effects batched to runEffects",
(dispatch, wait, runEffects) => {
wait(~name="Initial mode is normal", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Normal
Feature_Vim.mode(state.vim) == Vim.Mode.Normal
);

dispatch(KeyboardInput({isText: true, input: "i"}));

wait(~name="Mode switches to insert", (state: State.t) =>
Feature_Vim.mode(state.vim) == Vim.Types.Insert
Feature_Vim.mode(state.vim) == Vim.Mode.Insert
);

/* Simulate multiple events getting dispatched before running effects */
Expand Down

0 comments on commit 354a87e

Please sign in to comment.