Skip to content

Commit 58060c2

Browse files
authored
Merge neovim#33972 feat(lsp): textDocument/inlineCompletion
2 parents 42f244b + 0e70aa0 commit 58060c2

File tree

14 files changed

+840
-12
lines changed

14 files changed

+840
-12
lines changed

runtime/colors/vim.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ hi('PmenuMatchSel', { link = 'PmenuSel' })
6262
hi('PmenuExtra', { link = 'Pmenu' })
6363
hi('PmenuExtraSel', { link = 'PmenuSel' })
6464
hi('ComplMatchIns', {})
65+
hi('ComplHint', { link = 'NonText' })
66+
hi('ComplHintMore', { link = 'MoreMsg' })
6567
hi('Substitute', { link = 'Search' })
6668
hi('Whitespace', { link = 'NonText' })
6769
hi('MsgSeparator', { link = 'StatusLine' })

runtime/doc/lsp.txt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ They are also listed below.
332332
- `'textDocument/formatting'`
333333
- `'textDocument/hover'`
334334
- `'textDocument/inlayHint'`
335+
- `'textDocument/inlineCompletion'`
335336
- `'textDocument/publishDiagnostics'`
336337
- `'textDocument/rangeFormatting'`
337338
- `'textDocument/rename'`
@@ -2219,6 +2220,73 @@ is_enabled({filter}) *vim.lsp.inlay_hint.is_enabled()*
22192220
(`boolean`)
22202221

22212222

2223+
==============================================================================
2224+
Lua module: vim.lsp.inline_completion *lsp-inline_completion*
2225+
2226+
enable({enable}, {filter}) *vim.lsp.inline_completion.enable()*
2227+
Enables or disables inline completion for the {filter}ed scope, inline
2228+
completion will automatically be refreshed when you are in insert mode.
2229+
2230+
To "toggle", pass the inverse of `is_enabled()`: >lua
2231+
vim.lsp.inline_completion.enable(not vim.lsp.inline_completion.is_enabled())
2232+
<
2233+
2234+
Parameters: ~
2235+
{enable} (`boolean?`) true/nil to enable, false to disable
2236+
{filter} (`table?`) Optional filters |kwargs|,
2237+
{bufnr}? (`integer`, default: all) Buffer number, or 0 for
2238+
current buffer, or nil for all.
2239+
• {client_id}? (`integer`, default: all) Client ID, or nil
2240+
for all.
2241+
2242+
get({opts}) *vim.lsp.inline_completion.get()*
2243+
Apply the currently displayed completion candidate to the buffer.
2244+
2245+
It returns false when no candidate can be applied, so you can use the
2246+
return value to implement a fallback: >lua
2247+
vim.keymap.set('i', '<Tab>', function()
2248+
if not vim.lsp.inline_completion.get() then
2249+
return '<Tab>'
2250+
end
2251+
end, {
2252+
expr = true,
2253+
replace_keycodes = true,
2254+
desc = 'Get the current inline completion',
2255+
})
2256+
<
2257+
2258+
Parameters: ~
2259+
{opts} (`table?`) A table with the following fields:
2260+
{bufnr}? (`integer`, default: 0) Buffer handle, or 0 for
2261+
current.
2262+
2263+
Return: ~
2264+
(`boolean`) `true` if a completion was applied, else `false`.
2265+
2266+
is_enabled({filter}) *vim.lsp.inline_completion.is_enabled()*
2267+
Query whether inline completion is enabled in the {filter}ed scope
2268+
2269+
Parameters: ~
2270+
{filter} (`table?`) Optional filters |kwargs|,
2271+
{bufnr}? (`integer`, default: all) Buffer number, or 0 for
2272+
current buffer, or nil for all.
2273+
• {client_id}? (`integer`, default: all) Client ID, or nil
2274+
for all.
2275+
2276+
select({opts}) *vim.lsp.inline_completion.select()*
2277+
Switch between available inline completion candidates.
2278+
2279+
Parameters: ~
2280+
{opts} (`table?`) A table with the following fields:
2281+
{bufnr}? (`integer`) (default: current buffer)
2282+
{count}? (`integer`, default: v:count1) The number of
2283+
candidates to move by. A positive integer moves forward by
2284+
{count} candidates, while a negative integer moves backward
2285+
by {count} candidates.
2286+
{wrap}? (`boolean`, default: `true`) Whether to loop around
2287+
file or not. Similar to 'wrapscan'.
2288+
2289+
22222290
==============================================================================
22232291
Lua module: vim.lsp.linked_editing_range *lsp-linked_editing_range*
22242292

runtime/doc/lua.txt

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3984,19 +3984,37 @@ by |vim.Pos| objects.
39843984
as format conversions.
39853985

39863986
Fields: ~
3987-
{row} (`integer`) 0-based byte index.
3988-
{col} (`integer`) 0-based byte index.
3989-
{buf}? (`integer`) Optional buffer handle.
3987+
{row} (`integer`) 0-based byte index.
3988+
{col} (`integer`) 0-based byte index.
3989+
{buf}? (`integer`) Optional buffer handle.
39903990

