Skip to content

Commit

Permalink
New docs
Browse files Browse the repository at this point in the history
  • Loading branch information
liuchengxu committed Oct 31, 2023
1 parent d731dc5 commit 90789c1
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 379 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Docs

on:
push:
Expand All @@ -8,7 +8,7 @@ on:

jobs:
build:
name: Build, Test and Deploy
name: Build, Test and Deploy Docs
runs-on: ubuntu-latest
permissions:
contents: write # To push a branch
Expand All @@ -19,8 +19,8 @@ jobs:
with:
toolchain: stable
- run: (test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.4" mdbook)
- run: mdbook build docs && mdbook test docs # In case of custom book path: mdbook build path/to/mybook && mdbook test path/to/mybook
- run: mdbook build docs && mdbook test docs
- uses: JamesIves/github-pages-deploy-action@4.1.7
with:
branch: gh-pages # The branch the action should deploy to.
folder: docs/book # The folder the action should deploy.
branch: gh-pages
folder: docs/book
326 changes: 2 additions & 324 deletions README.md

Large diffs are not rendered by default.

35 changes: 11 additions & 24 deletions crates/maple_core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ impl MatcherConfig {
}
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct PickerConfig {
/// Specifies how many items will be displayed in the results window.
pub max_display_size: Option<usize>,
/// Render the preview highlight with specified theme using syntect backend.
///
/// If the theme is not found, the default theme (`Visual Studio Dark+`) will be used.
pub syntect_highlight_theme: Option<String>,
}

#[derive(Serialize, Deserialize, Debug)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct LogConfig {
Expand Down Expand Up @@ -172,10 +161,10 @@ pub struct LinterPluginConfig {
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct PluginConfig {
pub cursorword: CursorWordConfig,
pub markdown: MarkdownPluginConfig,
pub ctags: CtagsPluginConfig,
pub git: GitPluginConfig,
pub linter: LinterPluginConfig,
pub markdown: MarkdownPluginConfig,
}

#[derive(Serialize, Deserialize, Debug, Default)]
Expand Down Expand Up @@ -215,13 +204,17 @@ pub struct ProviderConfig {
/// Priorities of the ignore config:
/// provider_ignores > provider_ignores > global_ignore
pub ignore: HashMap<String, IgnoreConfig>,
}

#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "kebab-case", default, deny_unknown_fields)]
pub struct InputHistoryConfig {
/// Specifies how many items will be displayed in the results window.
pub max_display_size: Option<usize>,

/// Render the preview highlight with specified theme using syntect backend.
///
/// If the theme is not found, the default theme (`Visual Studio Dark+`) will be used.
pub syntect_highlight_theme: Option<String>,

/// Whether to share the input history of each provider.
pub share_all_inputs: bool,
pub share_input_history: bool,
}

#[derive(Serialize, Deserialize, Debug, Default)]
Expand All @@ -233,9 +226,6 @@ pub struct Config {
/// Matcher configuration.
pub matcher: MatcherConfig,

/// Picker configuration.
pub picker: PickerConfig,

/// Plugin configuration.
pub plugin: PluginConfig,

Expand All @@ -249,9 +239,6 @@ pub struct Config {
///
/// The project path must be specified as absolute path or a path relative to the home directory.
pub project_ignore: HashMap<AbsPathBuf, IgnoreConfig>,

/// Input history configuration
pub input_history: InputHistoryConfig,
}

impl Config {
Expand Down Expand Up @@ -294,7 +281,7 @@ mod tests {
[matcher]
tiebreak = "score,-begin,-end,-length"
[plugin.cursor-word-highlighter]
[plugin.cursorword]
enable = true
[provider.debounce]
Expand Down
2 changes: 1 addition & 1 deletion crates/maple_core/src/stdio_server/handler/on_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ impl<'a> CachedPreviewImpl<'a> {
// 1 (header line) + 1 (1-based line number)
let line_number_offset = context_lines.len() + 1 + 1;
let maybe_line_highlights = if let Some(theme) =
&crate::config::config().picker.syntect_highlight_theme
&crate::config::config().provider.syntect_highlight_theme
{
const THEME: &str = "Visual Studio Dark+";
let theme = if HIGHLIGHTER.theme_exists(theme) {
Expand Down
35 changes: 24 additions & 11 deletions crates/maple_core/src/stdio_server/plugin/markdown.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::stdio_server::input::{AutocmdEvent, PluginAction};
use crate::stdio_server::plugin::ClapPlugin;
use crate::stdio_server::plugin::{ClapPlugin, Toggle};
use crate::stdio_server::vim::Vim;
use anyhow::{anyhow, Result};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -201,26 +201,46 @@ fn find_toc_range(input_file: impl AsRef<Path>) -> std::io::Result<Option<(usize
#[clap_plugin(id = "markdown", actions = ["generate-toc", "update-toc", "delete-toc"])]
pub struct MarkdownPlugin {
vim: Vim,
toggle: Toggle,
}

impl MarkdownPlugin {
pub fn new(vim: Vim) -> Self {
Self { vim }
Self {
vim,
toggle: Toggle::Off,
}
}

async fn update_toc(&self, bufnr: usize) -> Result<()> {
let file = self.vim.bufabspath(bufnr).await?;
if let Some((start, end)) = find_toc_range(&file)? {
let shiftwidth = self.vim.getbufvar("", "&shiftwidth").await?;
// TODO: skip update if the new doc is the same as the old one.
let new_toc = generate_toc(file, start + 1, shiftwidth)?;
self.vim.deletebufline(bufnr, start + 1, end + 1).await?;
self.vim.exec("append_and_write", json!([start, new_toc]))?;
}
Ok(())
}
}

#[async_trait::async_trait]
impl ClapPlugin for MarkdownPlugin {
async fn handle_autocmd(&mut self, _autocmd: AutocmdEvent) -> Result<()> {
if self.toggle.is_off() {
return Ok(());
}

Ok(())
}

async fn handle_action(&mut self, action: PluginAction) -> Result<()> {
let PluginAction { method, params: _ } = action;
match method.as_str() {
Self::GENERATE_TOC => {
let curlnum = self.vim.line(".").await?;
let file = self.vim.current_buffer_path().await?;
let curlnum = self.vim.line(".").await?;
let shiftwidth = self.vim.getbufvar("", "&shiftwidth").await?;
let mut toc = generate_toc(file, curlnum, shiftwidth)?;
let prev_line = self.vim.curbufline(curlnum - 1).await?;
Expand All @@ -231,15 +251,8 @@ impl ClapPlugin for MarkdownPlugin {
.exec("append_and_write", json!([curlnum - 1, toc]))?;
}
Self::UPDATE_TOC => {
let file = self.vim.current_buffer_path().await?;
let bufnr = self.vim.bufnr("").await?;
if let Some((start, end)) = find_toc_range(&file)? {
let shiftwidth = self.vim.getbufvar("", "&shiftwidth").await?;
// TODO: skip update if the new doc is the same as the old one.
let new_toc = generate_toc(file, start + 1, shiftwidth)?;
self.vim.deletebufline(bufnr, start + 1, end + 1).await?;
self.vim.exec("append_and_write", json!([start, new_toc]))?;
}
self.update_toc(bufnr).await?;
}
Self::DELETE_TOC => {
let file = self.vim.current_buffer_path().await?;
Expand Down
2 changes: 1 addition & 1 deletion crates/maple_core/src/stdio_server/provider/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl Context {
};

let input_history = crate::datastore::INPUT_HISTORY_IN_MEMORY.lock();
let inputs = if crate::config::config().input_history.share_all_inputs {
let inputs = if crate::config::config().provider.share_input_history {
input_history.all_inputs()
} else {
input_history.inputs(&env.provider_id)
Expand Down
6 changes: 6 additions & 0 deletions docs/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ Vim-clap was initially written in pure VimScript, but later incorporated a Rust
- While Vim-clap is intended to be compatible with Windows, comprehensive testing on this platform has not been conducted to the same extent as macOS and Linux (specifically Ubuntu), as the plugin author primarily utilizes these operating systems. Consequently, there may be Windows-specific issues yet to be identified. If you encounter any problems on Windows, please [create an issue](https://github.com/liuchengxu/vim-clap/issues/new?assignees=&labels=&template=bug_report.md&title=), and any assistance in addressing these issues would be highly appreciated.

- While Vim-Clap strives to offer equal support for both Vim and NeoVim, certain nuances arise from the differing implementation details between the two. For example, the focusability of Vim's `popup` differs from NeoVim's `floating_win`.

## Credit

- Vim-clap is initially enlightened by [snails](https://github.com/manateelazycat/snails).
- Some providers' idea and code are borrowed from [fzf.vim](https://github.com/junegunn/fzf.vim).
- The built-in fzy python implementation is based on [sweep.py](https://github.com/aslpavel/sweep.py).
44 changes: 32 additions & 12 deletions docs/src/plugins/plugins.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Available Plugins

<!-- clap-markdown-toc -->

* [ctags](#ctags)
* [cursorword](#cursorword)
* [git](#git)
* [linter](#linter)
* [markdown](#markdown)

<!-- /clap-markdown-toc -->

## ctags

- Alternatives
Expand All @@ -12,14 +22,9 @@
enable = true
```

- Features
- highlight the word under the cursor.

- Alternatives
- [vim_current_word](https://github.com/dominikduda/vim_current_word)
- [vim-illuminate](https://github.com/RRethy/vim-illuminate)
- [vim-cursorword](https://github.com/itchyny/vim-cursorword)
- [vim-brightest](https://github.com/osyo-manga/vim-brightest)
| Features | Alternatives |
| :------------------------------------- | :----------------------------------------------------- |
| Highlight the word under the cursor | [nvim-blame-line](https://github.com/tveskag/nvim-blame-line)</br>[vim-illuminate](https://github.com/RRethy/vim-illuminate)</br> [vim-cursorword](https://github.com/itchyny/vim-cursorword)</br>[vim-brightest](https://github.com/osyo-manga/vim-brightest) |

## git

Expand All @@ -28,12 +33,27 @@ enable = true
enable = true
```

| Features | Alternatives |
| :------------------------------------- | :----------------------------------------------------- |
| Show blame info at the end of line | [nvim-blame-line](https://github.com/tveskag/nvim-blame-line) |
| Open the permalink of current line in browser | _none_ |

## linter

```toml
[plugin.linter]
enable = true
```

- Features
- Show blame info at the end of line
- Lint files asynchronously

- Alternatives
- [nvim-blame-line](https://github.com/tveskag/nvim-blame-line)

## linter
- [ale](https://github.com/dense-analysis/ale)

## markdown

```toml
[plugin.markdown]
enable = true
```
45 changes: 44 additions & 1 deletion docs/src/providers/intro.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Clap Providers

<!-- clap-markdown-toc -->

* [Builtin Providers](#builtin-providers)
* [Global Variables](#global-variables)
* [How to Create Your Own Provider](#how-to-create-your-own-provider)
* [Disable Auto-Completion Plugin in Clap Input Window](#disable-auto-completion-plugin-in-clap-input-window)

<!-- /clap-markdown-toc -->


## Builtin Providers

Additional requirement means the potential extra tool needed for the particular provider besides the Rust binary [`maple`](../guide/install_rust.md).
Expand Down Expand Up @@ -54,7 +64,7 @@ Additional requirement means the potential extra tool needed for the particular

[Send a pull request](https://github.com/liuchengxu/vim-clap/pulls) if certain provider is not listed here.

### Global variables
### Global Variables

- `g:clap_layout`: Dict, `{ 'width': '67%', 'height': '33%', 'row': '33%', 'col': '17%' }` by default. This variable controls the size and position of vim-clap window. By default, the vim-clap window is placed relative to the currently active window. To make it relative to the whole editor modify this variable as shown below:

Expand Down Expand Up @@ -89,3 +99,36 @@ The option naming convention for provider is `g:clap_provider_{provider_id}_{opt
- `g:clap_provider_grep_opts`: An empty string by default, allows you to enable flags such as `'--hidden -g "!.git/"'`.

See `:help clap-options` for more information.

## How to Create Your Own Provider

```vim
" `:Clap quick_open` to open some dotfiles quickly.
" `description` is actually optional, but if you want to show this provider
" when you call `:Clap`, the `description` is neccessary.
let g:clap_provider_quick_open = {
\ 'source': ['~/.vimrc', '~/.spacevim', '~/.bashrc', '~/.tmux.conf'],
\ 'sink': 'e',
\ 'description': 'Quick open some dotfiles',
\ }
```

Find more examples at [wiki/Examples](https://github.com/liuchengxu/vim-clap/wiki/Examples).

For complete guide about writing a clap provider please see [PROVIDER.md](PROVIDER.md).

## Disable Auto-Completion Plugin in Clap Input Window

Some of the auto-completion engines need to turn off to prevent bizarre behaviors(#580)

For nvim-completion, add autocmd to your init.vim:

```vim
autocmd FileType clap_input let g:completion_enable_auto_pop = 0
```

For nvim-compe:

```vim
autocmd FileType clap_input call compe#setup({ 'enabled': v:false }, 0)
```

0 comments on commit 90789c1

Please sign in to comment.