Skip to content

Commit 00cc276

Browse files
committed
feat!: deprecate the nvim-cmp, coq_nvim, and null-ls sources
The in-process language server can be used instead.
1 parent d424ea9 commit 00cc276

File tree

7 files changed

+120
-246
lines changed

7 files changed

+120
-246
lines changed

doc/crates.txt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,6 @@ text.error *crates-config-text-error*
734734
Format string used when there was an error loading crate information.
735735

736736

737-
open_programs *crates-config-open_programs*
738-
DEPRECATED: `vim.ui.open()` is used instead
739-
740737
highlight *crates-config-highlight*
741738
Section type: `HighlightConfig`
742739

@@ -1414,6 +1411,7 @@ completion.cmp *crates-config-completion-cmp*
14141411

14151412

14161413
completion.cmp.enabled *crates-config-completion-cmp-enabled*
1414+
DEPRECATED: The nvim-cmp source will be removed soon. Use the in-process language server instead.
14171415
Type: `boolean`, Default: `false`
14181416

14191417
Whether to load and register the |nvim-cmp| source.
@@ -1478,6 +1476,7 @@ completion.coq *crates-config-completion-coq*
14781476

14791477

14801478
completion.coq.enabled *crates-config-completion-coq-enabled*
1479+
DEPRECATED: The coq_nvim source will be removed soon. Use the in-process language server instead.
14811480
Type: `boolean`, Default: `false`
14821481

14831482
Whether to load and register the |coq_nvim| source.
@@ -1590,21 +1589,24 @@ completion.crates.max_results *crates-config-completion-crates-max_results*
15901589

15911590

15921591
src *crates-config-src*
1593-
DEPRECATED: please use |crates-config-completion| instead.
1594-
1592+
DEPRECATED: This will be ignored.
1593+
Please use |crates-config-completion| instead.
15951594
null_ls *crates-config-null_ls*
1595+
DEPRECATED: The null-ls source will be removed soon. Use the in-process language server instead.
15961596
Section type: `NullLsConfig`
15971597

15981598
Configuration options for null-ls.nvim actions.
15991599

16001600

16011601
null_ls.enabled *crates-config-null_ls-enabled*
1602+
DEPRECATED: The null-ls source will be removed soon. Use the in-process language server instead.
16021603
Type: `boolean`, Default: `false`
16031604

16041605
Whether to register the |null-ls.nvim| source.
16051606

16061607

16071608
null_ls.name *crates-config-null_ls-name*
1609+
DEPRECATED: The null-ls source will be removed soon. Use the in-process language server instead.
16081610
Type: `string`, Default: `"crates.nvim"`
16091611

16101612
The |null-ls.nvim| name.
@@ -1651,6 +1653,8 @@ lsp.on_attach *crates-config-lsp-on_attach*
16511653

16521654
Callback to run when the in-process language server attaches to a buffer.
16531655

1656+
NOTE: Alternatively you can also use the `LspAttach` autocmd.
1657+
16541658
NOTE: Ignored if |crates-config-autoload| is disabled.
16551659

16561660

