forked from niuiic/blink-cmp-rg.nvim
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable toggling the plugin on/off with folke/snacks.nvim (#123)
Issue ===== In some scenarios it's not nice to have blink-ripgrep pop up: - if there are performance issues - when giving a presentation - when recording a video demo Solution ======== Provide a way to toggle the plugin on/off with a keymap. Right now this is off by default and depends on https://github.com/folke/snacks.nvim/blob/main/docs/toggle.md Users that don't want to use this feature or add snacks.nvim can simply ignore it.
- Loading branch information
1 parent
ceae07f
commit eea5060
Showing
6 changed files
with
153 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
integration-tests/cypress/e2e/blink-ripgrep/toggling.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { flavors } from "@catppuccin/palette" | ||
import { rgbify } from "@tui-sandbox/library/dist/src/client/color-utilities" | ||
import { createFakeGitDirectoriesToLimitRipgrepScope } from "./createFakeGitDirectoriesToLimitRipgrepScope" | ||
|
||
describe("toggling features on/off", () => { | ||
// Some features can be toggled on/off without restarting Neovim. This can be | ||
// useful to combat performance issues, for example. | ||
it("can toggle the plugin on/off in blink completions", () => { | ||
cy.visit("/") | ||
cy.startNeovim({ | ||
filename: "limited/main-project-file.lua", | ||
startupScriptModifications: ["enable_toggling.lua"], | ||
}).then((nvim) => { | ||
// when completing from a file in a superproject, the search may descend | ||
// to subprojects | ||
cy.contains("this text is from main-project-file") | ||
createFakeGitDirectoriesToLimitRipgrepScope() | ||
|
||
// first verify that the plugin is enabled | ||
cy.typeIntoTerminal("o") | ||
cy.typeIntoTerminal("some") | ||
|
||
cy.contains("here").should( | ||
"have.css", | ||
"color", | ||
rgbify(flavors.macchiato.colors.green.rgb), | ||
) | ||
|
||
cy.typeIntoTerminal("{esc}") | ||
|
||
// toggle the plugin off and wait for confirmation | ||
cy.typeIntoTerminal("{esc}") | ||
cy.typeIntoTerminal(" tg") | ||
cy.contains("Disabled **blink-ripgrep**") | ||
|
||
// try to complete again | ||
cy.typeIntoTerminal("ciw") | ||
cy.typeIntoTerminal("some") | ||
|
||
nvim | ||
.runLuaCode({ | ||
luaCode: `return _G.blink_ripgrep_invocations`, | ||
}) | ||
.should((result) => { | ||
// ripgrep should only have been invoked once | ||
expect(result.value).to.be.an("array") | ||
const invocations = JSON.stringify(result.value) | ||
expect(invocations).to.contain("ignored-because-mode-is-off") | ||
}) | ||
|
||
// toggle it back on | ||
cy.typeIntoTerminal("{esc}") | ||
cy.typeIntoTerminal(" tg") | ||
cy.contains("Enabled **blink-ripgrep**") | ||
|
||
// try to complete again and verify that the completion is there | ||
cy.typeIntoTerminal("ciw") | ||
cy.typeIntoTerminal("some") | ||
|
||
cy.contains("here").should( | ||
"have.css", | ||
"color", | ||
rgbify(flavors.macchiato.colors.green.rgb), | ||
) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
integration-tests/test-environment/config-modifications/enable_toggling.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require("blink-ripgrep").setup({ | ||
future_features = { | ||
toggles = { | ||
-- mnemonic: toggle grep | ||
on_off = "<leader>tg", | ||
}, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters