diff options
60 files changed, 578 insertions, 352 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7699233ea3..399ac24ecc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -83,8 +83,10 @@ jobs: args: --check runtime/ - if: success() || failure() && steps.abort_job.outputs.status == 'success' - name: lintlua - run: make lintlua + name: luacheck + run: | + cmake -B $BUILD_DIR -G Ninja + cmake --build $BUILD_DIR --target lintlua-luacheck - if: success() || failure() && steps.abort_job.outputs.status == 'success' name: lintsh @@ -162,8 +164,8 @@ jobs: run: echo "status=${{ job.status }}" >> $GITHUB_OUTPUT - if: success() || failure() && steps.abort_job.outputs.status == 'success' - name: lintc - run: make lintc + name: clint.py + run: cmake --build build --target lintc-clint - if: success() || failure() && steps.abort_job.outputs.status == 'success' name: check-single-includes diff --git a/cmake.config/iwyu/mapping.imp b/cmake.config/iwyu/mapping.imp index 592c60b756..4e55aa9875 100644 --- a/cmake.config/iwyu/mapping.imp +++ b/cmake.config/iwyu/mapping.imp @@ -178,6 +178,8 @@ { include: [ '"regexp_bt.h.generated.h"', private, '"nvim/regexp.h"', public ] }, { include: [ '"ui_events_call.h.generated.h"', private, '"nvim/ui.h"', public ] }, { include: [ '"ui_events_client.h.generated.h"', private, '"nvim/ui_client.h"', public ] }, + { include: [ '"ui_events_remote.generated.h"', private, '"nvim/api/ui.h"', public ] }, + { include: [ '"ui_events_remote.h.generated.h"', private, '"nvim/api/ui.h"', public ] }, # Def to normal headers: nvim/header_defs.h -> nvim/header.h # diff --git a/cmake/Util.cmake b/cmake/Util.cmake index a86ced89d6..e15b44d29a 100644 --- a/cmake/Util.cmake +++ b/cmake/Util.cmake @@ -79,12 +79,13 @@ function(add_glob_target) file(TO_CMAKE_PATH "${f}" f) list(APPEND globfiles ${f}) endforeach() - foreach(exclude_pattern ${ARG_EXCLUDE}) - list(FILTER globfiles EXCLUDE REGEX ${exclude_pattern}) - endforeach() list(APPEND ARG_FILES ${globfiles}) endforeach() + foreach(exclude_pattern ${ARG_EXCLUDE}) + list(FILTER ARG_FILES EXCLUDE REGEX ${exclude_pattern}) + endforeach() + if(NOT ARG_TOUCH_STRATEGY) set(ARG_TOUCH_STRATEGY PER_FILE) endif() diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 16d0bcb612..49b5c9da70 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -132,8 +132,7 @@ back to Lua's default search mechanism. The first script found is run and The return value is cached after the first call to `require()` for each module, with subsequent calls returning the cached value without searching for, or -executing any script. For further details on `require()`, see the Lua -documentation at https://www.lua.org/manual/5.1/manual.html#pdf-require. +executing any script. For further details on `require()`, see |luaref-require()|. For example, if 'runtimepath' is `foo,bar` and |package.cpath| was `./?.so;./?.dll` at startup, `require('mod')` searches these paths in order @@ -1641,6 +1640,7 @@ gsplit({s}, {sep}, {plain}) *vim.gsplit()* See also: ~ |vim.split()| + |luaref-patterns| https://www.lua.org/pil/20.2.html http://lua-users.org/wiki/StringLibraryTutorial @@ -1913,6 +1913,7 @@ trim({s}) *vim.trim()* (string) String with whitespace removed from its beginning and end See also: ~ + |luaref-patterns| https://www.lua.org/pil/20.2.html validate({opt}) *vim.validate()* diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt index ce07c3035c..719c6037e6 100644 --- a/runtime/doc/news.txt +++ b/runtime/doc/news.txt @@ -164,6 +164,10 @@ REMOVED FEATURES *news-removed* The following deprecated functions or APIs were removed. +• It is no longer possible to scroll the whole screen when showing messages + longer than 'cmdheight'. |msgsep| is now always enabled even if 'display' + doesn't contain the "msgsep" flag. + • `filetype.vim` is removed in favor of |lua-filetype| (Note that filetype logic and tests still align with Vim, so additions or changes need to be contributed there first.) diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index c00b921d5c..e11574ee97 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -1,6 +1,22 @@ local M = {} local health = require('vim.health') +local fn_bool = function(key) + return function(...) + return vim.fn[key](...) == 1 + end +end + +local has = fn_bool('has') +local executable = fn_bool('executable') +local empty = fn_bool('empty') +local filereadable = fn_bool('filereadable') +local filewritable = fn_bool('filewritable') + +local shell_error = function() + return vim.v.shell_error ~= 0 +end + local suggest_faq = 'https://github.com/neovim/neovim/wiki/Building-Neovim#optimized-builds' local function check_runtime() @@ -37,15 +53,6 @@ end local function check_config() health.report_start('Configuration') local ok = true - local empty = function(o) - return 0 ~= vim.fn.empty(o) - end - local filereadable = function(o) - return 0 ~= vim.fn.filereadable(o) - end - local filewritable = function(o) - return 0 ~= vim.fn.filewritable(o) - end local vimrc = ( empty(vim.env.MYVIMRC) and vim.fn.stdpath('config') .. '/init.vim' or vim.env.MYVIMRC @@ -65,7 +72,7 @@ local function check_config() health.report_error('$VIM is invalid: ' .. vim.env.VIM) end - if 1 == vim.fn.exists('$NVIM_TUI_ENABLE_CURSOR_SHAPE') then + if vim.env.NVIM_TUI_ENABLE_CURSOR_SHAPE then ok = false health.report_warn('$NVIM_TUI_ENABLE_CURSOR_SHAPE is ignored in Nvim 0.2+', { "Use the 'guicursor' option to configure cursor shape. :help 'guicursor'", @@ -139,240 +146,245 @@ local function check_config() end local function check_performance() - vim.api.nvim_exec([=[ - func! s:check_performance() abort - let s:suggest_faq = ']=] .. suggest_faq .. [=[' - - call health#report_start('Performance') - - " check buildtype - let s:buildtype = matchstr(execute('version'), '\v\cbuild type:?\s*[^\n\r\t ]+') - if empty(s:buildtype) - call health#report_error('failed to get build type from :version') - elseif s:buildtype =~# '\v(MinSizeRel|Release|RelWithDebInfo)' - call health#report_ok(s:buildtype) - else - call health#report_info(s:buildtype) - call health#report_warn( - \ 'Non-optimized '.(has('debug')?'(DEBUG) ':'').'build. Nvim will be slower.', - \ ['Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo`.', - \ s:suggest_faq]) - endif - - " check for slow shell invocation - let s:slow_cmd_time = 1.5 - let s:start_time = reltime() - call system('echo') - let s:elapsed_time = reltimefloat(reltime(s:start_time)) - if s:elapsed_time > s:slow_cmd_time - call health#report_warn( - \ 'Slow shell invocation (took '.printf('%.2f', s:elapsed_time).' seconds).') - endif - endf - - call s:check_performance() - ]=], false) + health.report_start('Performance') + + -- Check buildtype + local buildtype = vim.fn.matchstr(vim.fn.execute('version'), [[\v\cbuild type:?\s*[^\n\r\t ]+]]) + if empty(buildtype) then + health.report_error('failed to get build type from :version') + elseif vim.regex([[\v(MinSizeRel|Release|RelWithDebInfo)]]):match_str(buildtype) then + health.report_ok(buildtype) + else + health.report_info(buildtype) + health.report_warn( + 'Non-optimized ' .. (has('debug') and '(DEBUG) ' or '') .. 'build. Nvim will be slower.', + { + 'Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo`.', + suggest_faq, + } + ) + end + + -- check for slow shell invocation + local slow_cmd_time = 1.5 + local start_time = vim.fn.reltime() + vim.fn.system('echo') + local elapsed_time = vim.fn.reltimefloat(vim.fn.reltime(start_time)) + if elapsed_time > slow_cmd_time then + health.report_warn( + 'Slow shell invocation (took ' .. vim.fn.printf('%.2f', elapsed_time) .. ' seconds).' + ) + end end -- Load the remote plugin manifest file and check for unregistered plugins local function check_rplugin_manifest() - vim.api.nvim_exec( - [=[ - func! s:check_rplugin_manifest() abort - call health#report_start('Remote Plugins') - let existing_rplugins = {} - - for item in remote#host#PluginsForHost('python') - let existing_rplugins[item.path] = 'python' - endfor - - for item in remote#host#PluginsForHost('python3') - let existing_rplugins[item.path] = 'python3' - endfor - - let require_update = 0 - - for path in map(split(&runtimepath, ','), 'resolve(v:val)') - let python_glob = glob(path.'/rplugin/python*', 1, 1) - if empty(python_glob) - continue - endif - - let python_dir = python_glob[0] - let python_version = fnamemodify(python_dir, ':t') - - for script in glob(python_dir.'/*.py', 1, 1) - \ + glob(python_dir.'/*/__init__.py', 1, 1) - let contents = join(readfile(script)) - if contents =~# '\<\%(from\|import\)\s\+neovim\>' - if script =~# '[\/]__init__\.py$' - let script = tr(fnamemodify(script, ':h'), '\', '/') - endif - - if !has_key(existing_rplugins, script) - let msg = printf('"%s" is not registered.', fnamemodify(path, ':t')) - if python_version ==# 'pythonx' - if !has('python3') - let msg .= ' (python3 not available)' - endif - elseif !has(python_version) - let msg .= printf(' (%s not available)', python_version) - else - let require_update = 1 - endif - - call health#report_warn(msg) - endif - - break - endif - endfor - endfor - - if require_update - call health#report_warn('Out of date', ['Run `:UpdateRemotePlugins`']) - else - call health#report_ok('Up to date') - endif - endf + health.report_start('Remote Plugins') - call s:check_rplugin_manifest() - ]=], - false - ) + local existing_rplugins = {} + for _, item in ipairs(vim.fn['remote#host#PluginsForHost']('python')) do + existing_rplugins[item.path] = 'python' + end + + for item in ipairs(vim.fn['remote#host#PluginsForHost']('python3')) do + existing_rplugins[item.path] = 'python3' + end + + local require_update = false + local handle_path = function(path) + local python_glob = vim.fn.glob(path .. '/rplugin/python*', true, true) + if empty(python_glob) then + return + end + + local python_dir = python_glob[1] + local python_version = vim.fn.fnamemodify(python_dir, ':t') + + local scripts = vim.fn.glob(python_dir .. '/*.py', true, true) + vim.list_extend(scripts, vim.fn.glob(python_dir .. '/*/__init__.py', true, true)) + + for script in ipairs(scripts) do + local contents = vim.fn.join(vim.fn.readfile(script)) + if vim.regex([[\<\%(from\|import\)\s\+neovim\>]]):match_str(contents) then + if vim.regex([[[\/]__init__\.py$]]):match_str(script) then + script = vim.fn.tr(vim.fn.fnamemodify(script, ':h'), '\\', '/') + end + if not existing_rplugins[script] then + local msg = vim.fn.printf('"%s" is not registered.', vim.fn.fnamemodify(path, ':t')) + if python_version == 'pythonx' then + if not has('python3') then + msg = msg .. ' (python3 not available)' + end + elseif not has(python_version) then + msg = msg .. vim.fn.printf(' (%s not available)', python_version) + else + require_update = true + end + + health.report_warn(msg) + end + + break + end + end + end + + for _, path in ipairs(vim.fn.map(vim.fn.split(vim.o.runtimepath, ','), 'resolve(v:val)')) do + handle_path(path) + end + + if require_update then + health.report_warn('Out of date', { 'Run `:UpdateRemotePlugins`' }) + else + health.report_ok('Up to date') + end end local function check_tmux() - vim.api.nvim_exec([=[ - let s:suggest_faq = ']=] .. suggest_faq .. [=[' - - func! s:get_tmux_option(option) abort - let cmd = 'tmux show-option -qvg '.a:option " try global scope - let out = system(split(cmd)) - let val = substitute(out, '\v(\s|\r|\n)', '', 'g') - if v:shell_error - call health#report_error('command failed: '.cmd."\n".out) + if empty(vim.env.TMUX) or not executable('tmux') then + return + end + + local get_tmux_option = function(option) + local cmd = 'tmux show-option -qvg ' .. option -- try global scope + local out = vim.fn.system(vim.fn.split(cmd)) + local val = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g') + if shell_error() then + health.report_error('command failed: ' .. cmd .. '\n' .. out) return 'error' - elseif empty(val) - let cmd = 'tmux show-option -qvgs '.a:option " try session scope - let out = system(split(cmd)) - let val = substitute(out, '\v(\s|\r|\n)', '', 'g') - if v:shell_error - call health#report_error('command failed: '.cmd."\n".out) + elseif empty(val) then + cmd = 'tmux show-option -qvgs ' .. option -- try session scope + out = vim.fn.system(vim.fn.split(cmd)) + val = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g') + if shell_error() then + health.report_error('command failed: ' .. cmd .. '\n' .. out) return 'error' - endif - endif + end + end return val - endf + end - func! s:check_tmux() abort - if empty($TMUX) || !executable('tmux') - return - endif - call health#report_start('tmux') - - " check escape-time - let suggestions = ["set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10", - \ s:suggest_faq] - let tmux_esc_time = s:get_tmux_option('escape-time') - if tmux_esc_time !=# 'error' - if empty(tmux_esc_time) - call health#report_error('`escape-time` is not set', suggestions) - elseif tmux_esc_time > 300 - call health#report_error( - \ '`escape-time` ('.tmux_esc_time.') is higher than 300ms', suggestions) - else - call health#report_ok('escape-time: '.tmux_esc_time) - endif - endif - - " check focus-events - let suggestions = ["(tmux 1.9+ only) Set `focus-events` in ~/.tmux.conf:\nset-option -g focus-events on"] - let tmux_focus_events = s:get_tmux_option('focus-events') - if tmux_focus_events !=# 'error' - if empty(tmux_focus_events) || tmux_focus_events !=# 'on' - call health#report_warn( - \ "`focus-events` is not enabled. |'autoread'| may not work.", suggestions) - else - call health#report_ok('focus-events: '.tmux_focus_events) - endif - endif - - " check default-terminal and $TERM - call health#report_info('$TERM: '.$TERM) - let cmd = 'tmux show-option -qvg default-terminal' - let out = system(split(cmd)) - let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g') - if empty(tmux_default_term) - let cmd = 'tmux show-option -qvgs default-terminal' - let out = system(split(cmd)) - let tmux_default_term = substitute(out, '\v(\s|\r|\n)', '', 'g') - endif - - if v:shell_error - call health#report_error('command failed: '.cmd."\n".out) - elseif tmux_default_term !=# $TERM - call health#report_info('default-terminal: '.tmux_default_term) - call health#report_error( - \ '$TERM differs from the tmux `default-terminal` setting. Colors might look wrong.', - \ ['$TERM may have been set by some rc (.bashrc, .zshrc, ...).']) - elseif $TERM !~# '\v(tmux-256color|screen-256color)' - call health#report_error( - \ '$TERM should be "screen-256color" or "tmux-256color" in tmux. Colors might look wrong.', - \ ["Set default-terminal in ~/.tmux.conf:\nset-option -g default-terminal \"screen-256color\"", - \ s:suggest_faq]) - endif - - " check for RGB capabilities - let info = system(['tmux', 'show-messages', '-JT']) - let has_tc = stridx(info, " Tc: (flag) true") != -1 - let has_rgb = stridx(info, " RGB: (flag) true") != -1 - if !has_tc && !has_rgb - call health#report_warn( - \ "Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.", - \ ["Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-overrides ',XXX:RGB'", - \ "For older tmux versions use this instead:\nset-option -ga terminal-overrides ',XXX:Tc'"]) - endif - endf - - call s:check_tmux() - ]=], false) + health.report_start('tmux') + + -- check escape-time + local suggestions = + { 'set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10', suggest_faq } + local tmux_esc_time = get_tmux_option('escape-time') + if tmux_esc_time ~= 'error' then + if empty(tmux_esc_time) then + health.report_error('`escape-time` is not set', suggestions) + elseif tmux_esc_time > 300 then + health.report_error( + '`escape-time` (' .. tmux_esc_time .. ') is higher than 300ms', + suggestions + ) + else + health.report_ok('escape-time: ' .. tmux_esc_time) + end + end + + -- check focus-events + local tmux_focus_events = get_tmux_option('focus-events') + if tmux_focus_events ~= 'error' then + if empty(tmux_focus_events) or tmux_focus_events ~= 'on' then + health.report_warn( + "`focus-events` is not enabled. |'autoread'| may not work.", + { '(tmux 1.9+ only) Set `focus-events` in ~/.tmux.conf:\nset-option -g focus-events on' } + ) + else + health.report_ok('focus-events: ' .. tmux_focus_events) + end + end + + -- check default-terminal and $TERM + health.report_info('$TERM: ' .. vim.env.TERM) + local cmd = 'tmux show-option -qvg default-terminal' + local out = vim.fn.system(vim.fn.split(cmd)) + local tmux_default_term = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g') + if empty(tmux_default_term) then + cmd = 'tmux show-option -qvgs default-terminal' + out = vim.fn.system(vim.fn.split(cmd)) + tmux_default_term = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g') + end + + if shell_error() then + health.report_error('command failed: ' .. cmd .. '\n' .. out) + elseif tmux_default_term ~= vim.env.TERM then + health.report_info('default-terminal: ' .. tmux_default_term) + health.report_error( + '$TERM differs from the tmux `default-terminal` setting. Colors might look wrong.', + { '$TERM may have been set by some rc (.bashrc, .zshrc, ...).' } + ) + elseif not vim.regex([[\v(tmux-256color|screen-256color)]]):match_str(vim.env.TERM) then + health.report_error( + '$TERM should be "screen-256color" or "tmux-256color" in tmux. Colors might look wrong.', + { + 'Set default-terminal in ~/.tmux.conf:\nset-option -g default-terminal "screen-256color"', + suggest_faq, + } + ) + end + + -- check for RGB capabilities + local info = vim.fn.system({ 'tmux', 'show-messages', '-JT' }) + local has_tc = vim.fn.stridx(info, ' Tc: (flag) true') ~= -1 + local has_rgb = vim.fn.stridx(info, ' RGB: (flag) true') ~= -1 + if not has_tc and not has_rgb then + health.report_warn( + "Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.", + { + "Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-overrides ',XXX:RGB'", + "For older tmux versions use this instead:\nset-option -ga terminal-overrides ',XXX:Tc'", + } + ) + end end local function check_terminal() - vim.api.nvim_exec( - [=[ - func! s:check_terminal() abort - if !executable('infocmp') - return - endif - call health#report_start('terminal') - let cmd = 'infocmp -L' - let out = system(split(cmd)) - let kbs_entry = matchstr(out, 'key_backspace=[^,[:space:]]*') - let kdch1_entry = matchstr(out, 'key_dc=[^,[:space:]]*') - - if v:shell_error - \ && (!has('win32') - \ || empty(matchstr(out, - \ 'infocmp: couldn''t open terminfo file .\+' - \ ..'\%(conemu\|vtpcon\|win32con\)'))) - call health#report_error('command failed: '.cmd."\n".out) - else - call health#report_info(printf('key_backspace (kbs) terminfo entry: `%s`', (empty(kbs_entry) ? '? (not found)' : kbs_entry))) - call health#report_info(printf('key_dc (kdch1) terminfo entry: `%s`', (empty(kbs_entry) ? '? (not found)' : kdch1_entry))) - endif - for env_var in ['XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY'] - if exists('$'.env_var) - call health#report_info(printf('$%s="%s"', env_var, eval('$'.env_var))) - endif - endfor - endf - - call s:check_terminal() - ]=], - false - ) + if not executable('infocmp') then + return + end + + health.report_start('terminal') + local cmd = 'infocmp -L' + local out = vim.fn.system(vim.fn.split(cmd)) + local kbs_entry = vim.fn.matchstr(out, 'key_backspace=[^,[:space:]]*') + local kdch1_entry = vim.fn.matchstr(out, 'key_dc=[^,[:space:]]*') + + if + shell_error() + and ( + not has('win32') + or empty( + vim.fn.matchstr( + out, + [[infocmp: couldn't open terminfo file .\+\%(conemu\|vtpcon\|win32con\)]] + ) + ) + ) + then + health.report_error('command failed: ' .. cmd .. '\n' .. out) + else + health.report_info( + vim.fn.printf( + 'key_backspace (kbs) terminfo entry: `%s`', + (empty(kbs_entry) and '? (not found)' or kbs_entry) + ) + ) + + health.report_info( + vim.fn.printf( + 'key_dc (kdch1) terminfo entry: `%s`', + (empty(kbs_entry) and '? (not found)' or kdch1_entry) + ) + ) + end + + for env_var in ipairs({ 'XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY' }) do + if vim.env[env_var] then + health.report_info(vim.fn.printf('$%s="%s"', env_var, vim.env[env_var])) + end + end end function M.check() diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua index b875da0abc..044880e076 100644 --- a/runtime/lua/vim/health.lua +++ b/runtime/lua/vim/health.lua @@ -23,7 +23,20 @@ end local path2name = function(path) if path:match('%.lua$') then -- Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp" - return path:gsub('.-lua[%\\%/]', '', 1):gsub('[%\\%/]', '.'):gsub('%.health.-$', '') + + -- Get full path, make sure all slashes are '/' + path = vim.fs.normalize(path) + + -- Remove everything up to the last /lua/ folder + path = path:gsub('^.*/lua/', '') + + -- Remove the filename (health.lua) + path = vim.fn.fnamemodify(path, ':h') + + -- Change slashes to dots + path = path:gsub('/', '.') + + return path else -- Vim: transform "../autoload/health/provider.vim" into "provider" return vim.fn.fnamemodify(path, ':t:r') diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua index cfd6c938f7..134a009a72 100644 --- a/runtime/lua/vim/lsp.lua +++ b/runtime/lua/vim/lsp.lua @@ -1557,15 +1557,21 @@ end --- Notify all attached clients that a buffer has changed. local text_document_did_change_handler do - text_document_did_change_handler = - function(_, bufnr, changedtick, firstline, lastline, new_lastline) - -- Detach (nvim_buf_attach) via returning True to on_lines if no clients are attached - if tbl_isempty(all_buffer_active_clients[bufnr] or {}) then - return true - end - util.buf_versions[bufnr] = changedtick - changetracking.send_changes(bufnr, firstline, lastline, new_lastline) + text_document_did_change_handler = function( + _, + bufnr, + changedtick, + firstline, + lastline, + new_lastline + ) + -- Detach (nvim_buf_attach) via returning True to on_lines if no clients are attached + if tbl_isempty(all_buffer_active_clients[bufnr] or {}) then + return true end + util.buf_versions[bufnr] = changedtick + changetracking.send_changes(bufnr, firstline, lastline, new_lastline) + end end ---@private diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua index b53c66ba63..7967d13943 100644 --- a/runtime/lua/vim/shared.lua +++ b/runtime/lua/vim/shared.lua @@ -60,6 +60,7 @@ end)() --- Splits a string at each instance of a separator. --- ---@see |vim.split()| +---@see |luaref-patterns| ---@see https://www.lua.org/pil/20.2.html ---@see http://lua-users.org/wiki/StringLibraryTutorial --- @@ -529,6 +530,7 @@ end --- Trim whitespace (Lua pattern "%s") from both sides of a string. --- +---@see |luaref-patterns| ---@see https://www.lua.org/pil/20.2.html ---@param s string String to trim ---@return string String with whitespace removed from its beginning and end diff --git a/src/nvim/CMakeLists.txt b/src/nvim/CMakeLists.txt index b95709526b..316f12e302 100755 --- a/src/nvim/CMakeLists.txt +++ b/src/nvim/CMakeLists.txt @@ -85,7 +85,7 @@ if(ENABLE_IWYU) string(APPEND iwyu_flags "-Xiwyu;--mapping_file=${PROJECT_SOURCE_DIR}/cmake.config/iwyu/gcc.symbols.imp") set_target_properties(nvim PROPERTIES C_INCLUDE_WHAT_YOU_USE "${iwyu_flags}") - target_compile_definitions(nvim PRIVATE EXITFREE) + target_compile_definitions(main_lib INTERFACE EXITFREE) endif() if(MSVC) @@ -977,7 +977,9 @@ add_glob_target( TARGET lintc-clint COMMAND ${PROJECT_SOURCE_DIR}/src/clint.py FLAGS --output=${LINT_OUTPUT_FORMAT} - FILES ${LINT_NVIM_SOURCES}) + FILES ${LINT_NVIM_SOURCES} + EXCLUDE + tui/terminfo_defs.h) add_custom_target(uncrustify-version COMMAND ${CMAKE_COMMAND} diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 4ff600618d..bf19c8c395 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -33,7 +33,6 @@ #include "nvim/pos.h" #include "nvim/ui.h" #include "nvim/version.h" -#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/private/funcs_metadata.generated.h" diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index 32b294c0ce..e67607a7e4 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -13,7 +13,11 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/api/ui.h" +#include "nvim/autocmd.h" #include "nvim/channel.h" +#include "nvim/event/loop.h" +#include "nvim/event/wstream.h" +#include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/main.h" @@ -27,13 +31,12 @@ #include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" -#include "nvim/window.h" #define BUF_POS(data) ((size_t)((data)->buf_wptr - (data)->buf)) #ifdef INCLUDE_GENERATED_DECLARATIONS # include "api/ui.c.generated.h" -# include "ui_events_remote.generated.h" +# include "ui_events_remote.generated.h" // IWYU pragma: export #endif static PMap(uint64_t) connected_uis = MAP_INIT; diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 4115743e1c..aa2d845728 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -13,6 +13,7 @@ #include <string.h> #include "auto/config.h" +#include "klib/kvec.h" #include "nvim/ascii.h" #include "nvim/buffer_defs.h" #include "nvim/charset.h" @@ -35,6 +36,7 @@ #include "nvim/plines.h" #include "nvim/pos.h" #include "nvim/state.h" +#include "nvim/strings.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/context.c b/src/nvim/context.c index b064a92b74..9de6c16536 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -5,7 +5,9 @@ #include <assert.h> #include <stdbool.h> +#include <stdint.h> #include <stdio.h> +#include <string.h> #include "nvim/api/private/converter.h" #include "nvim/api/private/helpers.h" @@ -23,8 +25,6 @@ #include "nvim/message.h" #include "nvim/option.h" #include "nvim/shada.h" -#include "nvim/types.h" -#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "context.c.generated.h" diff --git a/src/nvim/drawline.c b/src/nvim/drawline.c index 8fc1a4b029..77158e233a 100644 --- a/src/nvim/drawline.c +++ b/src/nvim/drawline.c @@ -21,7 +21,6 @@ #include "nvim/decoration_provider.h" #include "nvim/diff.h" #include "nvim/drawline.h" -#include "nvim/eval.h" #include "nvim/extmark_defs.h" #include "nvim/fold.h" #include "nvim/garray.h" diff --git a/src/nvim/eval/buffer.c b/src/nvim/eval/buffer.c index 72eb0f8d67..e8eca3f854 100644 --- a/src/nvim/eval/buffer.c +++ b/src/nvim/eval/buffer.c @@ -9,6 +9,7 @@ #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" +#include "nvim/buffer_defs.h" #include "nvim/change.h" #include "nvim/cursor.h" #include "nvim/eval.h" diff --git a/src/nvim/eval/encode.h b/src/nvim/eval/encode.h index e66dab1cff..41e7614fc0 100644 --- a/src/nvim/eval/encode.h +++ b/src/nvim/eval/encode.h @@ -4,6 +4,7 @@ #include <msgpack.h> #include <msgpack/pack.h> #include <stddef.h> +#include <string.h> #include "nvim/eval.h" #include "nvim/eval/typval.h" diff --git a/src/nvim/eval/userfunc.c b/src/nvim/eval/userfunc.c index c70d56cd25..1a3fd13fe3 100644 --- a/src/nvim/eval/userfunc.c +++ b/src/nvim/eval/userfunc.c @@ -45,6 +45,7 @@ #include "nvim/runtime.h" #include "nvim/search.h" #include "nvim/strings.h" +#include "nvim/types.h" #include "nvim/ui.h" #include "nvim/vim.h" diff --git a/src/nvim/eval/window.c b/src/nvim/eval/window.c index 4bcbc13534..b1e1669826 100644 --- a/src/nvim/eval/window.c +++ b/src/nvim/eval/window.c @@ -12,6 +12,7 @@ #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" +#include "nvim/buffer_defs.h" #include "nvim/cursor.h" #include "nvim/eval/funcs.h" #include "nvim/eval/typval.h" diff --git a/src/nvim/eval/window.h b/src/nvim/eval/window.h index 682a794113..995f0a55a9 100644 --- a/src/nvim/eval/window.h +++ b/src/nvim/eval/window.h @@ -2,9 +2,19 @@ #define NVIM_EVAL_WINDOW_H #include <stdbool.h> +#include <string.h> +#include "nvim/buffer.h" #include "nvim/buffer_defs.h" +#include "nvim/cursor.h" #include "nvim/eval/typval_defs.h" +#include "nvim/globals.h" +#include "nvim/mark.h" +#include "nvim/option_defs.h" +#include "nvim/os/os.h" +#include "nvim/pos.h" +#include "nvim/vim.h" +#include "nvim/window.h" /// Structure used by switch_win() to pass values to restore_win() typedef struct { diff --git a/src/nvim/event/libuv_process.c b/src/nvim/event/libuv_process.c index 10a09275d9..e528d21a71 100644 --- a/src/nvim/event/libuv_process.c +++ b/src/nvim/event/libuv_process.c @@ -1,6 +1,7 @@ // This is an open source non-commercial project. Dear PVS-Studio, please check // it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com +#include <assert.h> #include <stdint.h> #include <uv.h> @@ -12,6 +13,7 @@ #include "nvim/log.h" #include "nvim/macros.h" #include "nvim/os/os.h" +#include "nvim/ui_client.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/libuv_process.c.generated.h" diff --git a/src/nvim/event/process.c b/src/nvim/event/process.c index 9dfd6f329a..1a524a56ca 100644 --- a/src/nvim/event/process.c +++ b/src/nvim/event/process.c @@ -20,6 +20,7 @@ #include "nvim/os/shell.h" #include "nvim/os/time.h" #include "nvim/rbuffer.h" +#include "nvim/ui_client.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "event/process.c.generated.h" diff --git a/src/nvim/ex_session.c b/src/nvim/ex_session.c index cae9c18309..f15c2d258f 100644 --- a/src/nvim/ex_session.c +++ b/src/nvim/ex_session.c @@ -38,7 +38,6 @@ #include "nvim/path.h" #include "nvim/pos.h" #include "nvim/runtime.h" -#include "nvim/types.h" #include "nvim/vim.h" #include "nvim/window.h" diff --git a/src/nvim/hashtab.c b/src/nvim/hashtab.c index 042cb43ce4..f805d99d4b 100644 --- a/src/nvim/hashtab.c +++ b/src/nvim/hashtab.c @@ -30,6 +30,7 @@ #include "nvim/hashtab.h" #include "nvim/memory.h" #include "nvim/message.h" +#include "nvim/types.h" #include "nvim/vim.h" // Magic value for algorithm that walks through the array. diff --git a/src/nvim/indent.c b/src/nvim/indent.c index be1dfb77cf..ed4005d139 100644 --- a/src/nvim/indent.c +++ b/src/nvim/indent.c @@ -17,6 +17,7 @@ #include "nvim/edit.h" #include "nvim/eval.h" #include "nvim/eval/typval_defs.h" +#include "nvim/ex_cmds_defs.h" #include "nvim/ex_docmd.h" #include "nvim/extmark.h" #include "nvim/gettext.h" @@ -24,6 +25,7 @@ #include "nvim/indent.h" #include "nvim/indent_c.h" #include "nvim/mark.h" +#include "nvim/mbyte.h" #include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" diff --git a/src/nvim/indent_c.c b/src/nvim/indent_c.c index ccf4448e93..c2293add76 100644 --- a/src/nvim/indent_c.c +++ b/src/nvim/indent_c.c @@ -23,7 +23,6 @@ #include "nvim/pos.h" #include "nvim/search.h" #include "nvim/strings.h" -#include "nvim/types.h" #include "nvim/vim.h" // Find result cache for cpp_baseclass diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index fa8e78f624..ba948ff924 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -7,6 +7,7 @@ #include <limits.h> #include <stdbool.h> #include <stddef.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> diff --git a/src/nvim/linematch.c b/src/nvim/linematch.c index 629a31c913..a9dac40731 100644 --- a/src/nvim/linematch.c +++ b/src/nvim/linematch.c @@ -9,7 +9,6 @@ #include "nvim/linematch.h" #include "nvim/macros.h" #include "nvim/memory.h" -#include "nvim/vim.h" // struct for running the diff linematch algorithm typedef struct { diff --git a/src/nvim/lua/executor.c b/src/nvim/lua/executor.c index 12ddbd094f..f23310304f 100644 --- a/src/nvim/lua/executor.c +++ b/src/nvim/lua/executor.c @@ -49,6 +49,7 @@ #include "nvim/message.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/option_defs.h" +#include "nvim/os/fileio.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/pos.h" @@ -56,7 +57,6 @@ #include "nvim/runtime.h" #include "nvim/strings.h" #include "nvim/ui.h" -#include "nvim/ui_compositor.h" #include "nvim/undo.h" #include "nvim/usercmd.h" #include "nvim/version.h" diff --git a/src/nvim/main.c b/src/nvim/main.c index f41e054d73..4dfb00f2db 100644 --- a/src/nvim/main.c +++ b/src/nvim/main.c @@ -10,7 +10,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <time.h> #include "auto/config.h" #include "nvim/arglist.h" @@ -62,7 +61,6 @@ #include "nvim/os/fileio.h" #include "nvim/os/input.h" #include "nvim/os/os.h" -#include "nvim/os/pty_process.h" #include "nvim/os/stdpaths_defs.h" #include "nvim/os/time.h" #include "nvim/path.h" @@ -97,7 +95,6 @@ #include "nvim/msgpack_rpc/helpers.h" #include "nvim/msgpack_rpc/server.h" #include "nvim/os/signal.h" -#include "nvim/tui/tui.h" // values for "window_layout" enum { @@ -548,7 +545,9 @@ int main(int argc, char **argv) if (params.diff_mode) { // set options in each window for "nvim -d". FOR_ALL_WINDOWS_IN_TAB(wp, curtab) { - diff_win_options(wp, true); + if (!wp->w_arg_idx_invalid) { + diff_win_options(wp, true); + } } } diff --git a/src/nvim/mapping.c b/src/nvim/mapping.c index 04a0107fe8..2e1563760b 100644 --- a/src/nvim/mapping.c +++ b/src/nvim/mapping.c @@ -5,6 +5,7 @@ #include <assert.h> #include <inttypes.h> +#include <lauxlib.h> #include <limits.h> #include <stdbool.h> #include <stdio.h> diff --git a/src/nvim/mark.c b/src/nvim/mark.c index b98935e93d..a76472230d 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -5,6 +5,7 @@ #include <assert.h> #include <limits.h> +#include <stdint.h> #include <stdio.h> #include <string.h> @@ -39,7 +40,6 @@ #include "nvim/sign.h" #include "nvim/strings.h" #include "nvim/textobject.h" -#include "nvim/types.h" #include "nvim/undo_defs.h" #include "nvim/vim.h" diff --git a/src/nvim/memfile.c b/src/nvim/memfile.c index 61d7893948..46be9ccea5 100644 --- a/src/nvim/memfile.c +++ b/src/nvim/memfile.c @@ -62,7 +62,6 @@ #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/pos.h" -#include "nvim/types.h" #include "nvim/vim.h" #define MEMFILE_PAGE_SIZE 4096 /// default page size diff --git a/src/nvim/memory.c b/src/nvim/memory.c index aa8314b23d..5356300382 100644 --- a/src/nvim/memory.c +++ b/src/nvim/memory.c @@ -31,7 +31,6 @@ #include "nvim/message.h" #include "nvim/sign.h" #include "nvim/ui.h" -#include "nvim/ui_compositor.h" #include "nvim/usercmd.h" #include "nvim/vim.h" diff --git a/src/nvim/menu.c b/src/nvim/menu.c index 0fa45ac24a..2a18b08d8d 100644 --- a/src/nvim/menu.c +++ b/src/nvim/menu.c @@ -6,6 +6,7 @@ #include <assert.h> #include <stdbool.h> +#include <stdint.h> #include <string.h> #include "nvim/ascii.h" diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index b7d15fe9af..258f596ecc 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -3,6 +3,7 @@ #include <assert.h> #include <stdbool.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> diff --git a/src/nvim/move.c b/src/nvim/move.c index dc2f4b4844..ee9edb3dc4 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -27,12 +27,14 @@ #include "nvim/eval/window.h" #include "nvim/fold.h" #include "nvim/getchar.h" +#include "nvim/gettext.h" #include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/macros.h" #include "nvim/mbyte.h" #include "nvim/memline_defs.h" +#include "nvim/message.h" #include "nvim/mouse.h" #include "nvim/move.h" #include "nvim/option.h" diff --git a/src/nvim/msgpack_rpc/channel.c b/src/nvim/msgpack_rpc/channel.c index 0c23a7798c..d60e18590f 100644 --- a/src/nvim/msgpack_rpc/channel.c +++ b/src/nvim/msgpack_rpc/channel.c @@ -20,14 +20,15 @@ #include "nvim/channel.h" #include "nvim/event/defs.h" #include "nvim/event/loop.h" +#include "nvim/event/process.h" #include "nvim/event/rstream.h" #include "nvim/event/stream.h" #include "nvim/event/wstream.h" -#include "nvim/globals.h" #include "nvim/log.h" #include "nvim/main.h" #include "nvim/map.h" #include "nvim/memory.h" +#include "nvim/message.h" #include "nvim/msgpack_rpc/channel.h" #include "nvim/msgpack_rpc/channel_defs.h" #include "nvim/msgpack_rpc/helpers.h" diff --git a/src/nvim/normal.h b/src/nvim/normal.h index 90a5c4103e..bed1a40b97 100644 --- a/src/nvim/normal.h +++ b/src/nvim/normal.h @@ -4,6 +4,7 @@ #include <stdbool.h> #include "nvim/buffer_defs.h" +#include "nvim/macros.h" #include "nvim/pos.h" // Values for find_ident_under_cursor() diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index a97e9b7c7e..c8d5a10dbb 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -3,6 +3,7 @@ #include <assert.h> #include <stdbool.h> +#include <stdint.h> #include <string.h> #include "nvim/api/private/helpers.h" diff --git a/src/nvim/os/fileio.c b/src/nvim/os/fileio.c index e93e1febcb..5af39555c9 100644 --- a/src/nvim/os/fileio.c +++ b/src/nvim/os/fileio.c @@ -16,6 +16,8 @@ #include "auto/config.h" #include "nvim/gettext.h" +#include "nvim/globals.h" +#include "nvim/log.h" #include "nvim/macros.h" #include "nvim/memory.h" #include "nvim/message.h" diff --git a/src/nvim/os/fs.c b/src/nvim/os/fs.c index e0449d468a..98ec9aa826 100644 --- a/src/nvim/os/fs.c +++ b/src/nvim/os/fs.c @@ -302,7 +302,9 @@ static bool is_executable(const char *name, char **abspath) static bool is_executable_ext(const char *name, char **abspath) FUNC_ATTR_NONNULL_ARG(1) { - const bool is_unix_shell = strstr((char *)path_tail(p_sh), "sh") != NULL; + const bool is_unix_shell = strstr(path_tail(p_sh), "powershell") == NULL + && strstr(path_tail(p_sh), "pwsh") == NULL + && strstr(path_tail(p_sh), "sh") != NULL; char *nameext = strrchr(name, '.'); size_t nameext_len = nameext ? strlen(nameext) : 0; xstrlcpy(os_buf, name, sizeof(os_buf)); diff --git a/src/nvim/path.c b/src/nvim/path.c index 9350335e54..6d14db7de1 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -6,6 +6,7 @@ #include <limits.h> #include <stdbool.h> #include <stddef.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> diff --git a/src/nvim/plines.c b/src/nvim/plines.c index e4d1ddf8d8..38ca91a6ac 100644 --- a/src/nvim/plines.c +++ b/src/nvim/plines.c @@ -23,7 +23,6 @@ #include "nvim/option.h" #include "nvim/plines.h" #include "nvim/pos.h" -#include "nvim/types.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/runtime.c b/src/nvim/runtime.c index e009b883ca..ea975042ed 100644 --- a/src/nvim/runtime.c +++ b/src/nvim/runtime.c @@ -9,7 +9,6 @@ #include <errno.h> #include <fcntl.h> #include <inttypes.h> -#include <stddef.h> #include <stdio.h> #include <string.h> #include <uv.h> diff --git a/src/nvim/shada.c b/src/nvim/shada.c index 754139a147..92d47fbf49 100644 --- a/src/nvim/shada.c +++ b/src/nvim/shada.c @@ -53,7 +53,6 @@ #include "nvim/search.h" #include "nvim/shada.h" #include "nvim/strings.h" -#include "nvim/types.h" #include "nvim/version.h" #include "nvim/vim.h" diff --git a/src/nvim/statusline.c b/src/nvim/statusline.c index db3e3f91bf..b75b3c313f 100644 --- a/src/nvim/statusline.c +++ b/src/nvim/statusline.c @@ -31,12 +31,14 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/move.h" +#include "nvim/normal.h" #include "nvim/option.h" #include "nvim/optionstr.h" #include "nvim/os/os.h" #include "nvim/path.h" #include "nvim/pos.h" #include "nvim/screen.h" +#include "nvim/sign_defs.h" #include "nvim/statusline.h" #include "nvim/strings.h" #include "nvim/types.h" diff --git a/src/nvim/testdir/test_shell.vim b/src/nvim/testdir/test_shell.vim new file mode 100644 index 0000000000..8b9c7a5b12 --- /dev/null +++ b/src/nvim/testdir/test_shell.vim @@ -0,0 +1,209 @@ +" Test for the shell related options ('shell', 'shellcmdflag', 'shellpipe', +" 'shellquote', 'shellredir', 'shellxescape', and 'shellxquote') + +source check.vim +source shared.vim + +func Test_shell_options() + " The expected value of 'shellcmdflag', 'shellpipe', 'shellquote', + " 'shellredir', 'shellxescape', 'shellxquote' for the supported shells. + let shells = [] + if has('unix') + let shells += [['sh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['ksh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['mksh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['zsh', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['zsh-beta', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['bash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['fish', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['ash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['dash', '-c', '2>&1| tee', '', '>%s 2>&1', '', ''], + \ ['csh', '-c', '|& tee', '', '>&', '', ''], + \ ['tcsh', '-c', '|& tee', '', '>&', '', '']] + endif + if has('win32') + let shells += [['cmd', '/s /c', '>%s 2>&1', '', '>%s 2>&1', '', '"']] + endif + + " start a new Vim instance with 'shell' set to each of the supported shells + " and check the default shell option settings + let after =<< trim END + let l = [&shell, &shellcmdflag, &shellpipe, &shellquote] + let l += [&shellredir, &shellxescape, &shellxquote] + call writefile([json_encode(l)], 'Xtestout') + qall! + END + for e in shells + if RunVim([], after, '--cmd "set shell=' .. e[0] .. '"') + call assert_equal(e, json_decode(readfile('Xtestout')[0])) + endif + endfor + + " Test shellescape() for each of the shells. + for e in shells + exe 'set shell=' .. e[0] + if e[0] =~# '.*csh$' || e[0] =~# '.*csh.exe$' + let str1 = "'cmd \"arg1\" '\\''arg2'\\'' \\!%#'" + let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\\\!\\%\\#'" + elseif e[0] =~# '.*powershell$' || e[0] =~# '.*powershell.exe$' + let str1 = "'cmd \"arg1\" ''arg2'' !%#'" + let str2 = "'cmd \"arg1\" ''arg2'' \\!\\%\\#'" + else + let str1 = "'cmd \"arg1\" '\\''arg2'\\'' !%#'" + let str2 = "'cmd \"arg1\" '\\''arg2'\\'' \\!\\%\\#'" + endif + call assert_equal(str1, shellescape("cmd \"arg1\" 'arg2' !%#"), e[0]) + call assert_equal(str2, shellescape("cmd \"arg1\" 'arg2' !%#", 1), e[0]) + + " Try running an external command with the shell. + if executable(e[0]) + " set the shell options for the current 'shell' + let [&shellcmdflag, &shellpipe, &shellquote, &shellredir, + \ &shellxescape, &shellxquote] = e[1:6] + new + r !echo hello + call assert_equal('hello', substitute(getline(2), '\W', '', 'g'), e[0]) + bwipe! + endif + endfor + set shell& shellcmdflag& shellpipe& shellquote& + set shellredir& shellxescape& shellxquote& + call delete('Xtestout') +endfunc + +" Test for the 'shell' option +func Test_shell() + throw 'Skipped: Nvim missing :shell currently' + CheckUnix + let save_shell = &shell + set shell= + let caught_e91 = 0 + try + shell + catch /E91:/ + let caught_e91 = 1 + endtry + call assert_equal(1, caught_e91) + let &shell = save_shell +endfunc + +" Test for the 'shellquote' option +func Test_shellquote() + CheckUnix + set shellquote=# + set verbose=20 + redir => v + silent! !echo Hello + redir END + set verbose& + set shellquote& + call assert_match(': "#echo Hello#"', v) +endfunc + +" Test for the 'shellescape' option +func Test_shellescape() + let save_shell = &shell + set shell=bash + call assert_equal("'text'", shellescape('text')) + call assert_equal("'te\"xt'", 'te"xt'->shellescape()) + call assert_equal("'te'\\''xt'", shellescape("te'xt")) + + call assert_equal("'te%xt'", shellescape("te%xt")) + call assert_equal("'te\\%xt'", shellescape("te%xt", 1)) + call assert_equal("'te#xt'", shellescape("te#xt")) + call assert_equal("'te\\#xt'", shellescape("te#xt", 1)) + call assert_equal("'te!xt'", shellescape("te!xt")) + call assert_equal("'te\\!xt'", shellescape("te!xt", 1)) + + call assert_equal("'te\nxt'", shellescape("te\nxt")) + call assert_equal("'te\\\nxt'", shellescape("te\nxt", 1)) + set shell=tcsh + call assert_equal("'te\\!xt'", shellescape("te!xt")) + call assert_equal("'te\\\\!xt'", shellescape("te!xt", 1)) + call assert_equal("'te\\\nxt'", shellescape("te\nxt")) + call assert_equal("'te\\\\\nxt'", shellescape("te\nxt", 1)) + + let &shell = save_shell +endfunc + +" Test for 'shellslash' +func Test_shellslash() + CheckOption shellslash + let save_shellslash = &shellslash + " The shell and cmdflag, and expected slash in tempname with shellslash set or + " unset. The assert checks the file separator before the leafname. + " ".*\\\\[^\\\\]*$" + let shells = [['cmd', '/c', '/', '/'], + \ ['powershell', '-Command', '/', '/'], + \ ['sh', '-c', '/', '/']] + for e in shells + exe 'set shell=' .. e[0] .. ' | set shellcmdflag=' .. e[1] + set noshellslash + let file = tempname() + call assert_match('^.\+' .. e[2] .. '[^' .. e[2] .. ']\+$', file, e[0] .. ' ' .. e[1] .. ' nossl') + set shellslash + let file = tempname() + call assert_match('^.\+' .. e[3] .. '[^' .. e[3] .. ']\+$', file, e[0] .. ' ' .. e[1] .. ' ssl') + endfor + let &shellslash = save_shellslash +endfunc + +" Test for 'shellxquote' +func Test_shellxquote() + CheckUnix + + let save_shell = &shell + let save_sxq = &shellxquote + let save_sxe = &shellxescape + + call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell') + call setfperm('Xtestshell', "r-x------") + set shell=./Xtestshell + + set shellxquote=\\" + call feedkeys(":!pwd\<CR>\<CR>", 'xt') + call assert_equal(['Cmd: [-c "pwd"]'], readfile('Xlog')) + + set shellxquote=( + call feedkeys(":!pwd\<CR>\<CR>", 'xt') + call assert_equal(['Cmd: [-c (pwd)]'], readfile('Xlog')) + + set shellxquote=\\"( + call feedkeys(":!pwd\<CR>\<CR>", 'xt') + call assert_equal(['Cmd: [-c "(pwd)"]'], readfile('Xlog')) + + set shellxescape=\"&<<()@^ + set shellxquote=( + call feedkeys(":!pwd\"&<<{}@^\<CR>\<CR>", 'xt') + call assert_equal(['Cmd: [-c (pwd^"^&^<^<{}^@^^)]'], readfile('Xlog')) + + let &shell = save_shell + let &shellxquote = save_sxq + let &shellxescape = save_sxe + call delete('Xtestshell') + call delete('Xlog') +endfunc + +" Test for using the shell set in the $SHELL environment variable +func Test_set_shell() + let after =<< trim [CODE] + call writefile([&shell], "Xtestout") + quit! + [CODE] + + if has('win32') + let $SHELL = 'C:\with space\cmd.exe' + let expected = '"C:\with space\cmd.exe"' + else + let $SHELL = '/bin/with space/sh' + let expected = '"/bin/with space/sh"' + endif + + if RunVimPiped([], after, '', '') + let lines = readfile('Xtestout') + call assert_equal(expected, lines[0]) + endif + call delete('Xtestout') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_startup.vim b/src/nvim/testdir/test_startup.vim index 1f9f53eb43..1ee1d0dfe3 100644 --- a/src/nvim/testdir/test_startup.vim +++ b/src/nvim/testdir/test_startup.vim @@ -725,27 +725,6 @@ func Test_read_stdin() call delete('Xtestout') endfunc -func Test_set_shell() - let after =<< trim [CODE] - call writefile([&shell], "Xtestout") - quit! - [CODE] - - if has('win32') - let $SHELL = 'C:\with space\cmd.exe' - let expected = '"C:\with space\cmd.exe"' - else - let $SHELL = '/bin/with space/sh' - let expected = '"/bin/with space/sh"' - endif - - if RunVimPiped([], after, '', '') - let lines = readfile('Xtestout') - call assert_equal(expected, lines[0]) - endif - call delete('Xtestout') -endfunc - func Test_progpath() " Tests normally run with "./vim" or "../vim", these must have been expanded " to a full path. diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index bfa8a277bd..6c8373b335 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -142,40 +142,4 @@ func Test_system_with_shell_quote() endtry endfunc -" Test for 'shellxquote' -func Test_Shellxquote() - CheckUnix - - let save_shell = &shell - let save_sxq = &shellxquote - let save_sxe = &shellxescape - - call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell') - call setfperm('Xtestshell', "r-x------") - set shell=./Xtestshell - - set shellxquote=\\" - call feedkeys(":!pwd\<CR>\<CR>", 'xt') - call assert_equal(['Cmd: [-c "pwd"]'], readfile('Xlog')) - - set shellxquote=( - call feedkeys(":!pwd\<CR>\<CR>", 'xt') - call assert_equal(['Cmd: [-c (pwd)]'], readfile('Xlog')) - - set shellxquote=\\"( - call feedkeys(":!pwd\<CR>\<CR>", 'xt') - call assert_equal(['Cmd: [-c "(pwd)"]'], readfile('Xlog')) - - set shellxescape=\"&<<()@^ - set shellxquote=( - call feedkeys(":!pwd\"&<<{}@^\<CR>\<CR>", 'xt') - call assert_equal(['Cmd: [-c (pwd^"^&^<^<{}^@^^)]'], readfile('Xlog')) - - let &shell = save_shell - let &shellxquote = save_sxq - let &shellxescape = save_sxe - call delete('Xtestshell') - call delete('Xlog') -endfunc - " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c index ee6c39a8ba..8d58966f46 100644 --- a/src/nvim/textobject.c +++ b/src/nvim/textobject.c @@ -4,6 +4,7 @@ // textobject.c: functions for text objects #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <string.h> @@ -28,7 +29,6 @@ #include "nvim/search.h" #include "nvim/strings.h" #include "nvim/textobject.h" -#include "nvim/types.h" #include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS diff --git a/src/nvim/tui/input.c b/src/nvim/tui/input.c index 91fbdf7886..5325ae3e4d 100644 --- a/src/nvim/tui/input.c +++ b/src/nvim/tui/input.c @@ -8,31 +8,27 @@ #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/vim.h" #include "nvim/ascii.h" -#include "nvim/autocmd.h" #include "nvim/charset.h" #include "nvim/event/defs.h" -#include "nvim/event/multiqueue.h" -#include "nvim/globals.h" #include "nvim/log.h" #include "nvim/macros.h" #include "nvim/main.h" #include "nvim/map.h" #include "nvim/memory.h" -#include "nvim/message.h" #include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" #include "nvim/tui/input.h" #include "nvim/tui/input_defs.h" #include "nvim/tui/tui.h" +#include "nvim/types.h" +#include "nvim/ui_client.h" #ifdef MSWIN # include "nvim/os/os_win_console.h" #endif #include "nvim/event/rstream.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/ui.h" #define KEY_BUFFER_SIZE 0xfff diff --git a/src/nvim/tui/terminfo.c b/src/nvim/tui/terminfo.c index 507e9df21e..d630a34ce2 100644 --- a/src/nvim/tui/terminfo.c +++ b/src/nvim/tui/terminfo.c @@ -7,12 +7,12 @@ #include <string.h> #include <unibilium.h> +#include "klib/kvec.h" +#include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" +#include "nvim/ascii.h" #include "nvim/charset.h" -#include "nvim/globals.h" #include "nvim/memory.h" -#include "nvim/message.h" -#include "nvim/option.h" #include "nvim/strings.h" #include "nvim/tui/terminfo.h" #include "nvim/tui/terminfo_defs.h" diff --git a/src/nvim/tui/tui.c b/src/nvim/tui/tui.c index e46dc892ea..44b99f6c84 100644 --- a/src/nvim/tui/tui.c +++ b/src/nvim/tui/tui.c @@ -16,7 +16,6 @@ #include "klib/kvec.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" -#include "nvim/api/vim.h" #include "nvim/ascii.h" #include "nvim/cursor_shape.h" #include "nvim/event/defs.h" @@ -32,12 +31,10 @@ #include "nvim/main.h" #include "nvim/mbyte.h" #include "nvim/memory.h" -#include "nvim/message.h" #include "nvim/msgpack_rpc/channel.h" -#include "nvim/option.h" #include "nvim/os/input.h" #include "nvim/os/os.h" -#include "nvim/os/signal.h" +#include "nvim/ui_client.h" #ifdef MSWIN # include "nvim/os/os_win_console.h" #endif @@ -46,7 +43,6 @@ #include "nvim/tui/tui.h" #include "nvim/ugrid.h" #include "nvim/ui.h" -#include "nvim/vim.h" // Space reserved in two output buffers to make the cursor normal or invisible // when flushing. No existing terminal will require 32 bytes to do that. diff --git a/src/nvim/ui.c b/src/nvim/ui.c index b25fa04c8b..9f1cb87eb0 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -7,8 +7,8 @@ #include <stddef.h> #include <stdint.h> #include <stdlib.h> +#include <string.h> -#include "auto/config.h" #include "klib/kvec.h" #include "nvim/api/private/helpers.h" #include "nvim/api/ui.h" @@ -17,8 +17,6 @@ #include "nvim/buffer_defs.h" #include "nvim/cursor_shape.h" #include "nvim/drawscreen.h" -#include "nvim/event/defs.h" -#include "nvim/event/loop.h" #include "nvim/ex_getln.h" #include "nvim/gettext.h" #include "nvim/globals.h" @@ -27,15 +25,14 @@ #include "nvim/highlight_defs.h" #include "nvim/log.h" #include "nvim/lua/executor.h" -#include "nvim/main.h" +#include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/msgpack_rpc/channel.h" #include "nvim/option.h" #include "nvim/os/time.h" #include "nvim/strings.h" -#include "nvim/tui/tui.h" #include "nvim/ui.h" +#include "nvim/ui_client.h" #include "nvim/ui_compositor.h" #include "nvim/vim.h" #include "nvim/window.h" diff --git a/src/nvim/ui_client.c b/src/nvim/ui_client.c index 47c255fc80..222ba3d5dd 100644 --- a/src/nvim/ui_client.c +++ b/src/nvim/ui_client.c @@ -6,15 +6,18 @@ #include <stdlib.h> #include "nvim/api/private/helpers.h" +#include "nvim/channel.h" #include "nvim/eval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/event/loop.h" -#include "nvim/event/multiqueue.h" #include "nvim/globals.h" #include "nvim/highlight.h" #include "nvim/log.h" #include "nvim/main.h" #include "nvim/memory.h" #include "nvim/msgpack_rpc/channel.h" +#include "nvim/msgpack_rpc/channel_defs.h" +#include "nvim/os/os_defs.h" #include "nvim/tui/tui.h" #include "nvim/ui.h" #include "nvim/ui_client.h" diff --git a/src/nvim/ui_client.h b/src/nvim/ui_client.h index 24b8fad4cc..201c97f9d3 100644 --- a/src/nvim/ui_client.h +++ b/src/nvim/ui_client.h @@ -1,11 +1,14 @@ #ifndef NVIM_UI_CLIENT_H #define NVIM_UI_CLIENT_H +#include <stdbool.h> #include <stddef.h> +#include <stdint.h> #include "nvim/api/private/defs.h" #include "nvim/grid_defs.h" #include "nvim/macros.h" +#include "nvim/types.h" typedef struct { const char *name; @@ -35,10 +38,11 @@ EXTERN TriState ui_client_bg_respose INIT(= kNone); EXTERN bool ui_client_forward_stdin INIT(= false); #define UI_CLIENT_STDIN_FD 3 +// uncrustify:off #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui_client.h.generated.h" - # include "ui_events_client.h.generated.h" #endif +// uncrustify:on #endif // NVIM_UI_CLIENT_H diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index ad44e2ca22..9ff9eabff8 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -24,7 +24,6 @@ #include "nvim/highlight_group.h" #include "nvim/log.h" #include "nvim/macros.h" -#include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option_defs.h" diff --git a/src/nvim/window.c b/src/nvim/window.c index 2bcbef14b0..627d418a55 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -11,12 +11,14 @@ #include <stdlib.h> #include <string.h> +#include "klib/kvec.h" #include "nvim/api/private/defs.h" #include "nvim/api/private/helpers.h" #include "nvim/arglist.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" +#include "nvim/buffer_defs.h" #include "nvim/charset.h" #include "nvim/cursor.h" #include "nvim/decoration.h" @@ -59,6 +61,7 @@ #include "nvim/option.h" #include "nvim/optionstr.h" #include "nvim/os/os.h" +#include "nvim/os/os_defs.h" #include "nvim/path.h" #include "nvim/plines.h" #include "nvim/pos.h" diff --git a/src/nvim/window.h b/src/nvim/window.h index f348f102c9..4ab2bea60a 100644 --- a/src/nvim/window.h +++ b/src/nvim/window.h @@ -6,6 +6,7 @@ #include "nvim/buffer.h" #include "nvim/buffer_defs.h" +#include "nvim/macros.h" #include "nvim/mark.h" #include "nvim/os/os.h" #include "nvim/os/os_defs.h" |