Compare commits

...

6 Commits

Author SHA1 Message Date
luukvbaal
8761681d09
Merge deae451b26 into 7121983c45 2024-12-18 17:41:49 +01:00
Lewis Russell
7121983c45 refactor(man.lua): various changes
- Replace all uses of vim.regex with simpler Lua patterns.
- Replace all uses of vim.fn.substitute with string.gsub.
- Rework error handling so expected errors are passed back via a return.
  - These get routed up an passed to `vim.notify()`
  - Any other errors will cause a stack trace.
- Reworked the module initialization of `localfile_arg`
- Updated all type annotations.
- Refactored CLI completion by introduction a parse_cmdline()
  function.
- Simplified `show_toc()`
- Refactor highlighting
- Inline some functions
- Fix completion on MacOS 13 and earlier.
  - Prefer `manpath -q` over `man -w`
- Make completion more efficient by avoiding vim.fn.sort and vim.fn.uniq
  - Reimplement using a single loop
2024-12-18 14:40:36 +00:00
phanium
888a803755
fix(lsp): vim.lsp.start fails if existing client has no workspace_folders #31608
Problem:
regression since https://github.com/neovim/neovim/pull/31340

`nvim -l repro.lua`:
```lua
vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls' }
vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls', root_dir = 'foo' }

-- swapped case will be ok:
-- vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls', root_dir = 'foo' }
-- vim.lsp.start { cmd = { 'lua-language-server' }, name = 'lua_ls' }
```

Failure:
```
E5113: Error while calling lua chunk: /…/lua/vim/lsp.lua:214: bad argument #1 to
'ipairs' (table expected, got nil)
stack traceback:
        [C]: in function 'ipairs'
        /…/lua/vim/lsp.lua:214: in function 'reuse_client'
        /…/lua/vim/lsp.lua:629: in function 'start'
        repro.lua:34: in main chunk
```
2024-12-18 06:37:12 -08:00
Peter Lithammer
07d5dc8938
feat(lsp): show server version in :checkhealth #31611
Problem:
Language server version information missing from `:checkhealth vim.lsp`.

Solution:
Store `InitializeResult.serverInfo.version` from the `initialize`
response and display for each client in `:checkhealth vim.lsp`.
2024-12-18 06:31:25 -08:00
Justin M. Keyes
f9eb68f340
fix(coverity): error handling CHECKED_RETURN #31618
CID 516406:  Error handling issues  (CHECKED_RETURN)
    /src/nvim/api/vimscript.c: 284 in nvim_call_dict_function()
    278       Object rv = OBJECT_INIT;
    279
    280       typval_T rettv;
    281       bool mustfree = false;
    282       switch (dict.type) {
    283       case kObjectTypeString:
    >>>     CID 516406:  Error handling issues  (CHECKED_RETURN)
    >>>     Calling "eval0" without checking return value (as is done elsewhere 10 out of 12 times).
    284         TRY_WRAP(err, {
    285           eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE);
    286           clear_evalarg(&EVALARG_EVALUATE, NULL);
    287         });
    288         if (ERROR_SET(err)) {
    289           return rv;
2024-12-18 06:05:37 -08:00
Luuk van Baal
deae451b26 feat(ui): builtin ext_cmdline completion popupmenu
Problem:  Enabling ext_cmdline implicitly requires ext_popupmenu
          to handle cmdline-completion with wildoptions=pum.
Solution: Allow marking a window as the ext_cmdline window through
          nvim_open_win(), including prompt offset. Anchor the cmdline-
          completion popupmenu to this window. Projected to be used
          with a default ext_cmdline/message replacement.
2024-12-16 12:40:55 +01:00
22 changed files with 559 additions and 432 deletions

View File

@ -3199,8 +3199,8 @@ nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()*
like a tooltip near the buffer text). like a tooltip near the buffer text).
• row: Row position in units of "screen cell height", may be • row: Row position in units of "screen cell height", may be
fractional. fractional.
• col: Column position in units of "screen cell width", may • col: Column position in units of screen cell width, may be
be fractional. fractional.
• focusable: Enable focus by user actions (wincmds, mouse • focusable: Enable focus by user actions (wincmds, mouse
events). Defaults to true. Non-focusable windows can be events). Defaults to true. Non-focusable windows can be
entered by |nvim_set_current_win()|, or, when the `mouse` entered by |nvim_set_current_win()|, or, when the `mouse`
@ -3290,6 +3290,9 @@ nvim_open_win({buffer}, {enter}, {config}) *nvim_open_win()*
• hide: If true the floating window will be hidden. • hide: If true the floating window will be hidden.
• vertical: Split vertically |:vertical|. • vertical: Split vertically |:vertical|.
• split: Split direction: "left", "right", "above", "below". • split: Split direction: "left", "right", "above", "below".
• _cmdline_offset: (EXPERIMENTAL) When provided, anchor the
|cmdline-completion| popupmenu to this window, with an
offset in screen cell width.
Return: ~ Return: ~
Window handle, or 0 on error Window handle, or 0 on error