docgen/gen_doc.lua

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ end
284284
---@param lines string[]
285285
---@param path string[]
286286
---@param schema SchemaElement[]
287-
local function gen_vimdoc_config(lines, path, schema)
287+
---@param parent_deprecated Deprecated?
288+
local function gen_vimdoc_config(lines, path, schema, parent_deprecated)
288289
for _, s in ipairs(schema) do
289290
if s.hidden then
290291
goto continue
@@ -302,34 +303,43 @@ local function gen_vimdoc_config(lines, path, schema)
302303
table.insert(lines, key)
303304
end
304305
305-
if s.deprecated then
306-
if s.deprecated.new_field then
307-
local nf = "crates-config-" .. table.concat(s.deprecated.new_field, "-")
308-
table.insert(lines, string.format(" DEPRECATED: please use |%s| instead.", nf))
309-
elseif s.deprecated.msg then
310-
table.insert(lines, " DEPRECATED: " .. s.deprecated.msg)
311-
elseif s.deprecated.hard then
312-
table.insert(lines, " DEPRECATED: ignored")
313-
end
314-
table.insert(lines, "")
315-
else
316-
if s.type.config_type == "section" then
317-
table.insert(lines, string.format(" Section type: `%s`", s.type.emmylua_annotation))
318-
table.insert(lines, "")
306+
local deprecated = s.deprecated or parent_deprecated
307+
if deprecated then
308+
if deprecated.msg then
309+
local msg = string.sub(deprecated.msg, 1, 1):upper() .. string.sub(deprecated.msg, 2)
310+
table.insert(lines, " DEPRECATED: " .. msg)
311+
elseif not deprecated.hard then
312+
table.insert(lines, " DEPRECATED: This will stop working soon.")
319313
else
320-
local t = s.type.emmylua_annotation
321-
local d = s.default_text or vim.inspect(s.default)
322-
table.insert(lines, string.format(" Type: `%s`, Default: `%s`", t, d))
323-
table.insert(lines, "")
314+
table.insert(lines, " DEPRECATED: This will be ignored.")
315+
end
316+
if deprecated.new_field then
317+
local nf = "crates-config-" .. table.concat(deprecated.new_field, "-")
318+
table.insert(lines, string.format(" Please use |%s| instead.", nf))
324319
end
320+
end
321+
322+
if deprecated and deprecated.hard then
323+
goto continue
324+
end
325+
326+
if s.type.config_type == "section" then
327+
table.insert(lines, string.format(" Section type: `%s`", s.type.emmylua_annotation))
328+
else
329+
local t = s.type.emmylua_annotation
330+
local d = s.default_text or vim.inspect(s.default)
331+
table.insert(lines, string.format(" Type: `%s`, Default: `%s`", t, d))
332+
end
333+
table.insert(lines, "")
325334
335+
if s.description then
326336
local description = s.description:gsub("^ ", ""):gsub("\n ", "\n")
327337
table.insert(lines, description)
328338
table.insert(lines, "")
329339
end
330340
331341
if s.type.config_type == "section" then
332-
gen_vimdoc_config(lines, p, s.fields)
342+
gen_vimdoc_config(lines, p, s.fields, deprecated)
333343
end
334344
335345
::continue::
@@ -348,7 +358,7 @@ local function gen_def_config(lines, indent, path, schema)
348358
end
349359
350360
for _, s in ipairs(schema) do
351-
if not s.hidden and not s.deprecated then
361+
if not s.hidden and not (s.deprecated and (s.deprecated.hard or s.deprecated.new_field)) then
352362
local name = s.name
353363
354364
if s.type.config_type == "section" then
@@ -396,7 +406,7 @@ local function gen_vim_doc()
396406
elseif ph == "SUBCOMMANDS" then
397407
gen_vimdoc_subcommands(lines)
398408
elseif ph == "CONFIGURATION" then
399-
gen_vimdoc_config(lines, {}, config.schema)
409+
gen_vimdoc_config(lines, {}, config.schema, nil)
400410
elseif ph == "HIGHLIGHTS" then
401411
gen_vimdoc_highlights(lines)
402412
else

docgen/templates/documentation.md.in

Lines changed: 32 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
Documentation for `crates.nvim` `<VERSION>`
22

