summaryrefslogtreecommitdiffstatshomepage
path: root/src/nvim/path.c
AgeCommit message (Collapse)AuthorFiles
2026-04-24fix(path): normalize path slashes on Windows #37729tao1
Problem: On Windows, path separators may become inconsistent for various reasons, which makes normalization quite painful. Solution: Normalize paths to `/` at the entry boundaries and always use it internally, converting back only in rare cases where `\` is really needed (e.g. cmd.exe/bat scripts?). This is the first commit in a series of incremental steps. Note: * some funcs won't respect shellslash. e.g. `expand/fnamemodify` * some funcs still respect shellslash, but will be updated in a follow PR. e.g. `ex_pwd/f_chdir/f_getcwd` * uv's built-in funcs always return `\`. e.g. `uv.cwd/uv.exepath` Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
2026-04-14build: update clang v21, fix warningsdundargoc1
- `src/nvim/ex_cmds_defs.h`: use "U" instead of "u" per `readability-uppercase-literal-suffix`
2026-04-06vim-patch:9.2.0291: too many strlen() callszeertzjq1
Problem: too many strlen() calls Solution: refactor concat_fname() and remove calls to strlen() (John Marriott) Function `concat_fnames()` can make up to 5 calls to `STRLEN()` (either directly or indirectly via `STRCAT()`). In many cases the lengths of arguments `fname1` and/or `fname2` are either known or can simply be calculated. This Commit refactors this function to accept the lengths of arguments `fname1` and `fname2` as arguments. It also adds new argument `ret` to return the resulting string as a `string_T`. Additionally: - function `add_pack_dir_to_rtp()` in `scriptfile.c`: Use a `string_T` to store local variables `new_rtp` and `afterdir`. Replace calls to `STRCAT()` with calls to `STRCPY()`. Change type of variable `keep` to `size_t` for consistency with other lengths. - function `qf_get_fnum()` in `quickfix.c`: Use a `string_T` to store local variables `ptr` and `bufname` - function `qf_push_dir()` in `quickfix.c`: Use a `string_T` to store local variable `dirname`. Replace call to `vim_strsave()` with `vim_strnsave()`. - function `qf_guess_filepath()` in `quickfix.c`: Use a `string_T` to store local variable `fullname`. - function `make_percent_swname()` in `memline.c`: Rename some variables to better reflect their use. Use a `string_T` to store local variables `d` and `fixed_name`. Slightly refactor to remove need to create an extra string. - function `get_file_in_dir()` in `memline.c`: Use a `string_T` to store local variables `tail` and `retval`. Move some variables closer to where they are used. - function `cs_resolve_file()` in `if_cscope.c`: Use a `string_T` to store local variable `csdir`. Remove one call to `STRLEN()`. - function `add_pathsep()` in `filepath.c`: Refactor and remove 1 call to `STRLEN()` - function `set_init_xdg_rtp()` in `option.c`: Use a `string_T` to store local variable `vimrc_xdg`. closes: vim/vim#19854 https://github.com/vim/vim/commit/cb51add7ae400a47407fb7fb7b7a54e238d4fdf4 Co-authored-by: John Marriott <basilisk@internode.on.net> Co-authored-by: Christian Brabandt <cb@256bit.org>
2026-03-20docs: miscJustin M. Keyes1
2026-03-18fix(fs): expand drive-relative paths on Windows #37084tao1
Problem: On windows, if a drive-relative path doesn't contain a slash, `path_to_absolute` can't split out the relative component, causing expansion to fails. e.g., `c:` `c:.` `c:..` `c:foo.md` Solution: For these cases, we can pass letter and colon to `path_full_dir_name`. Notably, `..` is included as well. if that relative path exists, it can be expanded correctly.
2026-03-11docs: api, messages, lsp, trustJustin M. Keyes1
gen_vimdoc.lua: In prepare for the upcoming release, comment-out the "Experimental" warning for prerelease features.
2026-02-19vim-patch:9.2.0020: Wrong shortened buffer after :cd with duplicate slashes ↵zeertzjq1
(#37955) Problem: Wrong shortened buffer name after :cd with duplicate slashes. Solution: Skip over multiple consecutive path separators (zeertzjq). related: neovim/neovim#37080 closes: vim/vim#19444 https://github.com/vim/vim/commit/f245e17ac70df43fd7fe650c7227bb16a4615283 N/A patches: vim-patch:9.0.1859: heap-use-after-free in bt_normal() vim-patch:9.2.0022: bt_quickfix() is slow
2026-01-04vim-patch:9.1.1648: MS-Windows: some style issues with patch v9.1.1646zeertzjq1
Problem: MS-Windows: some style issues with patch v9.1.1646 Solution: Fix typose and code style issues (zeertzjq). closes: vim/vim#18036 https://github.com/vim/vim/commit/14afa278c1bcb2df51b647ffda2821c5294eb7ff
2026-01-04vim-patch:9.1.1646: MS-Windows: completion cannot handle implicit drive letterszeertzjq1
Problem: MS-Windows: completion cannot handle implicit drive letters Solution: Consider paths like \folder and /folder as absolute (Miguel Barro). closes: vim/vim#17829 https://github.com/vim/vim/commit/a2f13bf782f723e116c5d4cc7d79a23e918a24db Co-authored-by: Miguel Barro <miguel.barro@live.com>
2025-12-08build: slience some unwanted clang-tidy warningsJustin M. Keyes1
2025-11-15refactor(path)!: support RFC3986 in path_with_url() #36564Chip Senkbeil1
Problem: Nvim does not recognize URI scheme with numeric characters. While rare, there are URIs that contain numbers (e.g. [ed2k://](https://en.wikipedia.org/wiki/Ed2k_URI_scheme)) and characters like `+` (e.g. `svn+ssh`). I use it in [distant.nvim](https://github.com/chipsenkbeil/distant.nvim) to support multiple, distinct connections using `distant+1234://` as the scheme. Otherwise, if you open a file with the same name & path on two different machines from the same Nvim instance, their buffer names will conflict when just using `distant://`. Solution: Adds full support for detecting URI scheme per [RFC3986](https://www.rfc-editor.org/rfc/rfc3986#section-3.1)
2025-10-31fix(completion): complete drive-letter filepath on Windows #3635311soda111
Problem: On MSWIN, file completion (CTRL-X CTRL-F) only works for the current drive (so not for actual absolute paths), since drive letters are never included in the completion pattern. e.g. when completing "F:\Hello" Nvim currently completes "\Hello" which is relative to the current drive/volume. vim solves this by adding ':' to the default 'isfname' value on mswin, but that causes issues as ':' is not a valid windows path char anywhere _except_ after the drive letter. Solution: detect drive letters in front of the path when creating the completion pattern.
2025-10-24docs: types, news, lua-pluginJustin M. Keyes1
- mention "lua_ls", not "luals". https://github.com/neovim/neovim/discussions/36182 Co-authored-by: Maria Solano <majosolano99@gmail.com>
2025-08-27vim-patch:9.1.1690: Missing recursion guard in dos/unix_expandpath() (#35499)zeertzjq1
Problem: Missing recursion guard in dos/unix_expandpath() Solution: Add guard variables (ashamedbit) fixes: vim/vim#18099 closes: vim/vim#18106 https://github.com/vim/vim/commit/e8948a1f807cb595446e896e00bdf0e5339f0dd2 Co-authored-by: ashamedbit <muralianiruddhan@gmail.com> Co-authored-by: Hirohito Higashi <h.east.727@gmail.com>
2025-08-27refactor: rename ga_concat_strings_sep() to ga_concat_strings() (#35498)zeertzjq1
This adds a missing change from Vim patch 7.4.279. N/A patch: vim-patch:9.1.1691: over-allocation in ga_concat_strings()
2025-08-14refactor(build): remove INCLUDE_GENERATED_DECLARATIONS guardsbfredl1
These are not needed after #35129 but making uncrustify still play nice with them was a bit tricky. Unfortunately `uncrustify --update-config-with-doc` breaks strings with backslashes. This issue has been reported upstream, and in the meanwhile auto-update on every single run has been disabled.
2025-04-16fix(env.c): drop envmap, free os_getenv() result #32683Judit Novak1
Problem: vim.uv.os_setenv gets "stuck" per-key. #32550 Caused by the internal `envmap` cache. #7920 :echo $FOO <-- prints nothing :lua vim.uv.os_setenv("FOO", "bar") :echo $FOO <-- prints bar (as expected) :lua vim.uv.os_setenv("FOO", "fizz") :echo $FOO <-- prints bar, still (not expected. Should be "fizz") :lua vim.uv.os_unsetenv("FOO") :echo $FOO <-- prints bar, still (not expected. Should be nothing) :lua vim.uv.os_setenv("FOO", "buzz") :echo $FOO <-- prints bar, still (not expected. Should be "buzz") Solution: - Remove the `envmap` cache. - Callers to `os_getenv` must free the result. - Update all call-sites. - Introduce `os_getenv_noalloc`. - Extend `os_env_exists()` the `nonempty` parameter.
2025-03-19fix(path): crash with nvim_get_runtime_file during wildcard expansion (#32992)zeertzjq1
Problem: Crash with nvim_get_runtime_file during wildcard expansion. Solution: Ensure recursive gen_expand_wildcards() is allowed when calling os_breakcheck()
2025-03-15vim-patch:9.1.1204: MS-Windows: crash when passing long string to expand() ↵zeertzjq1
(#32902) Problem: MS-Windows: crash when passing long string to expand() with 'wildignorecase'. Solution: Use the same buflen as unix_expandpath() in dos_expandpath(). Remove an unnecessary STRLEN() while at it (zeertzjq). closes: vim/vim#16896 https://github.com/vim/vim/commit/00a749bd90e6b84e7e5132691d73fe9aa3fdff05
2025-03-15vim-patch:9.0.1458: buffer overflow when expanding long file namezeertzjq1
Problem: Buffer overflow when expanding long file name. Solution: Use a larger buffer and avoid overflowing it. (Yee Cheng Chin, closes vim/vim#12201) https://github.com/vim/vim/commit/a77670726e3706973adffc2b118f4576e1f58ea0 Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
2025-03-15vim-patch:8.2.4963: expanding path with "/**" may overrun end of bufferzeertzjq1
Problem: Expanding path with "/**" may overrun end of buffer. Solution: Use vim_snprintf(). https://github.com/vim/vim/commit/386c24cd262edac66a31add2fd989c96c4c2c952 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2025-02-19vim-patch:9.1.1122: too many strlen() calls in findfile.c (#32516)zeertzjq1
Problem: too many strlen() calls in findfile.c Solution: refactor findfile.c and remove calls to strlen() (John Marriott) closes: vim/vim#16595 https://github.com/vim/vim/commit/d6e3c9048dfb7e8f08f8fadc820c7e2208c3f030 Co-authored-by: John Marriott <basilisk@internode.on.net>
2025-01-30docs: miscdundargoc1
Co-authored-by: Dustin S. <dstackmasta27@gmail.com> Co-authored-by: Ferenc Fejes <fejes@inf.elte.hu> Co-authored-by: Maria José Solano <majosolano99@gmail.com> Co-authored-by: Yochem van Rosmalen <git@yochem.nl> Co-authored-by: brianhuster <phambinhanctb2004@gmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2025-01-24vim-patch:partial:9.1.1050: too many strlen() calls in os_unix.c (#32188)zeertzjq1
Problem: too many strlen() calls in os_unix.c Solution: refactor os_unix.c and remove calls to strlen() (John Marriott) closes: vim/vim#16496 https://github.com/vim/vim/commit/efc41a5958bf25b352e0916af5f57dafbbb44f17 Omit os_expand_wildcards() change: Nvim's code is more complicated and harder to refactor. Co-authored-by: John Marriott <basilisk@internode.on.net>
2024-12-23refactor: iwyu #31637Justin M. Keyes1
Result of `make iwyu` (after some "fixups").
2024-10-13vim-patch:8.2.0985: simplify() does not remove slashes from "///path"zeertzjq1
Problem: Simplify() does not remove slashes from "///path". Solution: Reduce > 2 slashes to one. (closes vim/vim#6263) https://github.com/vim/vim/commit/fdcbe3c3fedf48a43b22938c9331addb2f1182f1 Omit Test_readdirex() change: changed again in patch 9.0.0323. Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-10-11fix(build): remove USE_FNAME_CASE, redundant with CASE_INSENSITIVE_FILENAMEbfredl1
It stands to reason, you need to "fix" case-insensitive filenames if-and-only-if you have case-insensitive filenames.
2024-10-07vim-patch:9.1.0761: :cd completion fails on Windows with backslash in path ↵zeertzjq1
(#30703) Problem: :cd completion fails on Windows with backslash in path Solution: switch no_bslash argument to FALSE in file_pat_to_reg_pat() Note: only fixes the problem on Windows. For Unix, we still need to escape backslashes since those are taken as regex atoms (and could be invalid regex atoms). fixes: vim/vim#15643 closes: vim/vim#15808 https://github.com/vim/vim/commit/1a31c430bb175144d097ca607dbe10d7960f372a Co-authored-by: Christian Brabandt <cb@256bit.org>
2024-08-07vim-patch:partial:8.1.0914: code related to findfile() is spread out (#30000)zeertzjq1
Problem: Code related to findfile() is spread out. Solution: Put findfile() related code into a new source file. (Yegappan Lakshmanan, closes vim/vim#3934) https://github.com/vim/vim/commit/5fd0f5052f9a312bb4cfe7b4176b1211d45127ee Keep functions related to wildcard expansion in path.c, as in Vim they are now spread out among multiple files, which isn't really ideal.
2024-08-02vim-patch:9.0.0634: evaluating "expr" options has more overhead than neededzeertzjq1
Problem: Evaluating "expr" options has more overhead than needed. Solution: Use call_simple_func() for 'foldtext', 'includeexpr', 'printexpr', "expr" of 'spellsuggest', 'diffexpr', 'patchexpr', 'balloonexpr', 'formatexpr', 'indentexpr' and 'charconvert'. https://github.com/vim/vim/commit/a4e0b9785e409e9e660171cea76dfcc5fdafad9b vim-patch:9.0.0635: build error and compiler warnings Problem: Build error and compiler warnings. Solution: Add missing change. Add type casts. https://github.com/vim/vim/commit/3292a229402c9892f5ab90645fbfe2b1db342f5b Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-07-12vim-patch:9.1.0569: fnamemodify() treats ".." and "../" differently (#29673)zeertzjq1
Problem: fnamemodify() treats ".." and "../" differently. Solution: Expand ".." properly like how "/.." is treated in 8.2.3388. (zeertzjq) closes: vim/vim#15218 https://github.com/vim/vim/commit/1ee7420460768df67ea4bc73467f2d4f8b1555bd
2024-07-12vim-patch:9.1.0568: Cannot expand paths from 'cdpath' settingzeertzjq1
Problem: Cannot expand paths from 'cdpath' setting (Daniel Hahler) Solution: Implement 'cdpath' completion, add the new 'dir_in_path' completion type (LemonBoy) fixes vim/vim#374 closes: vim/vim#15205 https://github.com/vim/vim/commit/a20bf69a3b32024cb7809be87af33bf9dc490a19 Co-authored-by: LemonBoy <thatlemon@gmail.com>
2024-07-12vim-patch:8.2.3388: fnamemodify('path/..', ':p') differs from using ↵zeertzjq1
'path/../' (#29667) Problem: fnamemodify('path/..', ':p') differs from using 'path/../'. Solution: Include the "/.." in the directory name. (closes vim/vim#8808) https://github.com/vim/vim/commit/4eaef9979fc5032606897963f1af37674ee0d422 Co-authored-by: Bram Moolenaar <Bram@vim.org>
2024-07-10refactor: remove CH_FOLD macrodundargoc1
It should not be needed as utf_fold should already work on its own.
2024-06-11refactor(memory): use builtin strcat() instead of STRCAT()bfredl1
The latter was mostly relevant with the past char_u madness. NOTE: STRCAT also functioned as a counterfeit "NOLINT" for clint apparently. But NOLINT-ing every usecase is just the same as disabling the check entirely.
2024-05-19refactor(path.c): add nonnull attributes (#28829)zeertzjq1
This possibly fixes the coverity warning.
2024-05-17fix(path): avoid chdir() when resolving path (#28799)zeertzjq1
Use uv_fs_realpath() instead. It seems that uv_fs_realpath() has some problems on non-Linux platforms: - macOS and other BSDs: this function will fail with UV_ELOOP if more than 32 symlinks are found while resolving the given path. This limit is hardcoded and cannot be sidestepped. - Windows: while this function works in the common case, there are a number of corner cases where it doesn't: - Paths in ramdisk volumes created by tools which sidestep the Volume Manager (such as ImDisk) cannot be resolved. - Inconsistent casing when using drive letters. - Resolved path bypasses subst'd drives. Ref: https://docs.libuv.org/en/v1.x/fs.html#c.uv_fs_realpath I don't know if the old implementation that uses uv_chdir() and uv_cwd() also suffers from the same problems. - For the ELOOP case, chdir() seems to have the same limitations. - On Windows, Vim doesn't use anything like chdir() either. It uses _wfullpath(), while libuv uses GetFinalPathNameByHandleW().
2024-05-15docs: misc (#28609)dundargoc1
Closes https://github.com/neovim/neovim/issues/28484. Closes https://github.com/neovim/neovim/issues/28719. Co-authored-by: Chris <crwebb85@gmail.com> Co-authored-by: Gregory Anders <greg@gpanders.com> Co-authored-by: Jake B <16889000+jakethedev@users.noreply.github.com> Co-authored-by: Jonathan Raines <jonathan.s.raines@gmail.com> Co-authored-by: Yi Ming <ofseed@foxmail.com> Co-authored-by: Zane Dufour <zane@znd4.me> Co-authored-by: zeertzjq <zeertzjq@outlook.com>
2024-04-20refactor: add xmemcpyz() and use it in place of some xstrlcpy() (#28422)zeertzjq1
Problem: Using xstrlcpy() when the exact length of the string to be copied is known is not ideal because it requires adding 1 to the length and an unnecessary strlen(). Solution: Add xmemcpyz() and use it in place of such xstrlcpy() calls.
2024-04-13fix(path): check return value of append_path() (#28309)Joey Gouly1
If the filename passed to vim_FullName() is a relative directory, and does not exist, it is appended to the current working directory. Since the return value of append_path() was ignored, and if the buffer length was too small to fit getcwd() + dirname(filename), it would still try to append the basename(filename). This was manifesting as a failure in test/unit/path_spec.lua in: itp('fails and uses filename if given filename contains non-existing directory', .. This failure occurs when running the tests from directory with a short path such as: /work/src/nv test/unit/path_spec.lua:420: Expected objects to be the same. Passed in: (string) '/work/src/nv/test.file' Expected: (string) 'non_existing_dir/test.file' This return value for the second call to append_path() to append basename(filename) was checked, and this is where it would fail for normal / longer getcwd()s.
2024-01-11refactor(IWYU): fix headersdundargoc1
Remove `export` pramgas from defs headers as it causes IWYU to believe that the definitions from the defs headers comes from main header, which is not what we really want.
2024-01-01refactor: remove redundant NOLINT commentsdundargoc1
2023-12-30refactor: follow style guidedundargoc1
2023-12-20refactor: eliminate cyclic includesdundargoc1
2023-12-19refactor: use `bool` to represent boolean valuesdundargoc1
2023-12-09refactor(options): reduce `findoption()` usageFamiu Haque1
Problem: Many places in the code use `findoption()` to access an option using its name, even if the option index is available. This is very slow because it requires looping through the options array over and over. Solution: Use option index instead of name wherever possible. Also introduce an `OptIndex` enum which contains the index for every option as enum constants, this eliminates the need to pass static option names as strings.
2023-11-30refactor(IWYU): fix includes for cmdhist.h (#26324)zeertzjq1
2023-11-30build: don't define FUNC_ATTR_* as empty in headers (#26317)zeertzjq1
FUNC_ATTR_* should only be used in .c files with generated headers. Defining FUNC_ATTR_* as empty in headers causes misuses of them to be silently ignored. Instead don't define them by default, and only define them as empty after a .c file has included its generated header.
2023-11-28refactor: fix headers with IWYUdundargoc1
2023-11-27build(IWYU): fix includes for func_attr.hdundargoc1