3991-
When specified, it indicates that this position belongs to a
3992-
specific buffer. This field is required when performing
3993-
position conversions.
3994-
• {to_lsp} (`fun(pos: vim.Pos, position_encoding: lsp.PositionEncodingKind)`)
3995-
See |Pos:to_lsp()|.
3996-
{lsp} (`fun(buf: integer, pos: lsp.Position, position_encoding: lsp.PositionEncodingKind)`)
3997-
See |Pos:lsp()|.
3991+
When specified, it indicates that this position belongs
3992+
to a specific buffer. This field is required when
3993+
performing position conversions.
3994+
• {to_lsp} (`fun(pos: vim.Pos, position_encoding: lsp.PositionEncodingKind)`)
3995+
See |Pos:to_lsp()|.
3996+
{lsp} (`fun(buf: integer, pos: lsp.Position, position_encoding: lsp.PositionEncodingKind)`)
3997+
See |Pos:lsp()|.
3998+
• {to_cursor} (`fun(pos: vim.Pos): [integer, integer]`) See
3999+
|Pos:to_cursor()|.
4000+
{cursor} (`fun(pos: [integer, integer])`) See |Pos:cursor()|.
4001+
• {to_extmark} (`fun(pos: vim.Pos): [integer, integer]`) See
4002+
|Pos:to_extmark()|.
4003+
{extmark} (`fun(pos: [integer, integer])`) See |Pos:extmark()|.
39984004

39994005

4006+
Pos:cursor({pos}) *Pos:cursor()*
4007+
Creates a new |vim.Pos| from cursor position.
4008+
4009+
Parameters: ~
4010+
{pos} (`[integer, integer]`)
4011+
4012+
Pos:extmark({pos}) *Pos:extmark()*
4013+
Creates a new |vim.Pos| from extmark position.
4014+
4015+
Parameters: ~
4016+
{pos} (`[integer, integer]`)
4017+
40004018
Pos:lsp({buf}, {pos}, {position_encoding}) *Pos:lsp()*
40014019
Creates a new |vim.Pos| from `lsp.Position`.
40024020

@@ -4016,6 +4034,24 @@ Pos:lsp({buf}, {pos}, {position_encoding}) *Pos:lsp()*
40164034
{pos} (`lsp.Position`)
40174035
• {position_encoding} (`lsp.PositionEncodingKind`)
40184036

4037+
Pos:to_cursor({pos}) *Pos:to_cursor()*
4038+
Converts |vim.Pos| to cursor position.
4039+
4040+
Parameters: ~
4041+
{pos} (`vim.Pos`) See |vim.Pos|.
4042+
4043+
Return: ~
4044+
(`[integer, integer]`)
4045+
4046+
Pos:to_extmark({pos}) *Pos:to_extmark()*
4047+
Converts |vim.Pos| to extmark position.
4048+
4049+
Parameters: ~
4050+
{pos} (`vim.Pos`) See |vim.Pos|.
4051+
4052+
Return: ~
4053+
(`[integer, integer]`)
4054+
40194055
Pos:to_lsp({pos}, {position_encoding}) *Pos:to_lsp()*
40204056
Converts |vim.Pos| to `lsp.Position`.
40214057

runtime/doc/news.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ LSP
231231
• Support for related documents in pull diagnostics:
232232
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#relatedFullDocumentDiagnosticReport
233233
|vim.lsp.buf.signature_help()| supports "noActiveParameterSupport".
234+
• Support for `textDocument/inlineCompletion` |lsp-inline_completion|
235+
https://microsoft.github.io/language-server-protocol/specifications/lsp/3.18/specification/#textDocument_inlineCompletion
234236

235237
LUA
236238

runtime/doc/syntax.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,6 +5350,10 @@ PmenuMatchSel Popup menu: Matched text in selected item. Combined with
53505350
|hl-PmenuMatch| and |hl-PmenuSel|.
53515351
*hl-ComplMatchIns*
53525352
ComplMatchIns Matched text of the currently inserted completion.
5353+
*hl-ComplHint*
5354+
ComplHint Virtual text of the currently selected completion.
5355+
*hl-ComplHintMore*
5356+
ComplHintMore The additional information of the virtual text.
53535357
*hl-Question*
53545358
Question |hit-enter| prompt and yes/no questions.
53555359
*hl-QuickFixLine*

runtime/lua/vim/lsp.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ local lsp = vim._defer_require('vim.lsp', {
1616
document_color = ..., --- @module 'vim.lsp.document_color'
1717
handlers = ..., --- @module 'vim.lsp.handlers'
1818
inlay_hint = ..., --- @module 'vim.lsp.inlay_hint'
19+
inline_completion = ..., --- @module 'vim.lsp.inline_completion'
1920
linked_editing_range = ..., --- @module 'vim.lsp.linked_editing_range'
2021
log = ..., --- @module 'vim.lsp.log'
2122
protocol = ..., --- @module 'vim.lsp.protocol'

runtime/lua/vim/lsp/_capability.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ local api = vim.api
44
---| 'semantic_tokens'
55
---| 'folding_range'
66
---| 'linked_editing_range'
7+
---| 'inline_completion'
78

89
--- Tracks all supported capabilities, all of which derive from `vim.lsp.Capability`.
910
--- Returns capability *prototypes*, not their instances.

runtime/lua/vim/lsp/client.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ function Client:initialize()
514514
-- HACK: Capability modules must be loaded
515515
require('vim.lsp.semantic_tokens')
516516
require('vim.lsp._folding_range')
517+
require('vim.lsp.inline_completion')
517518

518519
local init_params = {
519520
-- The process Id of the parent process that started the server. Is null if
@@ -607,6 +608,7 @@ local static_registration_capabilities = {
607608
[ms.textDocument_foldingRange] = 'foldingRangeProvider',
608609
[ms.textDocument_implementation] = 'implementationProvider',
609610
[ms.textDocument_inlayHint] = 'inlayHintProvider',
611+
[ms.textDocument_inlineCompletion] = 'inlineCompletionProvider',
610612
[ms.textDocument_inlineValue] = 'inlineValueProvider',
611613
[ms.textDocument_linkedEditingRange] = 'linkedEditingRangeProvider',
612614
[ms.textDocument_moniker] = 'monikerProvider',

0 commit comments

Comments
 (0)