1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
---@meta
local
--- Search for files on the filesystem. Using `directory` as a starting point, returns all files (as `Node` objects) that
--- match the given pattern. Search results returned by this function are verified again on every run, and the command will
--- be reevaluated if the search results change.
---
---@param directory Node The root directory of the search
---@param pattern string A glob pattern
---@param include_directories boolean|nil Optional. Wether directories are returned
---@return Node[] A list of nodes that matched the pattern.
--- Finds a program by name within the specified paths.
--- This function searches for an executable program with the given `name` in the provided `paths`.
--- If `paths` is not provided, the `context.options.path` variable will be used, which defaults to the environment PATH variable.
--- Search results returned by this function are verified again on every run, and the command will
--- be reevaluated if the search results change.
---
---@param name string The name of the program to find.
---@param paths string[]|nil Optional. A list of paths to search for the program. If not specified, the `context.options.path` variable is used.
---@return Node The node representing the found program.
--- Represents a filesystem object, either a directory or a file, which may or may not exist yet.
--- Nodes serve as filesystem object references that can represent either directories or files, providing a range of utilities for path manipulation and file operations.
---@class Node
---@field parent Node The parent node of this node, representing the directory containing this filesystem object.
local Node
--- Creates a new Node object representing a filesystem object, either relative to `self` or absolute.
---@param path string A filesystem path, either absolute or relative to `self`.
---@return Node A new Node representing the specified path.
--- Returns the last component of the filesystem object's path, such as the directory or file name.
---@return string The final path component, representing either the directory or file name.
--- Returns the last component of the filesystem object's path without its extension, i.e., the base name.
---@return string The directory or file name without the file extension.
--- Returns the file extension of the filesystem object, or an empty string if there is no extension.
---@return string The file extension, if present; otherwise, an empty string.
--- Returns the absolute path of the filesystem object.
---@return string The full absolute path of the Node.
--- Returns the path of the filesystem object relative to a specified starting Node.
---@param from Node The node from which to calculate the relative path.
---@return string The relative path from the specified starting node.
--- Changes the file extension of the filesystem object. If no extension exists, it adds the new extension; otherwise, it replaces the existing extension.
---@param new_extension string The new file extension, without the `.` prefix.
--- Checks if the filesystem object exists and is a directory.
---@return boolean `true` if the node represents an existing directory; otherwise, `false`.
--- Checks if the filesystem object exists and is a file.
---@return boolean `true` if the node represents an existing file; otherwise, `false`.
--- Resolves a symbolic link to find the target filesystem object, if it exists. Only dereferences the last component of the path.
---@return Node A new node representing the resolved target filesystem object.
--- Canonicalizes the filesystem path, resolving any symbolic links along the entire path to the target object.
---@return Node A new node representing the fully resolved target filesystem object.
--- Deletes the file represented by the node. Raises an error if deletion fails.
--- Deletes the file represented by the node, ignoring any errors if the operation fails.
--- Reads the contents of the file represented by the node as a raw string, without processing encoding.
---@return string The raw content of the file.
--- Writes the specified string content to the file represented by the node, without processing encoding.
---@param content string The raw content to write to the file.