View File

@ -1126,6 +1126,9 @@ Lua module: vim.lsp.client *lsp-client*
• {server_capabilities} (`lsp.ServerCapabilities?`) Response from the • {server_capabilities} (`lsp.ServerCapabilities?`) Response from the
server sent on `initialize` describing the server sent on `initialize` describing the
server's capabilities. server's capabilities.
• {server_info} (`lsp.ServerInfo?`) Response from the server
sent on `initialize` describing information
about the server.
• {progress} (`vim.lsp.Client.Progress`) A ring buffer • {progress} (`vim.lsp.Client.Progress`) A ring buffer
(|vim.ringbuf()|) containing progress messages (|vim.ringbuf()|) containing progress messages
sent by the server. See sent by the server. See

View File

@ -115,6 +115,7 @@ LSP
• |vim.lsp.util.make_position_params()|, |vim.lsp.util.make_range_params()| • |vim.lsp.util.make_position_params()|, |vim.lsp.util.make_range_params()|
and |vim.lsp.util.make_given_range_params()| now require the `position_encoding` and |vim.lsp.util.make_given_range_params()| now require the `position_encoding`
parameter. parameter.
• `:checkhealth vim.lsp` displays the server version (if available).
LUA LUA

File diff suppressed because it is too large Load Diff

View File

@ -1769,8 +1769,7 @@ function vim.api.nvim_open_term(buffer, opts) end
--- - `row=0` and `col=0` if `anchor` is "SW" or "SE" --- - `row=0` and `col=0` if `anchor` is "SW" or "SE"
--- (thus like a tooltip near the buffer text). --- (thus like a tooltip near the buffer text).
--- - row: Row position in units of "screen cell height", may be fractional. --- - row: Row position in units of "screen cell height", may be fractional.
--- - col: Column position in units of "screen cell width", may be --- - col: Column position in units of screen cell width, may be fractional.
--- fractional.
--- - focusable: Enable focus by user actions (wincmds, mouse events). --- - focusable: Enable focus by user actions (wincmds, mouse events).
--- Defaults to true. Non-focusable windows can be entered by --- Defaults to true. Non-focusable windows can be entered by
--- `nvim_set_current_win()`, or, when the `mouse` field is set to true, --- `nvim_set_current_win()`, or, when the `mouse` field is set to true,
@ -1856,6 +1855,8 @@ function vim.api.nvim_open_term(buffer, opts) end
--- - hide: If true the floating window will be hidden. --- - hide: If true the floating window will be hidden.
--- - vertical: Split vertically `:vertical`. --- - vertical: Split vertically `:vertical`.
--- - split: Split direction: "left", "right", "above", "below". --- - split: Split direction: "left", "right", "above", "below".
--- - _cmdline_offset: (EXPERIMENTAL) When provided, anchor the `cmdline-completion`
--- popupmenu to this window, with an offset in screen cell width.
--- @return integer # Window handle, or 0 on error --- @return integer # Window handle, or 0 on error
function vim.api.nvim_open_win(buffer, enter, config) end function vim.api.nvim_open_win(buffer, enter, config) end

View File

@ -307,6 +307,7 @@ error('Cannot require a meta file')
--- @field noautocmd? boolean --- @field noautocmd? boolean
--- @field fixed? boolean --- @field fixed? boolean
--- @field hide? boolean --- @field hide? boolean
--- @field _cmdline_offset? integer
--- @class vim.api.keyset.win_text_height --- @class vim.api.keyset.win_text_height
--- @field start_row? integer --- @field start_row? integer

View File

@ -211,7 +211,7 @@ local function reuse_client_default(client, config)
for _, config_folder in ipairs(config_folders) do for _, config_folder in ipairs(config_folders) do
local found = false local found = false
for _, client_folder in ipairs(client.workspace_folders) do for _, client_folder in ipairs(client.workspace_folders or {}) do
if config_folder.uri == client_folder.uri then if config_folder.uri == client_folder.uri then
found = true found = true
break break

View File

@ -174,6 +174,10 @@ local validate = vim.validate
--- capabilities. --- capabilities.
--- @field server_capabilities lsp.ServerCapabilities? --- @field server_capabilities lsp.ServerCapabilities?
--- ---
--- Response from the server sent on `initialize` describing information about
--- the server.
--- @field server_info lsp.ServerInfo?
---
--- A ring buffer (|vim.ringbuf()|) containing progress messages --- A ring buffer (|vim.ringbuf()|) containing progress messages
--- sent by the server. --- sent by the server.
--- @field progress vim.lsp.Client.Progress --- @field progress vim.lsp.Client.Progress
@ -556,6 +560,8 @@ function Client:initialize()
self.offset_encoding = self.server_capabilities.positionEncoding self.offset_encoding = self.server_capabilities.positionEncoding
end end
self.server_info = result.serverInfo
if next(self.settings) then if next(self.settings) then
self:notify(ms.workspace_didChangeConfiguration, { settings = self.settings }) self:notify(ms.workspace_didChangeConfiguration, { settings = self.settings })
end end

View File

