diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 737538ae..f7430d03 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -47,7 +47,14 @@ jobs: with: file_pattern: README.md doc/crates.txt commit_message: "chore: generate docs" - + + - name: Upload Documentation to Wiki + uses: SwiftDocOrg/github-wiki-publish-action@v1 + with: + path: scripts/wiki + env: + GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + test: runs-on: ubuntu-latest steps: diff --git a/README.md b/README.md index adde890e..a5748c9c 100644 --- a/README.md +++ b/README.md @@ -8,32 +8,6 @@ Feel free to open issues. [Screencast from 2023-03-11 05-29-22.webm](https://user-images.githubusercontent.com/43008152/224464963-9810110f-2923-4346-a442-9d4f2723bdff.webm) -## Features -- Complete crate versions and features -- Completion sources for: - - [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) - - [coq.nvim](https://github.com/ms-jpq/coq_nvim) -- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) code actions -- Update crates to newest compatible version -- Upgrade crates to newest version -- Respect existing version requirements and update them in an elegant way (`smart_insert`) -- Automatically load when opening a `Cargo.toml` file (`autoload`) -- Live update while editing (`autoupdate`) -- Show version and upgrade candidates - - Indicate if compatible version is a pre-release or yanked - - Indicate if no version is compatible -- Open floating window with crate info - - Open documentation, crates.io, repository and homepage urls -- Open floating window with crate versions - - Select a version by pressing enter (`popup.keys.select`) -- Open floating window with crate features - - Navigate the feature hierarchy - - Enable/disable features - - Indicate if a feature is enabled directly or transitively -- Open floating window with crate dependencies - - Navigate the dependency hierarchy - - Indicate if a dependency is optional - ## Setup ### Installation @@ -42,7 +16,7 @@ To use a stable release. [__vim-plug__](https://github.com/junegunn/vim-plug) ``` Plug 'nvim-lua/plenary.nvim' -Plug 'saecki/crates.nvim', { 'tag': 'v0.4.0' } +Plug 'saecki/crates.nvim', { 'tag': 'stable' } lua require('crates').setup() ``` @@ -51,7 +25,7 @@ lua require('crates').setup() ```lua { 'saecki/crates.nvim', - tag = 'v0.4.0', + tag = 'stable', dependencies = { 'nvim-lua/plenary.nvim' }, config = function() require('crates').setup() @@ -98,460 +72,9 @@ lua require('crates').setup() ``` -### Auto completion -#### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source - -Enable it in the setup. -```lua -require('crates').setup { - ... - src = { - ... - cmp = { - enabled = true, - }, - }, -} -``` - -And add it to your list of sources. -```lua -require('cmp').setup { - ... - sources = { - { name = "path" }, - { name = "buffer" }, - { name = "nvim_lsp" }, - ... - { name = "crates" }, - }, -} -``` - -
-Or add it lazily. - -```lua -vim.api.nvim_create_autocmd("BufRead", { - group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }), - pattern = "Cargo.toml", - callback = function() - cmp.setup.buffer({ sources = { { name = "crates" } } }) - end, -}) -``` -
- -#### [coq.nvim](https://github.com/ms-jpq/coq_nvim) source -Enable it in the setup, and optionally change the display name. -```lua -require('crates').setup { - ... - src = { - ... - coq = { - enabled = true, - name = "crates.nvim", - }, - }, -} -``` - -### Code actions -#### [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) source -Enable it in the setup, and optionally change the display name. -```lua -local null_ls = require('null-ls') -require('crates').setup { - ... - null_ls = { - enabled = true, - name = "crates.nvim", - }, -} -``` - -## Config - -For more information about the type of some fields see [`teal/crates/config.tl`](teal/crates/config.tl). - -### Default - -The icons in the default configuration require a patched font.
-Any [Nerd Font](https://www.nerdfonts.com/font-downloads) should work. -```lua -require('crates').setup { - smart_insert = true, - insert_closing_quote = true, - avoid_prerelease = true, - autoload = true, - autoupdate = true, - autoupdate_throttle = 250, - loading_indicator = true, - date_format = "%Y-%m-%d", - thousands_separator = ".", - notification_title = "Crates", - curl_args = { "-sL", "--retry", "1" }, - max_parallel_requests = 80, - expand_crate_moves_cursor = true, - open_programs = { "xdg-open", "open" }, - disable_invalid_feature_diagnostic = false, - enable_update_available_warning = true, - text = { - loading = "  Loading", - version = "  %s", - prerelease = "  %s", - yanked = "  %s", - nomatch = "  No match", - upgrade = "  %s", - error = "  Error fetching crate", - }, - highlight = { - loading = "CratesNvimLoading", - version = "CratesNvimVersion", - prerelease = "CratesNvimPreRelease", - yanked = "CratesNvimYanked", - nomatch = "CratesNvimNoMatch", - upgrade = "CratesNvimUpgrade", - error = "CratesNvimError", - }, - popup = { - autofocus = false, - hide_on_select = false, - copy_register = '"', - style = "minimal", - border = "none", - show_version_date = false, - show_dependency_version = true, - max_height = 30, - min_width = 20, - padding = 1, - text = { - title = " %s", - pill_left = "", - pill_right = "", - description = "%s", - created_label = " created ", - created = "%s", - updated_label = " updated ", - updated = "%s", - downloads_label = " downloads ", - downloads = "%s", - homepage_label = " homepage ", - homepage = "%s", - repository_label = " repository ", - repository = "%s", - documentation_label = " documentation ", - documentation = "%s", - crates_io_label = " crates.io ", - crates_io = "%s", - categories_label = " categories ", - keywords_label = " keywords ", - version = " %s", - prerelease = " %s", - yanked = " %s", - version_date = " %s", - feature = " %s", - enabled = " %s", - transitive = " %s", - normal_dependencies_title = " Dependencies", - build_dependencies_title = " Build dependencies", - dev_dependencies_title = " Dev dependencies", - dependency = " %s", - optional = " %s", - dependency_version = " %s", - loading = "  ", - }, - highlight = { - title = "CratesNvimPopupTitle", - pill_text = "CratesNvimPopupPillText", - pill_border = "CratesNvimPopupPillBorder", - description = "CratesNvimPopupDescription", - created_label = "CratesNvimPopupLabel", - created = "CratesNvimPopupValue", - updated_label = "CratesNvimPopupLabel", - updated = "CratesNvimPopupValue", - downloads_label = "CratesNvimPopupLabel", - downloads = "CratesNvimPopupValue", - homepage_label = "CratesNvimPopupLabel", - homepage = "CratesNvimPopupUrl", - repository_label = "CratesNvimPopupLabel", - repository = "CratesNvimPopupUrl", - documentation_label = "CratesNvimPopupLabel", - documentation = "CratesNvimPopupUrl", - crates_io_label = "CratesNvimPopupLabel", - crates_io = "CratesNvimPopupUrl", - categories_label = "CratesNvimPopupLabel", - keywords_label = "CratesNvimPopupLabel", - version = "CratesNvimPopupVersion", - prerelease = "CratesNvimPopupPreRelease", - yanked = "CratesNvimPopupYanked", - version_date = "CratesNvimPopupVersionDate", - feature = "CratesNvimPopupFeature", - enabled = "CratesNvimPopupEnabled", - transitive = "CratesNvimPopupTransitive", - normal_dependencies_title = "CratesNvimPopupNormalDependenciesTitle", - build_dependencies_title = "CratesNvimPopupBuildDependenciesTitle", - dev_dependencies_title = "CratesNvimPopupDevDependenciesTitle", - dependency = "CratesNvimPopupDependency", - optional = "CratesNvimPopupOptional", - dependency_version = "CratesNvimPopupDependencyVersion", - loading = "CratesNvimPopupLoading", - }, - keys = { - hide = { "q", "" }, - open_url = { "" }, - select = { "" }, - select_alt = { "s" }, - toggle_feature = { "" }, - copy_value = { "yy" }, - goto_item = { "gd", "K", "" }, - jump_forward = { "" }, - jump_back = { "", "" }, - }, - }, - src = { - insert_closing_quote = true, - text = { - prerelease = "  pre-release ", - yanked = "  yanked ", - }, - cmp = { - enabled = false, - use_custom_kind = true, - kind_text = { - version = "Version", - feature = "Feature", - }, - kind_highlight = { - version = "CmpItemKindVersion", - feature = "CmpItemKindFeature", - }, - }, - coq = { - enabled = false, - name = "Crates", - }, - }, - null_ls = { - enabled = false, - name = "Crates", - }, - on_attach = function(bufnr) end, -} -``` - -### Plain text - -Replace these fields if you don't have a patched font. -```lua -require('crates').setup { - text = { - loading = " Loading...", - version = " %s", - prerelease = " %s", - yanked = " %s yanked", - nomatch = " Not found", - upgrade = " %s", - error = " Error fetching crate", - }, - popup = { - text = { - title = "# %s", - pill_left = "", - pill_right = "", - created_label = "created ", - updated_label = "updated ", - downloads_label = "downloads ", - homepage_label = "homepage ", - repository_label = "repository ", - documentation_label = "documentation ", - crates_io_label = "crates.io ", - categories_label = "categories ", - keywords_label = "keywords ", - version = "%s", - prerelease = "%s pre-release", - yanked = "%s yanked", - enabled = "* s", - transitive = "~ s", - normal_dependencies_title = " Dependencies", - build_dependencies_title = " Build dependencies", - dev_dependencies_title = " Dev dependencies", - optional = "? %s", - loading = " ...", - }, - }, - src = { - text = { - prerelease = " pre-release ", - yanked = " yanked ", - }, - }, -} -``` - -### Functions -```lua --- Setup config and auto commands. -require('crates').setup(cfg: Config) - --- Disable UI elements (virtual text and diagnostics). -require('crates').hide() --- Enable UI elements (virtual text and diagnostics). -require('crates').show() --- Enable or disable UI elements (virtual text and diagnostics). -require('crates').toggle() --- Update data. Optionally specify which `buf` to update. -require('crates').update(buf: integer|nil) --- Reload data (clears cache). Optionally specify which `buf` to reload. -require('crates').reload(buf: integer|nil) - --- Upgrade the crate on the current line. --- If the `alt` flag is passed as true, the opposite of the `smart_insert` config --- option will be used to insert the version. -require('crates').upgrade_crate(alt: boolean|nil) --- Upgrade the crates on the lines visually selected. --- See `crates.upgrade_crate()`. -require('crates').upgrade_crates(alt: boolean|nil) --- Upgrade all crates in the buffer. --- See `crates.upgrade_crate()`. -require('crates').upgrade_all_crates(alt: boolean|nil) - --- Update the crate on the current line. --- See `crates.upgrade_crate()`. -require('crates').update_crate(alt: boolean|nil) --- Update the crates on the lines visually selected. --- See `crates.upgrade_crate()`. -require('crates').update_crates(alt: boolean|nil) --- Update all crates in the buffer. --- See `crates.upgrade_crate()`. -require('crates').update_all_crates(alt: boolean|nil) - --- Expand a plain crate declaration into an inline table. -require('crates').expand_plain_crate_to_inline_table() --- Extract an crate declaration from a dependency section into a table. -require('crates').extract_crate_into_table() - --- Open the homepage of the crate on the current line. -require('crates').open_homepage() --- Open the repository page of the crate on the current line. -require('crates').open_repository() --- Open the documentation page of the crate on the current line. -require('crates').open_documentation() --- Open the `crates.io` page of the crate on the current line. -require('crates').open_crates_io() - --- Returns whether there is information to show in a popup. -require('crates').popup_available(): boolean --- Show/hide popup with crate details, all versions, all features or details about one feature. --- If `popup.autofocus` is disabled calling this again will focus the popup. -require('crates').show_popup() --- Same as `crates.show_popup()` but always show crate details. -require('crates').show_crate_popup() --- Same as `crates.show_popup()` but always show versions. -require('crates').show_versions_popup() --- Same as `crates.show_popup()` but always show features or features details. -require('crates').show_features_popup() --- Same as `crates.show_popup()` but always show depedencies. -require('crates').show_dependencies_popup() --- Focus the popup (jump into the floating window). --- Optionally specify the line to jump to, inside the popup. -require('crates').focus_popup(line: integer|nil) --- Hide the popup. -require('crates').hide_popup() -``` - -### Key mappings -Some examples of key mappings. -```lua -local crates = require('crates') -local opts = { silent = true } - -vim.keymap.set('n', 'ct', crates.toggle, opts) -vim.keymap.set('n', 'cr', crates.reload, opts) - -vim.keymap.set('n', 'cv', crates.show_versions_popup, opts) -vim.keymap.set('n', 'cf', crates.show_features_popup, opts) -vim.keymap.set('n', 'cd', crates.show_dependencies_popup, opts) - -vim.keymap.set('n', 'cu', crates.update_crate, opts) -vim.keymap.set('v', 'cu', crates.update_crates, opts) -vim.keymap.set('n', 'ca', crates.update_all_crates, opts) -vim.keymap.set('n', 'cU', crates.upgrade_crate, opts) -vim.keymap.set('v', 'cU', crates.upgrade_crates, opts) -vim.keymap.set('n', 'cA', crates.upgrade_all_crates, opts) - -vim.keymap.set('n', 'ce', crates.expand_plain_crate_to_inline_table, opts) -vim.keymap.set('n', 'cE', crates.extract_crate_into_table, opts) - -vim.keymap.set('n', 'cH', crates.open_homepage, opts) -vim.keymap.set('n', 'cR', crates.open_repository, opts) -vim.keymap.set('n', 'cD', crates.open_documentation, opts) -vim.keymap.set('n', 'cC', crates.open_crates_io, opts) -``` - -
-In vimscript - -```vim -nnoremap ct :lua require('crates').toggle() -nnoremap cr :lua require('crates').reload() - -nnoremap cv :lua require('crates').show_versions_popup() -nnoremap cf :lua require('crates').show_features_popup() -nnoremap cd :lua require('crates').show_dependencies_popup() - -nnoremap cu :lua require('crates').update_crate() -vnoremap cu :lua require('crates').update_crates() -nnoremap ca :lua require('crates').update_all_crates() -nnoremap cU :lua require('crates').upgrade_crate() -vnoremap cU :lua require('crates').upgrade_crates() -nnoremap cA :lua require('crates').upgrade_all_crates() - -nnoremap ce :lua require('crates').expand_plain_crate_to_inline_table() -nnoremap cE :lua require('crates').extract_crate_into_table() - -nnoremap cH :lua require('crates').open_homepage() -nnoremap cR :lua require('crates').open_repository() -nnoremap cD :lua require('crates').open_documentation() -nnoremap cC :lua require('crates').open_crates_io() -``` -
- -### Show appropriate documentation in `Cargo.toml` -How you might integrate `show_popup` into your `init.vim`. -```vim -nnoremap K :call show_documentation() -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - elseif (index(['man'], &filetype) >= 0) - execute 'Man '.expand('') - elseif (expand('%:t') == 'Cargo.toml' && luaeval('require("crates").popup_available()')) - lua require('crates').show_popup() - else - lua vim.lsp.buf.hover() - endif -endfunction -``` - -How you might integrate `show_popup` into your `init.lua`. -```lua -local function show_documentation() - local filetype = vim.bo.filetype - if vim.tbl_contains({ 'vim','help' }, filetype) then - vim.cmd('h '..vim.fn.expand('')) - elseif vim.tbl_contains({ 'man' }, filetype) then - vim.cmd('Man '..vim.fn.expand('')) - elseif vim.fn.expand('%:t') == 'Cargo.toml' and require('crates').popup_available() then - require('crates').show_popup() - else - vim.lsp.buf.hover() - end -end - -vim.keymap.set('n', 'K', show_documentation, { silent = true }) -``` +## [Documentation](https://github.com/Saecki/crates.nvim/wiki) +- [Stable](https://github.com/Saecki/crates.nvim/wiki/Stable-documentation) +- [Unstable](https://github.com/Saecki/crates.nvim/wiki/Unstable-documentation) ## Related projects - [simrat39/rust-tools.nvim](https://github.com/simrat39/rust-tools.nvim) diff --git a/doc/crates.txt b/doc/crates.txt index 59ba51ec..c7b766ea 100644 --- a/doc/crates.txt +++ b/doc/crates.txt @@ -2,7 +2,7 @@ *crates.nvim* Author: Tobias Schmitz -Version: 0.4.0 +Version: unstable Homepage: License: MIT license diff --git a/scripts/README.md.in b/scripts/README.md.in index e65d6a59..c3061288 100644 --- a/scripts/README.md.in +++ b/scripts/README.md.in @@ -8,32 +8,6 @@ Feel free to open issues. [Screencast from 2023-03-11 05-29-22.webm](https://user-images.githubusercontent.com/43008152/224464963-9810110f-2923-4346-a442-9d4f2723bdff.webm) -## Features -- Complete crate versions and features -- Completion sources for: - - [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) - - [coq.nvim](https://github.com/ms-jpq/coq_nvim) -- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) code actions -- Update crates to newest compatible version -- Upgrade crates to newest version -- Respect existing version requirements and update them in an elegant way (`smart_insert`) -- Automatically load when opening a `Cargo.toml` file (`autoload`) -- Live update while editing (`autoupdate`) -- Show version and upgrade candidates - - Indicate if compatible version is a pre-release or yanked - - Indicate if no version is compatible -- Open floating window with crate info - - Open documentation, crates.io, repository and homepage urls -- Open floating window with crate versions - - Select a version by pressing enter (`popup.keys.select`) -- Open floating window with crate features - - Navigate the feature hierarchy - - Enable/disable features - - Indicate if a feature is enabled directly or transitively -- Open floating window with crate dependencies - - Navigate the dependency hierarchy - - Indicate if a dependency is optional - ## Setup ### Installation @@ -42,7 +16,7 @@ To use a stable release. [__vim-plug__](https://github.com/junegunn/vim-plug) ``` Plug 'nvim-lua/plenary.nvim' -Plug 'saecki/crates.nvim', { 'tag': 'v' } +Plug 'saecki/crates.nvim', { 'tag': 'stable' } lua require('crates').setup() ``` @@ -51,7 +25,7 @@ lua require('crates').setup() ```lua { 'saecki/crates.nvim', - tag = 'v', + tag = 'stable', dependencies = { 'nvim-lua/plenary.nvim' }, config = function() require('crates').setup() @@ -98,238 +72,9 @@ lua require('crates').setup() ``` -### Auto completion -#### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source - -Enable it in the setup. -```lua -require('crates').setup { - ... - src = { - ... - cmp = { - enabled = true, - }, - }, -} -``` - -And add it to your list of sources. -```lua -require('cmp').setup { - ... - sources = { - { name = "path" }, - { name = "buffer" }, - { name = "nvim_lsp" }, - ... - { name = "crates" }, - }, -} -``` - -
-Or add it lazily. - -```lua -vim.api.nvim_create_autocmd("BufRead", { - group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }), - pattern = "Cargo.toml", - callback = function() - cmp.setup.buffer({ sources = { { name = "crates" } } }) - end, -}) -``` -
- -#### [coq.nvim](https://github.com/ms-jpq/coq_nvim) source -Enable it in the setup, and optionally change the display name. -```lua -require('crates').setup { - ... - src = { - ... - coq = { - enabled = true, - name = "crates.nvim", - }, - }, -} -``` - -### Code actions -#### [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) source -Enable it in the setup, and optionally change the display name. -```lua -local null_ls = require('null-ls') -require('crates').setup { - ... - null_ls = { - enabled = true, - name = "crates.nvim", - }, -} -``` - -## Config - -For more information about the type of some fields see [`teal/crates/config.tl`](teal/crates/config.tl). - -### Default - -The icons in the default configuration require a patched font.
-Any [Nerd Font](https://www.nerdfonts.com/font-downloads) should work. -```lua -require('crates').setup { - -} -``` - -### Plain text - -Replace these fields if you don't have a patched font. -```lua -require('crates').setup { - text = { - loading = " Loading...", - version = " %s", - prerelease = " %s", - yanked = " %s yanked", - nomatch = " Not found", - upgrade = " %s", - error = " Error fetching crate", - }, - popup = { - text = { - title = "# %s", - pill_left = "", - pill_right = "", - created_label = "created ", - updated_label = "updated ", - downloads_label = "downloads ", - homepage_label = "homepage ", - repository_label = "repository ", - documentation_label = "documentation ", - crates_io_label = "crates.io ", - categories_label = "categories ", - keywords_label = "keywords ", - version = "%s", - prerelease = "%s pre-release", - yanked = "%s yanked", - enabled = "* s", - transitive = "~ s", - normal_dependencies_title = " Dependencies", - build_dependencies_title = " Build dependencies", - dev_dependencies_title = " Dev dependencies", - optional = "? %s", - loading = " ...", - }, - }, - src = { - text = { - prerelease = " pre-release ", - yanked = " yanked ", - }, - }, -} -``` - -### Functions -```lua - -``` - -### Key mappings -Some examples of key mappings. -```lua -local crates = require('crates') -local opts = { silent = true } - -vim.keymap.set('n', 'ct', crates.toggle, opts) -vim.keymap.set('n', 'cr', crates.reload, opts) - -vim.keymap.set('n', 'cv', crates.show_versions_popup, opts) -vim.keymap.set('n', 'cf', crates.show_features_popup, opts) -vim.keymap.set('n', 'cd', crates.show_dependencies_popup, opts) - -vim.keymap.set('n', 'cu', crates.update_crate, opts) -vim.keymap.set('v', 'cu', crates.update_crates, opts) -vim.keymap.set('n', 'ca', crates.update_all_crates, opts) -vim.keymap.set('n', 'cU', crates.upgrade_crate, opts) -vim.keymap.set('v', 'cU', crates.upgrade_crates, opts) -vim.keymap.set('n', 'cA', crates.upgrade_all_crates, opts) - -vim.keymap.set('n', 'ce', crates.expand_plain_crate_to_inline_table, opts) -vim.keymap.set('n', 'cE', crates.extract_crate_into_table, opts) - -vim.keymap.set('n', 'cH', crates.open_homepage, opts) -vim.keymap.set('n', 'cR', crates.open_repository, opts) -vim.keymap.set('n', 'cD', crates.open_documentation, opts) -vim.keymap.set('n', 'cC', crates.open_crates_io, opts) -``` - -
-In vimscript - -```vim -nnoremap ct :lua require('crates').toggle() -nnoremap cr :lua require('crates').reload() - -nnoremap cv :lua require('crates').show_versions_popup() -nnoremap cf :lua require('crates').show_features_popup() -nnoremap cd :lua require('crates').show_dependencies_popup() - -nnoremap cu :lua require('crates').update_crate() -vnoremap cu :lua require('crates').update_crates() -nnoremap ca :lua require('crates').update_all_crates() -nnoremap cU :lua require('crates').upgrade_crate() -vnoremap cU :lua require('crates').upgrade_crates() -nnoremap cA :lua require('crates').upgrade_all_crates() - -nnoremap ce :lua require('crates').expand_plain_crate_to_inline_table() -nnoremap cE :lua require('crates').extract_crate_into_table() - -nnoremap cH :lua require('crates').open_homepage() -nnoremap cR :lua require('crates').open_repository() -nnoremap cD :lua require('crates').open_documentation() -nnoremap cC :lua require('crates').open_crates_io() -``` -
- -### Show appropriate documentation in `Cargo.toml` -How you might integrate `show_popup` into your `init.vim`. -```vim -nnoremap K :call show_documentation() -function! s:show_documentation() - if (index(['vim','help'], &filetype) >= 0) - execute 'h '.expand('') - elseif (index(['man'], &filetype) >= 0) - execute 'Man '.expand('') - elseif (expand('%:t') == 'Cargo.toml' && luaeval('require("crates").popup_available()')) - lua require('crates').show_popup() - else - lua vim.lsp.buf.hover() - endif -endfunction -``` - -How you might integrate `show_popup` into your `init.lua`. -```lua -local function show_documentation() - local filetype = vim.bo.filetype - if vim.tbl_contains({ 'vim','help' }, filetype) then - vim.cmd('h '..vim.fn.expand('')) - elseif vim.tbl_contains({ 'man' }, filetype) then - vim.cmd('Man '..vim.fn.expand('')) - elseif vim.fn.expand('%:t') == 'Cargo.toml' and require('crates').popup_available() then - require('crates').show_popup() - else - vim.lsp.buf.hover() - end -end - -vim.keymap.set('n', 'K', show_documentation, { silent = true }) -``` +## [Documentation](https://github.com/Saecki/crates.nvim/wiki) +- [Stable](https://github.com/Saecki/crates.nvim/wiki/Stable-documentation) +- [Unstable](https://github.com/Saecki/crates.nvim/wiki/Unstable-documentation) ## Related projects - [simrat39/rust-tools.nvim](https://github.com/simrat39/rust-tools.nvim) diff --git a/scripts/documentation.md.in b/scripts/documentation.md.in new file mode 100644 index 00000000..c397c8fe --- /dev/null +++ b/scripts/documentation.md.in @@ -0,0 +1,262 @@ +# +Documentation for `crates.nvim` `<VERSION>` + +## Features +- Complete crate versions and features +- Completion sources for: + - [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) + - [coq.nvim](https://github.com/ms-jpq/coq_nvim) +- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) code actions +- Update crates to newest compatible version +- Upgrade crates to newest version +- Respect existing version requirements and update them in an elegant way (`smart_insert`) +- Automatically load when opening a `Cargo.toml` file (`autoload`) +- Live update while editing (`autoupdate`) +- Show version and upgrade candidates + - Indicate if compatible version is a pre-release or yanked + - Indicate if no version is compatible +- Open floating window with crate info + - Open documentation, crates.io, repository and homepage urls +- Open floating window with crate versions + - Select a version by pressing enter (`popup.keys.select`) +- Open floating window with crate features + - Navigate the feature hierarchy + - Enable/disable features + - Indicate if a feature is enabled directly or transitively +- Open floating window with crate dependencies + - Navigate the dependency hierarchy + - Indicate if a dependency is optional + +## Setup +### Auto completion +#### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source + +Enable it in the setup. +```lua +require('crates').setup { + ... + src = { + ... + cmp = { + enabled = true, + }, + }, +} +``` + +And add it to your list of sources. +```lua +require('cmp').setup { + ... + sources = { + { name = "path" }, + { name = "buffer" }, + { name = "nvim_lsp" }, + ... + { name = "crates" }, + }, +} +``` + +<details> +<summary>Or add it lazily.</summary> + +```lua +vim.api.nvim_create_autocmd("BufRead", { + group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }), + pattern = "Cargo.toml", + callback = function() + cmp.setup.buffer({ sources = { { name = "crates" } } }) + end, +}) +``` +</details> + +#### [coq.nvim](https://github.com/ms-jpq/coq_nvim) source +Enable it in the setup, and optionally change the display name. +```lua +require('crates').setup { + ... + src = { + ... + coq = { + enabled = true, + name = "crates.nvim", + }, + }, +} +``` + +### Code actions +#### [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) source +Enable it in the setup, and optionally change the display name. +```lua +local null_ls = require('null-ls') +require('crates').setup { + ... + null_ls = { + enabled = true, + name = "crates.nvim", + }, +} +``` + +## Config + +For more information about the type of some fields see [`teal/crates/config.tl`](teal/crates/config.tl). + +### Default + +The icons in the default configuration require a patched font.<br> +Any [Nerd Font](https://www.nerdfonts.com/font-downloads) should work. +```lua +require('crates').setup { +<DEFAULT_CONFIGURATION> +} +``` + +### Plain text + +Replace these fields if you don't have a patched font. +```lua +require('crates').setup { + text = { + loading = " Loading...", + version = " %s", + prerelease = " %s", + yanked = " %s yanked", + nomatch = " Not found", + upgrade = " %s", + error = " Error fetching crate", + }, + popup = { + text = { + title = "# %s", + pill_left = "", + pill_right = "", + created_label = "created ", + updated_label = "updated ", + downloads_label = "downloads ", + homepage_label = "homepage ", + repository_label = "repository ", + documentation_label = "documentation ", + crates_io_label = "crates.io ", + categories_label = "categories ", + keywords_label = "keywords ", + version = "%s", + prerelease = "%s pre-release", + yanked = "%s yanked", + enabled = "* s", + transitive = "~ s", + normal_dependencies_title = " Dependencies", + build_dependencies_title = " Build dependencies", + dev_dependencies_title = " Dev dependencies", + optional = "? %s", + loading = " ...", + }, + }, + src = { + text = { + prerelease = " pre-release ", + yanked = " yanked ", + }, + }, +} +``` + +### Functions +```lua +<FUNCTIONS> +``` + +### Key mappings +Some examples of key mappings. +```lua +local crates = require('crates') +local opts = { silent = true } + +vim.keymap.set('n', '<leader>ct', crates.toggle, opts) +vim.keymap.set('n', '<leader>cr', crates.reload, opts) + +vim.keymap.set('n', '<leader>cv', crates.show_versions_popup, opts) +vim.keymap.set('n', '<leader>cf', crates.show_features_popup, opts) +vim.keymap.set('n', '<leader>cd', crates.show_dependencies_popup, opts) + +vim.keymap.set('n', '<leader>cu', crates.update_crate, opts) +vim.keymap.set('v', '<leader>cu', crates.update_crates, opts) +vim.keymap.set('n', '<leader>ca', crates.update_all_crates, opts) +vim.keymap.set('n', '<leader>cU', crates.upgrade_crate, opts) +vim.keymap.set('v', '<leader>cU', crates.upgrade_crates, opts) +vim.keymap.set('n', '<leader>cA', crates.upgrade_all_crates, opts) + +vim.keymap.set('n', '<leader>ce', crates.expand_plain_crate_to_inline_table, opts) +vim.keymap.set('n', '<leader>cE', crates.extract_crate_into_table, opts) + +vim.keymap.set('n', '<leader>cH', crates.open_homepage, opts) +vim.keymap.set('n', '<leader>cR', crates.open_repository, opts) +vim.keymap.set('n', '<leader>cD', crates.open_documentation, opts) +vim.keymap.set('n', '<leader>cC', crates.open_crates_io, opts) +``` + +<details> +<summary>In vimscript</summary> + +```vim +nnoremap <silent> <leader>ct :lua require('crates').toggle()<cr> +nnoremap <silent> <leader>cr :lua require('crates').reload()<cr> + +nnoremap <silent> <leader>cv :lua require('crates').show_versions_popup()<cr> +nnoremap <silent> <leader>cf :lua require('crates').show_features_popup()<cr> +nnoremap <silent> <leader>cd :lua require('crates').show_dependencies_popup()<cr> + +nnoremap <silent> <leader>cu :lua require('crates').update_crate()<cr> +vnoremap <silent> <leader>cu :lua require('crates').update_crates()<cr> +nnoremap <silent> <leader>ca :lua require('crates').update_all_crates()<cr> +nnoremap <silent> <leader>cU :lua require('crates').upgrade_crate()<cr> +vnoremap <silent> <leader>cU :lua require('crates').upgrade_crates()<cr> +nnoremap <silent> <leader>cA :lua require('crates').upgrade_all_crates()<cr> + +nnoremap <silent> <leader>ce :lua require('crates').expand_plain_crate_to_inline_table()<cr> +nnoremap <silent> <leader>cE :lua require('crates').extract_crate_into_table()<cr> + +nnoremap <silent> <leader>cH :lua require('crates').open_homepage()<cr> +nnoremap <silent> <leader>cR :lua require('crates').open_repository()<cr> +nnoremap <silent> <leader>cD :lua require('crates').open_documentation()<cr> +nnoremap <silent> <leader>cC :lua require('crates').open_crates_io()<cr> +``` +</details> + +### Show appropriate documentation in `Cargo.toml` +How you might integrate `show_popup` into your `init.vim`. +```vim +nnoremap <silent> K :call <SID>show_documentation()<cr> +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('<cword>') + elseif (index(['man'], &filetype) >= 0) + execute 'Man '.expand('<cword>') + elseif (expand('%:t') == 'Cargo.toml' && luaeval('require("crates").popup_available()')) + lua require('crates').show_popup() + else + lua vim.lsp.buf.hover() + endif +endfunction +``` + +How you might integrate `show_popup` into your `init.lua`. +```lua +local function show_documentation() + local filetype = vim.bo.filetype + if vim.tbl_contains({ 'vim','help' }, filetype) then + vim.cmd('h '..vim.fn.expand('<cword>')) + elseif vim.tbl_contains({ 'man' }, filetype) then + vim.cmd('Man '..vim.fn.expand('<cword>')) + elseif vim.fn.expand('%:t') == 'Cargo.toml' and require('crates').popup_available() then + require('crates').show_popup() + else + vim.lsp.buf.hover() + end +end + +vim.keymap.set('n', 'K', show_documentation, { silent = true }) +``` diff --git a/scripts/gen_doc.lua b/scripts/gen_doc.lua index 1392a32e..4f9b7c0b 100755 --- a/scripts/gen_doc.lua +++ b/scripts/gen_doc.lua @@ -6,16 +6,16 @@ exec lua "$0" "$@" local inspect = require("inspect") local config = require('lua.crates.config') local highlight = require('lua.crates.highlight') -local version = "0.4.0" +local version = "unstable" -local function format_readme_refs(line) +local function format_markdown_refs(line) line = line:gsub("`f#([^`]+)`", "`%1`") line = line:gsub("`p#([^`]+)`", "`%1`") line = line:gsub("`c#([^`]+)`", "`%1`") return line end -local function gen_readme_functions(lines) +local function gen_markdown_functions(lines) local file = io.open("teal/crates/init.tl", "r") for l in file:lines("*l") do if l == "end" then @@ -30,7 +30,7 @@ local function gen_readme_functions(lines) else local doc = l:match("^%s*%-%-%s*(.*)$") if doc then - local fmt = format_readme_refs(doc) + local fmt = format_markdown_refs(doc) table.insert(lines, "-- " .. fmt) end end @@ -273,31 +273,33 @@ local function gen_vim_doc() outfile:close() end -local function gen_readme() +local function gen_markdown(inpath, outpath, title) local lines = {} - local infile = io.open("scripts/README.md.in", "r") + local infile = io.open(inpath, "r") for l in infile:lines("*l") do if l == "<DEFAULT_CONFIGURATION>" then gen_def_config(lines, 1, {}, config.schema) elseif l == "<FUNCTIONS>" then - gen_readme_functions(lines) + gen_markdown_functions(lines) else l = l:gsub("<VERSION>", version) + l = l:gsub("<TITLE>", title) table.insert(lines, l) end end infile:close() local doc = table.concat(lines, "\n") - local outfile = io.open("README.md", "w") + local outfile = io.open(outpath, "w") outfile:write(doc) outfile:close() end local function gen_docs() gen_vim_doc() - gen_readme() + gen_markdown("scripts/README.md.in", "README.md", "") + gen_markdown("scripts/documentation.md.in", "scripts/wiki/Unstable-documentation.md", "Unstable documentation") end gen_docs() diff --git a/scripts/wiki/Home.md b/scripts/wiki/Home.md new file mode 100644 index 00000000..11926841 --- /dev/null +++ b/scripts/wiki/Home.md @@ -0,0 +1,2 @@ +- [[Stable documentation]] +- [[Unstable documentation]] \ No newline at end of file diff --git a/scripts/wiki/Stable-documentation.md b/scripts/wiki/Stable-documentation.md new file mode 100644 index 00000000..5cb5fb70 --- /dev/null +++ b/scripts/wiki/Stable-documentation.md @@ -0,0 +1,470 @@ +# Stable documentation +Documentation for `crates.nvim` `v0.4.0` + +## Features +- Complete crate versions and features +- Completion sources for: + - [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) + - [coq.nvim](https://github.com/ms-jpq/coq_nvim) +- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) code actions +- Update crates to newest compatible version +- Upgrade crates to newest version +- Respect existing version requirements and update them in an elegant way (`smart_insert`) +- Automatically load when opening a `Cargo.toml` file (`autoload`) +- Live update while editing (`autoupdate`) +- Show version and upgrade candidates + - Indicate if compatible version is a pre-release or yanked + - Indicate if no version is compatible +- Open floating window with crate info + - Open documentation, crates.io, repository and homepage urls +- Open floating window with crate versions + - Select a version by pressing enter (`popup.keys.select`) +- Open floating window with crate features + - Navigate the feature hierarchy + - Enable/disable features + - Indicate if a feature is enabled directly or transitively +- Open floating window with crate dependencies + - Navigate the dependency hierarchy + - Indicate if a dependency is optional + +## Setup +### Auto completion +#### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source + +Enable it in the setup. +```lua +require('crates').setup { + ... + src = { + ... + cmp = { + enabled = true, + }, + }, +} +``` + +And add it to your list of sources. +```lua +require('cmp').setup { + ... + sources = { + { name = "path" }, + { name = "buffer" }, + { name = "nvim_lsp" }, + ... + { name = "crates" }, + }, +} +``` + +<details> +<summary>Or add it lazily.</summary> + +```lua +vim.api.nvim_create_autocmd("BufRead", { + group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }), + pattern = "Cargo.toml", + callback = function() + cmp.setup.buffer({ sources = { { name = "crates" } } }) + end, +}) +``` +</details> + +#### [coq.nvim](https://github.com/ms-jpq/coq_nvim) source +Enable it in the setup, and optionally change the display name. +```lua +require('crates').setup { + ... + src = { + ... + coq = { + enabled = true, + name = "crates.nvim", + }, + }, +} +``` + +### Code actions +#### [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) source +Enable it in the setup, and optionally change the display name. +```lua +local null_ls = require('null-ls') +require('crates').setup { + ... + null_ls = { + enabled = true, + name = "crates.nvim", + }, +} +``` + +## Config + +For more information about the type of some fields see [`teal/crates/config.tl`](teal/crates/config.tl). + +### Default + +The icons in the default configuration require a patched font.<br> +Any [Nerd Font](https://www.nerdfonts.com/font-downloads) should work. +```lua +require('crates').setup { + smart_insert = true, + insert_closing_quote = true, + avoid_prerelease = true, + autoload = true, + autoupdate = true, + autoupdate_throttle = 250, + loading_indicator = true, + date_format = "%Y-%m-%d", + thousands_separator = ".", + notification_title = "Crates", + curl_args = { "-sL", "--retry", "1" }, + max_parallel_requests = 80, + open_programs = { "xdg-open", "open" }, + disable_invalid_feature_diagnostic = false, + text = { + loading = "  Loading", + version = "  %s", + prerelease = "  %s", + yanked = "  %s", + nomatch = "  No match", + upgrade = "  %s", + error = "  Error fetching crate", + }, + highlight = { + loading = "CratesNvimLoading", + version = "CratesNvimVersion", + prerelease = "CratesNvimPreRelease", + yanked = "CratesNvimYanked", + nomatch = "CratesNvimNoMatch", + upgrade = "CratesNvimUpgrade", + error = "CratesNvimError", + }, + popup = { + autofocus = false, + hide_on_select = false, + copy_register = '"', + style = "minimal", + border = "none", + show_version_date = false, + show_dependency_version = true, + max_height = 30, + min_width = 20, + padding = 1, + text = { + title = " %s", + pill_left = "", + pill_right = "", + description = "%s", + created_label = " created ", + created = "%s", + updated_label = " updated ", + updated = "%s", + downloads_label = " downloads ", + downloads = "%s", + homepage_label = " homepage ", + homepage = "%s", + repository_label = " repository ", + repository = "%s", + documentation_label = " documentation ", + documentation = "%s", + crates_io_label = " crates.io ", + crates_io = "%s", + categories_label = " categories ", + keywords_label = " keywords ", + version = " %s", + prerelease = " %s", + yanked = " %s", + version_date = " %s", + feature = " %s", + enabled = " %s", + transitive = " %s", + normal_dependencies_title = " Dependencies", + build_dependencies_title = " Build dependencies", + dev_dependencies_title = " Dev dependencies", + dependency = " %s", + optional = " %s", + dependency_version = " %s", + loading = "  ", + }, + highlight = { + title = "CratesNvimPopupTitle", + pill_text = "CratesNvimPopupPillText", + pill_border = "CratesNvimPopupPillBorder", + description = "CratesNvimPopupDescription", + created_label = "CratesNvimPopupLabel", + created = "CratesNvimPopupValue", + updated_label = "CratesNvimPopupLabel", + updated = "CratesNvimPopupValue", + downloads_label = "CratesNvimPopupLabel", + downloads = "CratesNvimPopupValue", + homepage_label = "CratesNvimPopupLabel", + homepage = "CratesNvimPopupUrl", + repository_label = "CratesNvimPopupLabel", + repository = "CratesNvimPopupUrl", + documentation_label = "CratesNvimPopupLabel", + documentation = "CratesNvimPopupUrl", + crates_io_label = "CratesNvimPopupLabel", + crates_io = "CratesNvimPopupUrl", + categories_label = "CratesNvimPopupLabel", + keywords_label = "CratesNvimPopupLabel", + version = "CratesNvimPopupVersion", + prerelease = "CratesNvimPopupPreRelease", + yanked = "CratesNvimPopupYanked", + version_date = "CratesNvimPopupVersionDate", + feature = "CratesNvimPopupFeature", + enabled = "CratesNvimPopupEnabled", + transitive = "CratesNvimPopupTransitive", + normal_dependencies_title = "CratesNvimPopupNormalDependenciesTitle", + build_dependencies_title = "CratesNvimPopupBuildDependenciesTitle", + dev_dependencies_title = "CratesNvimPopupDevDependenciesTitle", + dependency = "CratesNvimPopupDependency", + optional = "CratesNvimPopupOptional", + dependency_version = "CratesNvimPopupDependencyVersion", + loading = "CratesNvimPopupLoading", + }, + keys = { + hide = { "q", "<esc>" }, + open_url = { "<cr>" }, + select = { "<cr>" }, + select_alt = { "s" }, + toggle_feature = { "<cr>" }, + copy_value = { "yy" }, + goto_item = { "gd", "K", "<C-LeftMouse>" }, + jump_forward = { "<c-i>" }, + jump_back = { "<c-o>", "<C-RightMouse>" }, + }, + }, + src = { + insert_closing_quote = true, + text = { + prerelease = "  pre-release ", + yanked = "  yanked ", + }, + coq = { + enabled = false, + name = "Crates", + }, + }, + null_ls = { + enabled = false, + name = "Crates", + }, + on_attach = function(bufnr) end, +} +``` + +### Plain text + +Replace these fields if you don't have a patched font. +```lua +require('crates').setup { + text = { + loading = " Loading...", + version = " %s", + prerelease = " %s", + yanked = " %s yanked", + nomatch = " Not found", + upgrade = " %s", + error = " Error fetching crate", + }, + popup = { + text = { + title = "# %s", + pill_left = "", + pill_right = "", + created_label = "created ", + updated_label = "updated ", + downloads_label = "downloads ", + homepage_label = "homepage ", + repository_label = "repository ", + documentation_label = "documentation ", + crates_io_label = "crates.io ", + categories_label = "categories ", + keywords_label = "keywords ", + version = "%s", + prerelease = "%s pre-release", + yanked = "%s yanked", + enabled = "* s", + transitive = "~ s", + normal_dependencies_title = " Dependencies", + build_dependencies_title = " Build dependencies", + dev_dependencies_title = " Dev dependencies", + optional = "? %s", + loading = " ...", + }, + }, + src = { + text = { + prerelease = " pre-release ", + yanked = " yanked ", + }, + }, +} +``` + +### Functions +```lua +-- Setup config and auto commands. +require('crates').setup(cfg: Config) + +-- Disable UI elements (virtual text and diagnostics). +require('crates').hide() +-- Enable UI elements (virtual text and diagnostics). +require('crates').show() +-- Enable or disable UI elements (virtual text and diagnostics). +require('crates').toggle() +-- Update data. Optionally specify which `buf` to update. +require('crates').update(buf: integer|nil) +-- Reload data (clears cache). Optionally specify which `buf` to reload. +require('crates').reload(buf: integer|nil) + +-- Upgrade the crate on the current line. +-- If the `alt` flag is passed as true, the opposite of the `smart_insert` config +-- option will be used to insert the version. +require('crates').upgrade_crate(alt: boolean|nil) +-- Upgrade the crates on the lines visually selected. +-- See `crates.upgrade_crate()`. +require('crates').upgrade_crates(alt: boolean|nil) +-- Upgrade all crates in the buffer. +-- See `crates.upgrade_crate()`. +require('crates').upgrade_all_crates(alt: boolean|nil) + +-- Update the crate on the current line. +-- See `crates.upgrade_crate()`. +require('crates').update_crate(alt: boolean|nil) +-- Update the crates on the lines visually selected. +-- See `crates.upgrade_crate()`. +require('crates').update_crates(alt: boolean|nil) +-- Update all crates in the buffer. +-- See `crates.upgrade_crate()`. +require('crates').update_all_crates(alt: boolean|nil) + +-- Expand a plain crate declaration into an inline table. +require('crates').expand_plain_crate_to_inline_table() +-- Extract an crate declaration from a dependency section into a table. +require('crates').extract_crate_into_table() + +-- Open the homepage of the crate on the current line. +require('crates').open_homepage() +-- Open the repository page of the crate on the current line. +require('crates').open_repository() +-- Open the documentation page of the crate on the current line. +require('crates').open_documentation() +-- Open the `crates.io` page of the crate on the current line. +require('crates').open_crates_io() + +-- Returns whether there is information to show in a popup. +require('crates').popup_available(): boolean +-- Show/hide popup with crate details, all versions, all features or details about one feature. +-- If `popup.autofocus` is disabled calling this again will focus the popup. +require('crates').show_popup() +-- Same as `crates.show_popup()` but always show crate details. +require('crates').show_crate_popup() +-- Same as `crates.show_popup()` but always show versions. +require('crates').show_versions_popup() +-- Same as `crates.show_popup()` but always show features or features details. +require('crates').show_features_popup() +-- Same as `crates.show_popup()` but always show depedencies. +require('crates').show_dependencies_popup() +-- Focus the popup (jump into the floating window). +-- Optionally specify the line to jump to, inside the popup. +require('crates').focus_popup(line: integer|nil) +-- Hide the popup. +require('crates').hide_popup() +``` + +### Key mappings +Some examples of key mappings. +```lua +local crates = require('crates') +local opts = { silent = true } + +vim.keymap.set('n', '<leader>ct', crates.toggle, opts) +vim.keymap.set('n', '<leader>cr', crates.reload, opts) + +vim.keymap.set('n', '<leader>cv', crates.show_versions_popup, opts) +vim.keymap.set('n', '<leader>cf', crates.show_features_popup, opts) +vim.keymap.set('n', '<leader>cd', crates.show_dependencies_popup, opts) + +vim.keymap.set('n', '<leader>cu', crates.update_crate, opts) +vim.keymap.set('v', '<leader>cu', crates.update_crates, opts) +vim.keymap.set('n', '<leader>ca', crates.update_all_crates, opts) +vim.keymap.set('n', '<leader>cU', crates.upgrade_crate, opts) +vim.keymap.set('v', '<leader>cU', crates.upgrade_crates, opts) +vim.keymap.set('n', '<leader>cA', crates.upgrade_all_crates, opts) + +vim.keymap.set('n', '<leader>ce', crates.expand_plain_crate_to_inline_table, opts) +vim.keymap.set('n', '<leader>cE', crates.extract_crate_into_table, opts) + +vim.keymap.set('n', '<leader>cH', crates.open_homepage, opts) +vim.keymap.set('n', '<leader>cR', crates.open_repository, opts) +vim.keymap.set('n', '<leader>cD', crates.open_documentation, opts) +vim.keymap.set('n', '<leader>cC', crates.open_crates_io, opts) +``` + +<details> +<summary>In vimscript</summary> + +```vim +nnoremap <silent> <leader>ct :lua require('crates').toggle()<cr> +nnoremap <silent> <leader>cr :lua require('crates').reload()<cr> + +nnoremap <silent> <leader>cv :lua require('crates').show_versions_popup()<cr> +nnoremap <silent> <leader>cf :lua require('crates').show_features_popup()<cr> +nnoremap <silent> <leader>cd :lua require('crates').show_dependencies_popup()<cr> + +nnoremap <silent> <leader>cu :lua require('crates').update_crate()<cr> +vnoremap <silent> <leader>cu :lua require('crates').update_crates()<cr> +nnoremap <silent> <leader>ca :lua require('crates').update_all_crates()<cr> +nnoremap <silent> <leader>cU :lua require('crates').upgrade_crate()<cr> +vnoremap <silent> <leader>cU :lua require('crates').upgrade_crates()<cr> +nnoremap <silent> <leader>cA :lua require('crates').upgrade_all_crates()<cr> + +nnoremap <silent> <leader>ce :lua require('crates').expand_plain_crate_to_inline_table()<cr> +nnoremap <silent> <leader>cE :lua require('crates').extract_crate_into_table()<cr> + +nnoremap <silent> <leader>cH :lua require('crates').open_homepage()<cr> +nnoremap <silent> <leader>cR :lua require('crates').open_repository()<cr> +nnoremap <silent> <leader>cD :lua require('crates').open_documentation()<cr> +nnoremap <silent> <leader>cC :lua require('crates').open_crates_io()<cr> +``` +</details> + +### Show appropriate documentation in `Cargo.toml` +How you might integrate `show_popup` into your `init.vim`. +```vim +nnoremap <silent> K :call <SID>show_documentation()<cr> +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('<cword>') + elseif (index(['man'], &filetype) >= 0) + execute 'Man '.expand('<cword>') + elseif (expand('%:t') == 'Cargo.toml' && luaeval('require("crates").popup_available()')) + lua require('crates').show_popup() + else + lua vim.lsp.buf.hover() + endif +endfunction +``` + +How you might integrate `show_popup` into your `init.lua`. +```lua +local function show_documentation() + local filetype = vim.bo.filetype + if vim.tbl_contains({ 'vim','help' }, filetype) then + vim.cmd('h '..vim.fn.expand('<cword>')) + elseif vim.tbl_contains({ 'man' }, filetype) then + vim.cmd('Man '..vim.fn.expand('<cword>')) + elseif vim.fn.expand('%:t') == 'Cargo.toml' and require('crates').popup_available() then + require('crates').show_popup() + else + vim.lsp.buf.hover() + end +end + +vim.keymap.set('n', 'K', show_documentation, { silent = true }) +``` diff --git a/scripts/wiki/Unstable-documentation.md b/scripts/wiki/Unstable-documentation.md new file mode 100644 index 00000000..e7b0398c --- /dev/null +++ b/scripts/wiki/Unstable-documentation.md @@ -0,0 +1,484 @@ +# Unstable documentation +Documentation for `crates.nvim` `unstable` + +## Features +- Complete crate versions and features +- Completion sources for: + - [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) + - [coq.nvim](https://github.com/ms-jpq/coq_nvim) +- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) code actions +- Update crates to newest compatible version +- Upgrade crates to newest version +- Respect existing version requirements and update them in an elegant way (`smart_insert`) +- Automatically load when opening a `Cargo.toml` file (`autoload`) +- Live update while editing (`autoupdate`) +- Show version and upgrade candidates + - Indicate if compatible version is a pre-release or yanked + - Indicate if no version is compatible +- Open floating window with crate info + - Open documentation, crates.io, repository and homepage urls +- Open floating window with crate versions + - Select a version by pressing enter (`popup.keys.select`) +- Open floating window with crate features + - Navigate the feature hierarchy + - Enable/disable features + - Indicate if a feature is enabled directly or transitively +- Open floating window with crate dependencies + - Navigate the dependency hierarchy + - Indicate if a dependency is optional + +## Setup +### Auto completion +#### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source + +Enable it in the setup. +```lua +require('crates').setup { + ... + src = { + ... + cmp = { + enabled = true, + }, + }, +} +``` + +And add it to your list of sources. +```lua +require('cmp').setup { + ... + sources = { + { name = "path" }, + { name = "buffer" }, + { name = "nvim_lsp" }, + ... + { name = "crates" }, + }, +} +``` + +<details> +<summary>Or add it lazily.</summary> + +```lua +vim.api.nvim_create_autocmd("BufRead", { + group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }), + pattern = "Cargo.toml", + callback = function() + cmp.setup.buffer({ sources = { { name = "crates" } } }) + end, +}) +``` +</details> + +#### [coq.nvim](https://github.com/ms-jpq/coq_nvim) source +Enable it in the setup, and optionally change the display name. +```lua +require('crates').setup { + ... + src = { + ... + coq = { + enabled = true, + name = "crates.nvim", + }, + }, +} +``` + +### Code actions +#### [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim) source +Enable it in the setup, and optionally change the display name. +```lua +local null_ls = require('null-ls') +require('crates').setup { + ... + null_ls = { + enabled = true, + name = "crates.nvim", + }, +} +``` + +## Config + +For more information about the type of some fields see [`teal/crates/config.tl`](teal/crates/config.tl). + +### Default + +The icons in the default configuration require a patched font.<br> +Any [Nerd Font](https://www.nerdfonts.com/font-downloads) should work. +```lua +require('crates').setup { + smart_insert = true, + insert_closing_quote = true, + avoid_prerelease = true, + autoload = true, + autoupdate = true, + autoupdate_throttle = 250, + loading_indicator = true, + date_format = "%Y-%m-%d", + thousands_separator = ".", + notification_title = "Crates", + curl_args = { "-sL", "--retry", "1" }, + max_parallel_requests = 80, + expand_crate_moves_cursor = true, + open_programs = { "xdg-open", "open" }, + disable_invalid_feature_diagnostic = false, + enable_update_available_warning = true, + text = { + loading = "  Loading", + version = "  %s", + prerelease = "  %s", + yanked = "  %s", + nomatch = "  No match", + upgrade = "  %s", + error = "  Error fetching crate", + }, + highlight = { + loading = "CratesNvimLoading", + version = "CratesNvimVersion", + prerelease = "CratesNvimPreRelease", + yanked = "CratesNvimYanked", + nomatch = "CratesNvimNoMatch", + upgrade = "CratesNvimUpgrade", + error = "CratesNvimError", + }, + popup = { + autofocus = false, + hide_on_select = false, + copy_register = '"', + style = "minimal", + border = "none", + show_version_date = false, + show_dependency_version = true, + max_height = 30, + min_width = 20, + padding = 1, + text = { + title = " %s", + pill_left = "", + pill_right = "", + description = "%s", + created_label = " created ", + created = "%s", + updated_label = " updated ", + updated = "%s", + downloads_label = " downloads ", + downloads = "%s", + homepage_label = " homepage ", + homepage = "%s", + repository_label = " repository ", + repository = "%s", + documentation_label = " documentation ", + documentation = "%s", + crates_io_label = " crates.io ", + crates_io = "%s", + categories_label = " categories ", + keywords_label = " keywords ", + version = " %s", + prerelease = " %s", + yanked = " %s", + version_date = " %s", + feature = " %s", + enabled = " %s", + transitive = " %s", + normal_dependencies_title = " Dependencies", + build_dependencies_title = " Build dependencies", + dev_dependencies_title = " Dev dependencies", + dependency = " %s", + optional = " %s", + dependency_version = " %s", + loading = "  ", + }, + highlight = { + title = "CratesNvimPopupTitle", + pill_text = "CratesNvimPopupPillText", + pill_border = "CratesNvimPopupPillBorder", + description = "CratesNvimPopupDescription", + created_label = "CratesNvimPopupLabel", + created = "CratesNvimPopupValue", + updated_label = "CratesNvimPopupLabel", + updated = "CratesNvimPopupValue", + downloads_label = "CratesNvimPopupLabel", + downloads = "CratesNvimPopupValue", + homepage_label = "CratesNvimPopupLabel", + homepage = "CratesNvimPopupUrl", + repository_label = "CratesNvimPopupLabel", + repository = "CratesNvimPopupUrl", + documentation_label = "CratesNvimPopupLabel", + documentation = "CratesNvimPopupUrl", + crates_io_label = "CratesNvimPopupLabel", + crates_io = "CratesNvimPopupUrl", + categories_label = "CratesNvimPopupLabel", + keywords_label = "CratesNvimPopupLabel", + version = "CratesNvimPopupVersion", + prerelease = "CratesNvimPopupPreRelease", + yanked = "CratesNvimPopupYanked", + version_date = "CratesNvimPopupVersionDate", + feature = "CratesNvimPopupFeature", + enabled = "CratesNvimPopupEnabled", + transitive = "CratesNvimPopupTransitive", + normal_dependencies_title = "CratesNvimPopupNormalDependenciesTitle", + build_dependencies_title = "CratesNvimPopupBuildDependenciesTitle", + dev_dependencies_title = "CratesNvimPopupDevDependenciesTitle", + dependency = "CratesNvimPopupDependency", + optional = "CratesNvimPopupOptional", + dependency_version = "CratesNvimPopupDependencyVersion", + loading = "CratesNvimPopupLoading", + }, + keys = { + hide = { "q", "<esc>" }, + open_url = { "<cr>" }, + select = { "<cr>" }, + select_alt = { "s" }, + toggle_feature = { "<cr>" }, + copy_value = { "yy" }, + goto_item = { "gd", "K", "<C-LeftMouse>" }, + jump_forward = { "<c-i>" }, + jump_back = { "<c-o>", "<C-RightMouse>" }, + }, + }, + src = { + insert_closing_quote = true, + text = { + prerelease = "  pre-release ", + yanked = "  yanked ", + }, + cmp = { + enabled = false, + use_custom_kind = true, + kind_text = { + version = "Version", + feature = "Feature", + }, + kind_highlight = { + version = "CmpItemKindVersion", + feature = "CmpItemKindFeature", + }, + }, + coq = { + enabled = false, + name = "Crates", + }, + }, + null_ls = { + enabled = false, + name = "Crates", + }, + on_attach = function(bufnr) end, +} +``` + +### Plain text + +Replace these fields if you don't have a patched font. +```lua +require('crates').setup { + text = { + loading = " Loading...", + version = " %s", + prerelease = " %s", + yanked = " %s yanked", + nomatch = " Not found", + upgrade = " %s", + error = " Error fetching crate", + }, + popup = { + text = { + title = "# %s", + pill_left = "", + pill_right = "", + created_label = "created ", + updated_label = "updated ", + downloads_label = "downloads ", + homepage_label = "homepage ", + repository_label = "repository ", + documentation_label = "documentation ", + crates_io_label = "crates.io ", + categories_label = "categories ", + keywords_label = "keywords ", + version = "%s", + prerelease = "%s pre-release", + yanked = "%s yanked", + enabled = "* s", + transitive = "~ s", + normal_dependencies_title = " Dependencies", + build_dependencies_title = " Build dependencies", + dev_dependencies_title = " Dev dependencies", + optional = "? %s", + loading = " ...", + }, + }, + src = { + text = { + prerelease = " pre-release ", + yanked = " yanked ", + }, + }, +} +``` + +### Functions +```lua +-- Setup config and auto commands. +require('crates').setup(cfg: Config) + +-- Disable UI elements (virtual text and diagnostics). +require('crates').hide() +-- Enable UI elements (virtual text and diagnostics). +require('crates').show() +-- Enable or disable UI elements (virtual text and diagnostics). +require('crates').toggle() +-- Update data. Optionally specify which `buf` to update. +require('crates').update(buf: integer|nil) +-- Reload data (clears cache). Optionally specify which `buf` to reload. +require('crates').reload(buf: integer|nil) + +-- Upgrade the crate on the current line. +-- If the `alt` flag is passed as true, the opposite of the `smart_insert` config +-- option will be used to insert the version. +require('crates').upgrade_crate(alt: boolean|nil) +-- Upgrade the crates on the lines visually selected. +-- See `crates.upgrade_crate()`. +require('crates').upgrade_crates(alt: boolean|nil) +-- Upgrade all crates in the buffer. +-- See `crates.upgrade_crate()`. +require('crates').upgrade_all_crates(alt: boolean|nil) + +-- Update the crate on the current line. +-- See `crates.upgrade_crate()`. +require('crates').update_crate(alt: boolean|nil) +-- Update the crates on the lines visually selected. +-- See `crates.upgrade_crate()`. +require('crates').update_crates(alt: boolean|nil) +-- Update all crates in the buffer. +-- See `crates.upgrade_crate()`. +require('crates').update_all_crates(alt: boolean|nil) + +-- Expand a plain crate declaration into an inline table. +require('crates').expand_plain_crate_to_inline_table() +-- Extract an crate declaration from a dependency section into a table. +require('crates').extract_crate_into_table() + +-- Open the homepage of the crate on the current line. +require('crates').open_homepage() +-- Open the repository page of the crate on the current line. +require('crates').open_repository() +-- Open the documentation page of the crate on the current line. +require('crates').open_documentation() +-- Open the `crates.io` page of the crate on the current line. +require('crates').open_crates_io() + +-- Returns whether there is information to show in a popup. +require('crates').popup_available(): boolean +-- Show/hide popup with crate details, all versions, all features or details about one feature. +-- If `popup.autofocus` is disabled calling this again will focus the popup. +require('crates').show_popup() +-- Same as `crates.show_popup()` but always show crate details. +require('crates').show_crate_popup() +-- Same as `crates.show_popup()` but always show versions. +require('crates').show_versions_popup() +-- Same as `crates.show_popup()` but always show features or features details. +require('crates').show_features_popup() +-- Same as `crates.show_popup()` but always show depedencies. +require('crates').show_dependencies_popup() +-- Focus the popup (jump into the floating window). +-- Optionally specify the line to jump to, inside the popup. +require('crates').focus_popup(line: integer|nil) +-- Hide the popup. +require('crates').hide_popup() +``` + +### Key mappings +Some examples of key mappings. +```lua +local crates = require('crates') +local opts = { silent = true } + +vim.keymap.set('n', '<leader>ct', crates.toggle, opts) +vim.keymap.set('n', '<leader>cr', crates.reload, opts) + +vim.keymap.set('n', '<leader>cv', crates.show_versions_popup, opts) +vim.keymap.set('n', '<leader>cf', crates.show_features_popup, opts) +vim.keymap.set('n', '<leader>cd', crates.show_dependencies_popup, opts) + +vim.keymap.set('n', '<leader>cu', crates.update_crate, opts) +vim.keymap.set('v', '<leader>cu', crates.update_crates, opts) +vim.keymap.set('n', '<leader>ca', crates.update_all_crates, opts) +vim.keymap.set('n', '<leader>cU', crates.upgrade_crate, opts) +vim.keymap.set('v', '<leader>cU', crates.upgrade_crates, opts) +vim.keymap.set('n', '<leader>cA', crates.upgrade_all_crates, opts) + +vim.keymap.set('n', '<leader>ce', crates.expand_plain_crate_to_inline_table, opts) +vim.keymap.set('n', '<leader>cE', crates.extract_crate_into_table, opts) + +vim.keymap.set('n', '<leader>cH', crates.open_homepage, opts) +vim.keymap.set('n', '<leader>cR', crates.open_repository, opts) +vim.keymap.set('n', '<leader>cD', crates.open_documentation, opts) +vim.keymap.set('n', '<leader>cC', crates.open_crates_io, opts) +``` + +<details> +<summary>In vimscript</summary> + +```vim +nnoremap <silent> <leader>ct :lua require('crates').toggle()<cr> +nnoremap <silent> <leader>cr :lua require('crates').reload()<cr> + +nnoremap <silent> <leader>cv :lua require('crates').show_versions_popup()<cr> +nnoremap <silent> <leader>cf :lua require('crates').show_features_popup()<cr> +nnoremap <silent> <leader>cd :lua require('crates').show_dependencies_popup()<cr> + +nnoremap <silent> <leader>cu :lua require('crates').update_crate()<cr> +vnoremap <silent> <leader>cu :lua require('crates').update_crates()<cr> +nnoremap <silent> <leader>ca :lua require('crates').update_all_crates()<cr> +nnoremap <silent> <leader>cU :lua require('crates').upgrade_crate()<cr> +vnoremap <silent> <leader>cU :lua require('crates').upgrade_crates()<cr> +nnoremap <silent> <leader>cA :lua require('crates').upgrade_all_crates()<cr> + +nnoremap <silent> <leader>ce :lua require('crates').expand_plain_crate_to_inline_table()<cr> +nnoremap <silent> <leader>cE :lua require('crates').extract_crate_into_table()<cr> + +nnoremap <silent> <leader>cH :lua require('crates').open_homepage()<cr> +nnoremap <silent> <leader>cR :lua require('crates').open_repository()<cr> +nnoremap <silent> <leader>cD :lua require('crates').open_documentation()<cr> +nnoremap <silent> <leader>cC :lua require('crates').open_crates_io()<cr> +``` +</details> + +### Show appropriate documentation in `Cargo.toml` +How you might integrate `show_popup` into your `init.vim`. +```vim +nnoremap <silent> K :call <SID>show_documentation()<cr> +function! s:show_documentation() + if (index(['vim','help'], &filetype) >= 0) + execute 'h '.expand('<cword>') + elseif (index(['man'], &filetype) >= 0) + execute 'Man '.expand('<cword>') + elseif (expand('%:t') == 'Cargo.toml' && luaeval('require("crates").popup_available()')) + lua require('crates').show_popup() + else + lua vim.lsp.buf.hover() + endif +endfunction +``` + +How you might integrate `show_popup` into your `init.lua`. +```lua +local function show_documentation() + local filetype = vim.bo.filetype + if vim.tbl_contains({ 'vim','help' }, filetype) then + vim.cmd('h '..vim.fn.expand('<cword>')) + elseif vim.tbl_contains({ 'man' }, filetype) then + vim.cmd('Man '..vim.fn.expand('<cword>')) + elseif vim.fn.expand('%:t') == 'Cargo.toml' and require('crates').popup_available() then + require('crates').show_popup() + else + vim.lsp.buf.hover() + end +end + +vim.keymap.set('n', 'K', show_documentation, { silent = true }) +``` \ No newline at end of file