@@ -3,8 +3,13 @@ import { join, delimiter, normalize } from 'node:path';
3
3
import { constants , existsSync , accessSync } from 'node:fs' ;
4
4
5
5
export type NvimVersion = {
6
- /** Path to `nvim` executable. */
6
+ /**
7
+ * @deprecated
8
+ * Path to `nvim` executable.
9
+ */
7
10
readonly path : string ;
11
+ /** Nvim location or invocation command. */
12
+ readonly cmd : string [ ] ;
8
13
/** Nvim version, or undefined if there was an error. */
9
14
readonly nvimVersion ?: string ;
10
15
/** Nvim build type, or undefined if there was an error. */
@@ -36,16 +41,22 @@ export type FindNvimOptions = {
36
41
*/
37
42
readonly firstMatch ?: boolean ;
38
43
/**
39
- * (Optional) Additional specific file paths to check for Nvim executables .
40
- * These paths will be checked before searching `dirs`.
41
- * Useful for allowing users to specify exact Nvim executable locations .
44
+ * (Optional) Specific commands that (potentially) invoke Nvim and can receive arbitrary args .
45
+ * Checked before searching `dirs`. Useful for checking a user-configured Nvim location or
46
+ * unconventional wrappers such as Windows WSL .
42
47
*
43
- * Example: ['/usr/local/bin/nvim', '/opt/homebrew/bin/nvim']
48
+ * Example:
49
+ * ```
50
+ * cmds: [
51
+ * ['/usr/bin/env', 'nvim'],
52
+ * ['/opt/homebrew/bin/nvim'],
53
+ * ],
54
+ * ```
44
55
*/
45
- readonly paths ?: string [ ] ;
56
+ readonly cmds ?: string [ ] [ ] ;
46
57
/**
47
58
* (Optional) Additional directories to search for Nvim executables.
48
- * These directories will be searched after checking `paths `
59
+ * These directories will be searched after checking `cmds `
49
60
* but before searching `$PATH` and other default locations.
50
61
* Useful for including non-standard installation directories.
51
62
*
@@ -148,48 +159,47 @@ function normalizePath(path: string): string {
148
159
}
149
160
150
161
function getPlatformSearchDirs ( ) : Set < string > {
151
- const paths = new Set < string > ( ) ;
162
+ const dirs = new Set < string > ( ) ;
152
163
const { PATH , USERPROFILE , LOCALAPPDATA , PROGRAMFILES , HOME } = process . env ;
153
164
154
- PATH ?. split ( delimiter ) . forEach ( p => paths . add ( normalizePath ( p ) ) ) ;
165
+ PATH ?. split ( delimiter ) . forEach ( p => dirs . add ( normalizePath ( p ) ) ) ;
155
166
156
- // Add common Neovim installation paths not always in the system's PATH.
167
+ // Add common Nvim locations which may not be in the system $ PATH.
157
168
if ( windows ) {
158
- // Scoop common install location
169
+ // Scoop install location.
159
170
if ( USERPROFILE ) {
160
- paths . add ( normalizePath ( `${ USERPROFILE } /scoop/shims` ) ) ;
171
+ dirs . add ( normalizePath ( `${ USERPROFILE } /scoop/shims` ) ) ;
161
172
}
162
- paths . add ( normalizePath ( 'C:/ProgramData/scoop/shims' ) ) ;
173
+ dirs . add ( normalizePath ( 'C:/ProgramData/scoop/shims' ) ) ;
163
174
164
- // Winget common install location
165
- // See https://github.com/microsoft/winget-cli/blob/master/doc/specs/%23182%20-%20Support%20for%20installation%20of%20portable%20standalone%20apps.md
175
+ // Winget install location. https://github.com/microsoft/winget-cli/blob/master/doc/specs/%23182%20-%20Support%20for%20installation%20of%20portable%20standalone%20apps.md
166
176
if ( LOCALAPPDATA ) {
167
- paths . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WindowsApps` ) ) ;
168
- paths . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WinGet/Packages` ) ) ;
177
+ dirs . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WindowsApps` ) ) ;
178
+ dirs . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WinGet/Packages` ) ) ;
169
179
}
170
180
if ( PROGRAMFILES ) {
171
- paths . add ( normalizePath ( `${ PROGRAMFILES } /Neovim/bin` ) ) ;
172
- paths . add ( normalizePath ( `${ PROGRAMFILES } (x86)/Neovim/bin` ) ) ;
173
- paths . add ( normalizePath ( `${ PROGRAMFILES } /WinGet/Packages` ) ) ;
174
- paths . add ( normalizePath ( `${ PROGRAMFILES } (x86)/WinGet/Packages` ) ) ;
181
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } /Neovim/bin` ) ) ;
182
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } (x86)/Neovim/bin` ) ) ;
183
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } /WinGet/Packages` ) ) ;
184
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } (x86)/WinGet/Packages` ) ) ;
175
185
}
176
186
} else {
177
- // Common paths for Unix-like systems
187
+ // Common locations for Unix-like systems.
178
188
[
179
189
'/usr/local/bin' ,
180
190
'/usr/bin' ,
181
191
'/opt/homebrew/bin' ,
182
192
'/home/linuxbrew/.linuxbrew/bin' ,
183
193
'/snap/nvim/current/usr/bin' ,
184
- ] . forEach ( p => paths . add ( p ) ) ;
194
+ ] . forEach ( p => dirs . add ( p ) ) ;
185
195
186
196
if ( HOME ) {
187
- paths . add ( normalizePath ( `${ HOME } /bin` ) ) ;
188
- paths . add ( normalizePath ( `${ HOME } /.linuxbrew/bin` ) ) ;
197
+ dirs . add ( normalizePath ( `${ HOME } /bin` ) ) ;
198
+ dirs . add ( normalizePath ( `${ HOME } /.linuxbrew/bin` ) ) ;
189
199
}
190
200
}
191
201
192
- return paths ;
202
+ return dirs ;
193
203
}
194
204
195
205
/**
@@ -198,13 +208,13 @@ function getPlatformSearchDirs(): Set<string> {
198
208
* @param opt.minVersion See {@link FindNvimOptions.minVersion}
199
209
* @param opt.orderBy See {@link FindNvimOptions.orderBy}
200
210
* @param opt.firstMatch See {@link FindNvimOptions.firstMatch}
201
- * @param opt.paths See {@link FindNvimOptions.paths }
211
+ * @param opt.cmds See {@link FindNvimOptions.cmds }
202
212
* @param opt.dirs See {@link FindNvimOptions.dirs}
203
213
*/
204
214
export function findNvim ( opt : FindNvimOptions = { } ) : Readonly < FindNvimResult > {
205
215
const platformDirs = getPlatformSearchDirs ( ) ;
206
216
const nvimExecutable = windows ? 'nvim.exe' : 'nvim' ;
207
- const normalizedPathsFromUser = ( opt . paths ?? [ ] ) . map ( normalizePath ) ;
217
+ const normalizedPathsFromUser = ( opt . cmds ?? [ ] ) . map ( a => normalizePath ) ;
208
218
209
219
const allPaths = new Set < string > ( [
210
220
...normalizedPathsFromUser ,
0 commit comments