@ -40,6 +40,8 @@ local function check_active_clients()
local clients = vim.lsp.get_clients() local clients = vim.lsp.get_clients()
if next(clients) then if next(clients) then
for _, client in pairs(clients) do for _, client in pairs(clients) do
local server_version = vim.tbl_get(client, 'server_info', 'version')
or '? (no serverInfo.version response)'
local cmd ---@type string local cmd ---@type string
local ccmd = client.config.cmd local ccmd = client.config.cmd
if type(ccmd) == 'table' then if type(ccmd) == 'table' then
@ -62,6 +64,7 @@ local function check_active_clients()
end end
report_info(table.concat({ report_info(table.concat({
string.format('%s (id: %d)', client.name, client.id), string.format('%s (id: %d)', client.name, client.id),
string.format('- Version: %s', server_version),
dirs_info, dirs_info,
string.format('- Command: %s', cmd), string.format('- Command: %s', cmd),
string.format('- Settings: %s', vim.inspect(client.settings, { newline = '\n ' })), string.format('- Settings: %s', vim.inspect(client.settings, { newline = '\n ' })),

View File

@ -8,9 +8,9 @@ vim.api.nvim_create_user_command('Man', function(params)
if params.bang then if params.bang then
man.init_pager() man.init_pager()
else else
local ok, err = pcall(man.open_page, params.count, params.smods, params.fargs) local err = man.open_page(params.count, params.smods, params.fargs)
if not ok then if err then
vim.notify(man.errormsg or err, vim.log.levels.ERROR) vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
end end
end end
end, { end, {
@ -31,6 +31,9 @@ vim.api.nvim_create_autocmd('BufReadCmd', {
pattern = 'man://*', pattern = 'man://*',
nested = true, nested = true,
callback = function(params) callback = function(params)
require('man').read_page(vim.fn.matchstr(params.match, 'man://\\zs.*')) local err = require('man').read_page(assert(params.match:match('man://(.*)')))
if err then
vim.notify('man.lua: ' .. err, vim.log.levels.ERROR)
end
end, end,
}) })

View File

@ -131,6 +131,7 @@ typedef struct {
Boolean noautocmd; Boolean noautocmd;
Boolean fixed; Boolean fixed;
Boolean hide; Boolean hide;
Integer _cmdline_offset;
} Dict(win_config); } Dict(win_config);
typedef struct { typedef struct {

View File

@ -229,10 +229,9 @@ static Object _call_function(String fn, Array args, dict_T *self, Arena *arena,
funcexe.fe_selfdict = self; funcexe.fe_selfdict = self;
TRY_WRAP(err, { TRY_WRAP(err, {
// call_func() retval is deceptive, ignore it. Instead we set `msg_list` // call_func() retval is deceptive, ignore it. Instead TRY_WRAP sets `msg_list` to capture
// (see above) to capture abort-causing non-exception errors. // abort-causing non-exception errors.
call_func(fn.data, (int)fn.size, &rettv, (int)args.size, (void)call_func(fn.data, (int)fn.size, &rettv, (int)args.size, vim_args, &funcexe);
vim_args, &funcexe);
}); });
if (!ERROR_SET(err)) { if (!ERROR_SET(err)) {
@ -280,18 +279,23 @@ Object nvim_call_dict_function(Object dict, String fn, Array args, Arena *arena,
typval_T rettv; typval_T rettv;
bool mustfree = false; bool mustfree = false;
switch (dict.type) { switch (dict.type) {
case kObjectTypeString: case kObjectTypeString: {
int eval_ret;
TRY_WRAP(err, { TRY_WRAP(err, {
eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE); eval_ret = eval0(dict.data.string.data, &rettv, NULL, &EVALARG_EVALUATE);
clear_evalarg(&EVALARG_EVALUATE, NULL); clear_evalarg(&EVALARG_EVALUATE, NULL);
}); });
if (ERROR_SET(err)) { if (ERROR_SET(err)) {
return rv; return rv;
} }
if (eval_ret != OK) {
abort(); // Should not happen.
}
// Evaluation of the string arg created a new dict or increased the // Evaluation of the string arg created a new dict or increased the
// refcount of a dict. Not necessary for a RPC dict. // refcount of a dict. Not necessary for a RPC dict.
mustfree = true; mustfree = true;
break; break;
}
case kObjectTypeDict: case kObjectTypeDict:
object_to_vim(dict, &rettv, err); object_to_vim(dict, &rettv, err);
break; break;

View File

@ -125,8 +125,7 @@
/// - `row=0` and `col=0` if `anchor` is "SW" or "SE" /// - `row=0` and `col=0` if `anchor` is "SW" or "SE"
/// (thus like a tooltip near the buffer text). /// (thus like a tooltip near the buffer text).
/// - row: Row position in units of "screen cell height", may be fractional. /// - row: Row position in units of "screen cell height", may be fractional.
/// - col: Column position in units of "screen cell width", may be /// - col: Column position in units of screen cell width, may be fractional.
/// fractional.
/// - focusable: Enable focus by user actions (wincmds, mouse events). /// - focusable: Enable focus by user actions (wincmds, mouse events).
/// Defaults to true. Non-focusable windows can be entered by /// Defaults to true. Non-focusable windows can be entered by
/// |nvim_set_current_win()|, or, when the `mouse` field is set to true, /// |nvim_set_current_win()|, or, when the `mouse` field is set to true,
@ -212,6 +211,8 @@
/// - hide: If true the floating window will be hidden. /// - hide: If true the floating window will be hidden.
/// - vertical: Split vertically |:vertical|. /// - vertical: Split vertically |:vertical|.
/// - split: Split direction: "left", "right", "above", "below". /// - split: Split direction: "left", "right", "above", "below".
/// - _cmdline_offset: (EXPERIMENTAL) When provided, anchor the |cmdline-completion|
/// popupmenu to this window, with an offset in screen cell width.
/// ///
/// @param[out] err Error details, if any /// @param[out] err Error details, if any
/// ///
@ -295,6 +296,10 @@ Window nvim_open_win(Buffer buffer, Boolean enter, Dict(win_config) *config, Err
goto cleanup; goto cleanup;
} }
if (fconfig._cmdline_offset < INT_MAX) {
cmdline_win = wp;
}
// Autocommands may close `wp` or move it to another tabpage, so update and check `tp` after each // Autocommands may close `wp` or move it to another tabpage, so update and check `tp` after each
// event. In each case, `wp` should already be valid in `tp`, so switch_win should not fail. // event. In each case, `wp` should already be valid in `tp`, so switch_win should not fail.
// Also, autocommands may free the `buf` to switch to, so store a bufref to check. // Also, autocommands may free the `buf` to switch to, so store a bufref to check.
@ -643,6 +648,11 @@ restore_curwin:
didset_window_options(win, true); didset_window_options(win, true);
} }
} }
if (fconfig._cmdline_offset < INT_MAX) {
cmdline_win = win;
} else if (win == cmdline_win && fconfig._cmdline_offset == INT_MAX) {
cmdline_win = NULL;
}
#undef HAS_KEY_X #undef HAS_KEY_X
} }
@ -773,6 +783,9 @@ Dict(win_config) nvim_win_get_config(Window window, Arena *arena, Error *err)
const char *rel = (wp->w_floating && !config->external const char *rel = (wp->w_floating && !config->external
? float_relative_str[config->relative] : ""); ? float_relative_str[config->relative] : "");
PUT_KEY_X(rv, relative, cstr_as_string(rel)); PUT_KEY_X(rv, relative, cstr_as_string(rel));
if (config->_cmdline_offset < INT_MAX) {
PUT_KEY_X(rv, _cmdline_offset, config->_cmdline_offset);
}
return rv; return rv;
} }
@ -1320,6 +1333,10 @@ static bool parse_win_config(win_T *wp, Dict(win_config) *config, WinConfig *fco
fconfig->hide = config->hide; fconfig->hide = config->hide;
} }
if (HAS_KEY_X(config, _cmdline_offset)) {
fconfig->_cmdline_offset = (int)config->_cmdline_offset;
}
return true; return true;
fail: fail:

View File

@ -956,6 +956,7 @@ typedef struct {
bool noautocmd; bool noautocmd;
bool fixed; bool fixed;
bool hide; bool hide;
int _cmdline_offset;
} WinConfig; } WinConfig;
#define WIN_CONFIG_INIT ((WinConfig){ .height = 0, .width = 0, \ #define WIN_CONFIG_INIT ((WinConfig){ .height = 0, .width = 0, \
@ -969,7 +970,8 @@ typedef struct {
.style = kWinStyleUnused, \ .style = kWinStyleUnused, \
.noautocmd = false, \ .noautocmd = false, \
.hide = false, \ .hide = false, \
.fixed = false }) .fixed = false, \
._cmdline_offset = INT_MAX })
// Structure to store last cursor position and topline. Used by check_lnums() // Structure to store last cursor position and topline. Used by check_lnums()
// and reset_lnums(). // and reset_lnums().