33
# Features
4-
- Complete crate names, versions and features using one of:
5-
- In-process language server (`lsp`)
6-
- [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source (`completion.cmp`)
7-
- [coq.nvim](https://github.com/ms-jpq/coq_nvim) source (`completion.coq`)
8-
- Code actions using one of:
9-
- In-process language server (`lsp`)
10-
- [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim)/[none-ls.nvim](https://github.com/nvimtools/none-ls.nvim)
4+
- In-process language server (`lsp`)
5+
- Complete crate names, versions and features
6+
- Code actions
7+
- Hover
118
- Update crates to newest compatible version
129
- Upgrade crates to newest version
1310
- Respect existing version requirements and update them in an elegant way (`smart_insert`)
@@ -31,10 +28,12 @@ Documentation for `crates.nvim` `<VERSION>`
3128
# Setup
3229

3330
## In-process language server
34-
This is the recommended way to enable completion and code actions.
31+
The in-process langauge server is disabled by default. It can be enabled
32+
to support completions, code actions, and hover.
3533

3634
Enable the in-process language server in the setup and select whether to enable
37-
code actions, auto completion and hover.
35+
code actions, auto completion and hover. The `on_attach` function, or the `LspAttach`
36+
autocmd can be used to setup key mappings, just like for other language servers.
3837
```lua
3938
require("crates").setup {
4039
...
@@ -52,56 +51,30 @@ require("crates").setup {
5251
```
5352

5453
## Auto completion
55-
Completion is supported in a few different ways, either by the [in-process language server](#in-process-language-server),
56-
which also supports code actions, or by one of the following sources.
54+
Auto completion works through the [in-process language server](#in-process-language-server).
5755

58-
### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source
56+
### Crate name completion
57+
58+
Crate names of dependencies can be completed from searches on `crates.io`.
59+
This has to be enabled seperately:
5960

60-
Enable it in the setup.
6161
```lua
6262
require("crates").setup {
6363
...
6464
completion = {
65-
...
66-
cmp = {
67-
enabled = true,
68-
},
69-
},
70-
}
71-
```
72-
73-
And add it to your list of sources.
74-
```lua
75-
require("cmp").setup {
76-
...
77-
sources = {
78-
{ name = "path" },
79-
{ name = "buffer" },
80-
{ name = "nvim_lsp" },
81-
...
82-
{ name = "crates" },
83-
},
65+
crates = {
66+
enabled = true -- Disabled by default
67+
max_results = 8 -- The maximum number of search results to display
68+
min_chars = 3 -- The minimum number of charaters to type before completions begin appearing
69+
}
70+
}
8471
}
8572
```
8673

87-
<details>
88-
<summary>Or add it lazily.</summary>
89-
90-
```lua
91-
vim.api.nvim_create_autocmd("BufRead", {
92-
group = vim.api.nvim_create_augroup("CmpSourceCargo", { clear = true }),
93-
pattern = "Cargo.toml",
94-
callback = function()
95-
cmp.setup.buffer({ sources = { { name = "crates" } } })
96-
end,
97-
})
98-
```
99-
</details>
100-
101-
<details>
102-
<summary>Custom nvim-cmp completion kinds</summary>
74+
### [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) source
10375

104-
Enable custom completion kind in the config.
76+
Custom completion kinds are enabled by default, but icons need to be specified
77+
manually. The default kind names and highlight groups are as follows:
10578
```lua
10679
require("crates").setup {
10780
...
@@ -125,11 +98,12 @@ require("crates").setup {
12598
This will set a custom completion `cmp.kind_text` and `cmp.kind_hl_group` attributes
12699
to completion items for `nvim-cmp`.
127100

128-
Depending on how you've set up [the nvim-cmp menu](https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#basic-customisations)
129-
you'll have to handle these explicitly.
130-
If you haven't changed `nvim-cmp`s `formatting` configuration everything should work out of the box.
101+
<details>
102+
<summary>Custom nvim-cmp kind icons</summary>
103+
104+
How custom icons can be added depends on how you've set up [the nvim-cmp menu](https://github.com/hrsh7th/nvim-cmp/wiki/Menu-Appearance#basic-customisations).
131105

132-
Here's an example of how add custom icons.
106+
Here's an example of how add custom icons, you might need to adapt some things.
133107
```lua
134108
local kind_icons = {
135109
["Class"] = "🅒 ",
@@ -175,57 +149,15 @@ require("cmp").setup({
175149
```
176150
</details>
177151

178-
### [coq.nvim](https://github.com/ms-jpq/coq_nvim) source
179-
Enable it in the setup, and optionally change the display name.
180-
```lua
181-
require("crates").setup {
182-
...
183-
completion = {
184-
...
185-
coq = {
186-
enabled = true,
187-
name = "crates.nvim",
188-
},
189-
},
190-
}
191-
```
192-
193-
### Crate name completion
194-
195-
Crate names in dependencies can be completed from searches on `crates.io`. This has to be
196-
enabled seperately:
197-
198-
```lua
199-
require("crates").setup {
200-
...
201-
completion = {
202-
crates = {
203-
enabled = true -- disabled by default
204-
max_results = 8 -- The maximum number of search results to display
205-
min_chars = 3 -- The minimum number of charaters to type before completions begin appearing
206-
}
207-
}
208-
}
209-
```
210-
211152
## Code actions
212-
Code actions are supported in a few different ways, either by the [in-process language server](#in-process-language-server),
213-
which also supports completion, or by the null-ls/none-ls source.
153+
Code actions work through the [in-process language server](#in-process-language-server).
154+
But you can also set up key mappings for specific actions. See [key mappings](#key-mappings).
214155

215-
### [null-ls.nvim](https://github.com/jose-elias-alvarez/null-ls.nvim)/[none-ls.nvim](https://github.com/nvimtools/none-ls.nvim) source
216-
Enable it in the setup, and optionally change the display name.
217-
```lua
218-
require("crates").setup {
219-
...
220-
null_ls = {
221-
enabled = true,
222-
name = "crates.nvim",
223-
},
224-
}
225-
```
156+
## Hover
157+
Hover is supported through the [in-process language server](#in-process-language-server).
158+
But you can also set up key mappings for specific menus. See [key mappings](#key-mappings).
226159

227160
# Config
228-
229161
For more information about the config types have a look at the vimdoc or [`lua/crates/config/types.lua`](https://github.com/Saecki/crates.nvim/blob/main/lua/crates/config/types.lua).
230162

231163
## Default

0 commit comments

Comments
 (0)