Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add clarifications for fs.find() and fs.normalize() #21132

Merged
merged 1 commit into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
docs: add clarifications for fs.find() and fs.normalize()
Co-Authored-By: Gregory Anders <[email protected]>
Co-Authored-By: zeertzjq <[email protected]>
  • Loading branch information
3 people committed Nov 23, 2022
commit 901db417c69f361191eb6997049b3538187dc778
26 changes: 14 additions & 12 deletions runtime/doc/lua.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2286,42 +2286,44 @@ find({names}, {opts}) *vim.fs.find()*
Parameters: ~
• {names} (string|table|fun(name: string): boolean) Names of the files
and directories to find. Must be base names, paths and globs
are not supported. If a function it is called per file and
dir within the traversed directories to test if they match.
are not supported. The function is called per file and
directory within the traversed directories to test if they
match {names}.
• {opts} (table) Optional keyword arguments:
• path (string): Path to begin searching from. If omitted,
the current working directory is used.
the |current-directory| is used.
• upward (boolean, default false): If true, search upward
through parent directories. Otherwise, search through child
directories (recursively).
• stop (string): Stop searching when this directory is
reached. The directory itself is not searched.
• type (string): Find only files ("file") or directories
("directory"). If omitted, both files and directories that
match {name} are included.
match {names} are included.
• limit (number, default 1): Stop the search after finding
this many matches. Use `math.huge` to place no limit on the
number of matches.

Return: ~
(table) The paths of all matching files or directories
(table) The normalized paths |vim.fs.normalize()| of all matching
files or directories

normalize({path}) *vim.fs.normalize()*
Normalize a path to a standard format. A tilde (~) character at the
beginning of the path is expanded to the user's home directory and any
backslash (\) characters are converted to forward slashes (/). Environment
variables are also expanded.

Example: >
Examples: >

vim.fs.normalize('C:\Users\jdoe')
=> 'C:/Users/jdoe'
vim.fs.normalize('C:\Users\jdoe')
=> 'C:/Users/jdoe'

vim.fs.normalize('~/src/neovim')
=> '/home/jdoe/src/neovim'
vim.fs.normalize('~/src/neovim')
=> '/home/jdoe/src/neovim'

vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim')
=> '/Users/jdoe/.config/nvim/init.vim'
vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim')
=> '/Users/jdoe/.config/nvim/init.vim'
<

Parameters: ~
Expand Down
26 changes: 14 additions & 12 deletions runtime/lua/vim/fs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,12 @@ end
---@param names (string|table|fun(name: string): boolean) Names of the files
--- and directories to find.
--- Must be base names, paths and globs are not supported.
--- If a function it is called per file and dir within the
--- traversed directories to test if they match.
--- The function is called per file and directory within the
--- traversed directories to test if they match {names}.
---
---@param opts (table) Optional keyword arguments:
--- - path (string): Path to begin searching from. If
--- omitted, the current working directory is used.
--- omitted, the |current-directory| is used.
--- - upward (boolean, default false): If true, search
--- upward through parent directories. Otherwise,
--- search through child directories
Expand All @@ -92,12 +93,13 @@ end
--- reached. The directory itself is not searched.
--- - type (string): Find only files ("file") or
--- directories ("directory"). If omitted, both
--- files and directories that match {name} are
--- files and directories that match {names} are
--- included.
--- - limit (number, default 1): Stop the search after
AzerAfram marked this conversation as resolved.
Show resolved Hide resolved
--- finding this many matches. Use `math.huge` to
--- place no limit on the number of matches.
---@return (table) The paths of all matching files or directories
---
---@return (table) The normalized paths |vim.fs.normalize()| of all matching files or directories
function M.find(names, opts)
opts = opts or {}
vim.validate({
Expand Down Expand Up @@ -211,16 +213,16 @@ end
--- backslash (\\) characters are converted to forward slashes (/). Environment
--- variables are also expanded.
---
--- Example:
--- Examples:
--- <pre>
--- vim.fs.normalize('C:\\Users\\jdoe')
--- => 'C:/Users/jdoe'
--- vim.fs.normalize('C:\\Users\\jdoe')
--- => 'C:/Users/jdoe'
---
--- vim.fs.normalize('~/src/neovim')
--- => '/home/jdoe/src/neovim'
--- vim.fs.normalize('~/src/neovim')
--- => '/home/jdoe/src/neovim'
---
--- vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim')
--- => '/Users/jdoe/.config/nvim/init.vim'
--- vim.fs.normalize('$XDG_CONFIG_HOME/nvim/init.vim')
--- => '/Users/jdoe/.config/nvim/init.vim'
--- </pre>
---
---@param path (string) Path to normalize
Expand Down