View File

@ -365,7 +365,7 @@ static int cmdline_pum_create(CmdlineInfo *ccline, expand_T *xp, char **matches,
// Compute the popup menu starting column // Compute the popup menu starting column
char *endpos = showtail ? showmatches_gettail(xp->xp_pattern, true) : xp->xp_pattern; char *endpos = showtail ? showmatches_gettail(xp->xp_pattern, true) : xp->xp_pattern;
if (ui_has(kUICmdline)) { if (ui_has(kUICmdline) && cmdline_win == NULL) {
compl_startcol = (int)(endpos - ccline->cmdbuff); compl_startcol = (int)(endpos - ccline->cmdbuff);
} else { } else {
compl_startcol = cmd_screencol((int)(endpos - ccline->cmdbuff)); compl_startcol = cmd_screencol((int)(endpos - ccline->cmdbuff));
@ -1067,13 +1067,10 @@ int showmatches(expand_T *xp, bool wildmenu)
showtail = cmd_showtail; showtail = cmd_showtail;
} }
bool compl_use_pum = (ui_has(kUICmdline) // Cmdline completion popup menu with ext_wildmenu, or wildoptions=pum and
? ui_has(kUIPopupmenu) // no ext_cmdline, or ext_popupmenu, or cmdline_win set (_cmdline_offset).
: wildmenu && (wop_flags & kOptWopFlagPum)) if (ui_has(kUIWildmenu) || ((!ui_has(kUICmdline) || ui_has(kUIPopupmenu) || cmdline_win != NULL)
|| ui_has(kUIWildmenu); && wildmenu && (wop_flags & kOptWopFlagPum))) {
if (compl_use_pum) {
// cmdline completion popup menu (with wildoptions=pum)
return cmdline_pum_create(ccline, xp, matches, numMatches, showtail); return cmdline_pum_create(ccline, xp, matches, numMatches, showtail);
} }

View File

@ -2944,10 +2944,9 @@ static int cmd_startcol(void)
int cmd_screencol(int bytepos) int cmd_screencol(int bytepos)
{ {
int m; // maximum column int m; // maximum column
int col = cmd_startcol(); int col = cmd_startcol();
if (KeyTyped) { if (KeyTyped) {
m = Columns * Rows; m = cmdline_win ? cmdline_win->w_width_inner * cmdline_win->w_height_inner : Columns * Rows;
if (m < 0) { // overflow, Columns or Rows at weird value if (m < 0) { // overflow, Columns or Rows at weird value
m = MAXCOL; m = MAXCOL;
} }

View File

@ -744,6 +744,7 @@ EXTERN int cmdwin_level INIT( = 0); ///< cmdline recursion level
EXTERN buf_T *cmdwin_buf INIT( = NULL); ///< buffer of cmdline window or NULL EXTERN buf_T *cmdwin_buf INIT( = NULL); ///< buffer of cmdline window or NULL
EXTERN win_T *cmdwin_win INIT( = NULL); ///< window of cmdline window or NULL EXTERN win_T *cmdwin_win INIT( = NULL); ///< window of cmdline window or NULL
EXTERN win_T *cmdwin_old_curwin INIT( = NULL); ///< curwin before opening cmdline window or NULL EXTERN win_T *cmdwin_old_curwin INIT( = NULL); ///< curwin before opening cmdline window or NULL
EXTERN win_T *cmdline_win INIT( = NULL); ///< window in use by ext_cmdline
EXTERN char no_lines_msg[] INIT( = N_("--No lines in buffer--")); EXTERN char no_lines_msg[] INIT( = N_("--No lines in buffer--"));

View File

@ -154,11 +154,12 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
validate_cursor_col(curwin); validate_cursor_col(curwin);
int above_row = 0; int above_row = 0;
int below_row = cmdline_row; int below_row = cmdline_row;
win_T *target_win = (State == MODE_CMDLINE) ? cmdline_win : curwin;
// wildoptions=pum // wildoptions=pum
if (State == MODE_CMDLINE) { if (State == MODE_CMDLINE) {
pum_win_row = ui_has(kUICmdline) ? 0 : cmdline_row; pum_win_row = cmdline_win ? cmdline_win->w_wrow : ui_has(kUICmdline) ? 0 : cmdline_row;
cursor_col = cmd_startcol; cursor_col = (cmdline_win ? cmdline_win->w_config._cmdline_offset : 0) + cmd_startcol;
cursor_col %= cmdline_win ? cmdline_win->w_width_inner : Columns;
pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE; pum_anchor_grid = ui_has(kUICmdline) ? -1 : DEFAULT_GRID_HANDLE;
} else { } else {
// anchor position: the start of the completed word // anchor position: the start of the completed word
@ -168,14 +169,16 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
} else { } else {
cursor_col = curwin->w_wcol; cursor_col = curwin->w_wcol;
} }
pum_anchor_grid = (int)curwin->w_grid.target->handle; pum_anchor_grid = (int)curwin->w_grid.target->handle;
pum_win_row += curwin->w_grid.row_offset; }
cursor_col += curwin->w_grid.col_offset;
if (!ui_has(kUIMultigrid) && curwin->w_grid.target != &default_grid) { if (target_win != NULL) {
pum_win_row += target_win->w_grid.row_offset;
cursor_col += target_win->w_grid.col_offset;
if (!ui_has(kUIMultigrid) && target_win->w_grid.target != &default_grid) {
pum_anchor_grid = (int)default_grid.handle; pum_anchor_grid = (int)default_grid.handle;
pum_win_row += curwin->w_winrow; pum_win_row += target_win->w_winrow;
cursor_col += curwin->w_wincol; cursor_col += target_win->w_wincol;
} }
} }
@ -221,16 +224,16 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
int min_row = 0; int min_row = 0;
int min_col = 0; int min_col = 0;
int max_col = Columns; int max_col = Columns;
int win_start_col = curwin->w_wincol; int win_start_col = target_win ? target_win->w_wincol : 0;
int win_end_col = W_ENDCOL(curwin); int win_end_col = target_win ? W_ENDCOL(target_win) : 0;
if (!(State & MODE_CMDLINE) && ui_has(kUIMultigrid)) { if (target_win != NULL && ui_has(kUIMultigrid)) {
above_row -= curwin->w_winrow; above_row -= target_win->w_winrow;
below_row = MAX(below_row - curwin->w_winrow, curwin->w_grid.rows); below_row = MAX(below_row - target_win->w_winrow, target_win->w_grid.rows);
min_row = -curwin->w_winrow; min_row = -target_win->w_winrow;
min_col = -curwin->w_wincol; min_col = -target_win->w_wincol;
max_col = MAX(Columns - curwin->w_wincol, curwin->w_grid.cols); max_col = MAX(Columns - target_win->w_wincol, target_win->w_grid.cols);
win_start_col = 0; win_start_col = 0;
win_end_col = curwin->w_grid.cols; win_end_col = target_win->w_grid.cols;
} }
// Figure out the size and position of the pum. // Figure out the size and position of the pum.
@ -246,12 +249,12 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// pum above "pum_win_row" // pum above "pum_win_row"
pum_above = true; pum_above = true;
if (State == MODE_CMDLINE) { if (State == MODE_CMDLINE && target_win == NULL) {
// for cmdline pum, no need for context lines // For cmdline pum, no need for context lines unless target_win is set
context_lines = 0; context_lines = 0;
} else { } else {
// Leave two lines of context if possible // Leave two lines of context if possible
context_lines = MIN(2, curwin->w_wrow - curwin->w_cline_row); context_lines = MIN(2, target_win->w_wrow - target_win->w_cline_row);
} }
if (pum_win_row - min_row >= size + context_lines) { if (pum_win_row - min_row >= size + context_lines) {
@ -270,14 +273,14 @@ void pum_display(pumitem_T *array, int size, int selected, bool array_changed, i
// pum below "pum_win_row" // pum below "pum_win_row"
pum_above = false; pum_above = false;
if (State == MODE_CMDLINE) { if (State == MODE_CMDLINE && target_win == NULL) {
// for cmdline pum, no need for context lines // for cmdline pum, no need for context lines unless target_win is set
context_lines = 0; context_lines = 0;
} else { } else {
// Leave two lines of context if possible // Leave two lines of context if possible
validate_cheight(curwin); validate_cheight(target_win);
int cline_visible_offset = curwin->w_cline_row + int cline_visible_offset = target_win->w_cline_row +
curwin->w_cline_height - curwin->w_wrow; target_win->w_cline_height - target_win->w_wrow;
context_lines = MIN(3, cline_visible_offset); context_lines = MIN(3, cline_visible_offset);
} }

View File

@ -306,6 +306,100 @@ describe('vim.ui_attach', function()
}, },
}) })
end) end)
it('ext_cmdline completion popupmenu', function()
screen:try_resize(screen._width, 10)
screen:add_extra_attr_ids { [100] = { background = Screen.colors.Black } }
exec_lua([[
vim.o.wildoptions = 'pum'
local buf = vim.api.nvim_create_buf(false, true)
vim.cmd('call setline(1, range(1, 10))')
_G.win = vim.api.nvim_open_win(buf, false, {
relative = 'editor',
col = 3,
row = 3,
width = 20,
height = 1,
style = 'minimal',
focusable = false,
zindex = 300,
_cmdline_offset = 0,
})
vim.ui_attach(ns, { ext_cmdline = true }, function(event, content, _, firstc)
if event == 'cmdline_show' then
local prompt = vim.api.nvim_win_get_config(_G.win)._cmdline_offset == 0
prompt = (prompt and firstc or 'Excommand:') .. content[1][2]
vim.api.nvim_buf_set_lines(buf, -2, -1, false, { prompt })
vim.api.nvim_win_set_cursor(_G.win, { 1, #prompt })
vim.api.nvim__redraw({ win = _G.win, cursor = true, flush = true })
end
return true
end)
vim.api.nvim_set_hl(0, 'Pmenu', {})
]])
feed(':call buf<tab>')
screen:expect([[
1 |
2 |
3 |
4 :call bufadd^( |
5 {12: bufadd( }{100: } |
6 bufexists( {100: } |
7 buffer_exists( {12: } |
8 buffer_name( {12: } |
9 buffer_number( {12: } |
|
]])
exec_lua([[
vim.api.nvim_win_set_config(_G.win, {
relative = 'editor',
col = 0,
row = 1000,
width = 1000,
height = 1,
})
]])
screen:expect([[
1 |
2 |
3 |
4 |
5 {12: bufadd( }{100: } |
6 bufexists( {100: } |
7 buffer_exists( {12: } |
8 buffer_name( {12: } |
9 buffer_number( {12: } |
:call bufadd^( |
]])
feed('<tab>')
screen:expect([[
1 bufadd( {100: } |
2 {12: bufexists( }{100: } |
3 buffer_exists( {100: } |
4 buffer_name( {100: } |
5 buffer_number( {100: } |
6 buflisted( {100: } |
7 bufload( {12: } |
8 bufloaded( {12: } |
9 bufname( {12: } |
:call bufexists^( |
]])
-- Test different offset (e.g. for custom prompt)
exec_lua('vim.api.nvim_win_set_config(_G.win, { _cmdline_offset = 9 })')
feed('<Esc>:call buf<Tab>')
screen:expect([[
1 {12: bufadd( }{100: } |
2 bufexists( {100: } |
3 buffer_exists( {100: } |
4 buffer_name( {100: } |
5 buffer_number( {100: } |
6 buflisted( {100: } |
7 bufload( {12: } |
8 bufloaded( {12: } |
9 bufname( {12: } |
Excommand:call bufadd^( |
]])
end)
end) end)
describe('vim.ui_attach', function() describe('vim.ui_attach', function()

View File

@ -1854,6 +1854,20 @@ describe('LSP', function()
end, end,
} }
end) end)
it('vim.lsp.start when existing client has no workspace_folders', function()
exec_lua(create_server_definition)
eq(
{ 2, 'foo', 'foo' },
exec_lua(function()
local server = _G._create_server()
vim.lsp.start { cmd = server.cmd, name = 'foo' }
vim.lsp.start { cmd = server.cmd, name = 'foo', root_dir = 'bar' }
local foos = vim.lsp.get_clients()
return { #foos, foos[1].name, foos[2].name }
end)
)
end)
end) end)
describe('parsing tests', function() describe('parsing tests', function()

View File

@ -21,13 +21,12 @@ local function get_search_history(name)
local man = require('man') local man = require('man')
local res = {} local res = {}
--- @diagnostic disable-next-line:duplicate-set-field --- @diagnostic disable-next-line:duplicate-set-field
man.find_path = function(sect, name0) man._find_path = function(name0, sect)
table.insert(res, { sect, name0 }) table.insert(res, { sect, name0 })
return nil return nil
end end
local ok, rv = pcall(man.open_page, -1, { tab = 0 }, args) local err = man.open_page(-1, { tab = 0 }, args)
assert(not ok) assert(err and err:match('no manual entry'))
assert(rv and rv:match('no manual entry'))
return res return res
end) end)
end end
@ -225,7 +224,7 @@ describe(':Man', function()
matches('^/.+', actual_file) matches('^/.+', actual_file)
local args = { nvim_prog, '--headless', '+:Man ' .. actual_file, '+q' } local args = { nvim_prog, '--headless', '+:Man ' .. actual_file, '+q' }
matches( matches(
('Error detected while processing command line:\r\n' .. 'man.lua: "no manual entry for %s"'):format( ('Error detected while processing command line:\r\n' .. 'man.lua: no manual entry for %s'):format(
pesc(actual_file) pesc(actual_file)
), ),
fn.system(args, { '' }) fn.system(args, { '' })
@ -235,8 +234,8 @@ describe(':Man', function()
it('tries variants with spaces, underscores #22503', function() it('tries variants with spaces, underscores #22503', function()
eq({ eq({
{ '', 'NAME WITH SPACES' }, { vim.NIL, 'NAME WITH SPACES' },
{ '', 'NAME_WITH_SPACES' }, { vim.NIL, 'NAME_WITH_SPACES' },
}, get_search_history('NAME WITH SPACES')) }, get_search_history('NAME WITH SPACES'))
eq({ eq({
{ '3', 'some other man' }, { '3', 'some other man' },
@ -255,8 +254,8 @@ describe(':Man', function()
{ 'n', 'some_other_man' }, { 'n', 'some_other_man' },
}, get_search_history('n some other man')) }, get_search_history('n some other man'))
eq({ eq({
{ '', '123some other man' }, { vim.NIL, '123some other man' },
{ '', '123some_other_man' }, { vim.NIL, '123some_other_man' },
}, get_search_history('123some other man')) }, get_search_history('123some other man'))
eq({ eq({
{ '1', 'other_man' }, { '1', 'other_man' },
@ -265,11 +264,10 @@ describe(':Man', function()
end) end)
it('can complete', function() it('can complete', function()
t.skip(t.is_os('mac') and t.is_arch('x86_64'), 'not supported on intel mac')
eq( eq(
true, true,
exec_lua(function() exec_lua(function()
return #require('man').man_complete('f', 'Man g') > 0 return #require('man').man_complete('f', 'Man f') > 0
end) end)
) )
end) end)

View File

@ -623,8 +623,7 @@ local function test_cmdline(linegrid)
{ 'unplace', '', '', '' }, { 'unplace', '', '', '' },
} }
command('set wildmode=full') command('set wildmode=full wildmenu wildoptions=pum')
command('set wildmenu')
screen:set_option('ext_popupmenu', true) screen:set_option('ext_popupmenu', true)
feed(':sign <tab>') feed(':sign <tab>')