@@ -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
*
@@ -144,48 +155,47 @@ function normalizePath(path: string): string {
144
155
}
145
156
146
157
function getPlatformSearchDirs ( ) : Set < string > {
147
- const paths = new Set < string > ( ) ;
158
+ const dirs = new Set < string > ( ) ;
148
159
const { PATH , USERPROFILE , LOCALAPPDATA , PROGRAMFILES , HOME } = process . env ;
149
160
150
- PATH ?. split ( delimiter ) . forEach ( p => paths . add ( normalizePath ( p ) ) ) ;
161
+ PATH ?. split ( delimiter ) . forEach ( p => dirs . add ( normalizePath ( p ) ) ) ;
151
162
152
- // Add common Neovim installation paths not always in the system's PATH.
163
+ // Add common Nvim locations which may not be in the system $ PATH.
153
164
if ( windows ) {
154
- // Scoop common install location
165
+ // Scoop install location.
155
166
if ( USERPROFILE ) {
156
- paths . add ( normalizePath ( `${ USERPROFILE } /scoop/shims` ) ) ;
167
+ dirs . add ( normalizePath ( `${ USERPROFILE } /scoop/shims` ) ) ;
157
168
}
158
- paths . add ( normalizePath ( 'C:/ProgramData/scoop/shims' ) ) ;
169
+ dirs . add ( normalizePath ( 'C:/ProgramData/scoop/shims' ) ) ;
159
170
160
- // Winget common install location
161
- // See https://github.com/microsoft/winget-cli/blob/master/doc/specs/%23182%20-%20Support%20for%20installation%20of%20portable%20standalone%20apps.md
171
+ // Winget install location. https://github.com/microsoft/winget-cli/blob/master/doc/specs/%23182%20-%20Support%20for%20installation%20of%20portable%20standalone%20apps.md
162
172
if ( LOCALAPPDATA ) {
163
- paths . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WindowsApps` ) ) ;
164
- paths . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WinGet/Packages` ) ) ;
173
+ dirs . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WindowsApps` ) ) ;
174
+ dirs . add ( normalizePath ( `${ LOCALAPPDATA } /Microsoft/WinGet/Packages` ) ) ;
165
175
}
166
176
if ( PROGRAMFILES ) {
167
- paths . add ( normalizePath ( `${ PROGRAMFILES } /Neovim/bin` ) ) ;
168
- paths . add ( normalizePath ( `${ PROGRAMFILES } (x86)/Neovim/bin` ) ) ;
169
- paths . add ( normalizePath ( `${ PROGRAMFILES } /WinGet/Packages` ) ) ;
170
- paths . add ( normalizePath ( `${ PROGRAMFILES } (x86)/WinGet/Packages` ) ) ;
177
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } /Neovim/bin` ) ) ;
178
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } (x86)/Neovim/bin` ) ) ;
179
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } /WinGet/Packages` ) ) ;
180
+ dirs . add ( normalizePath ( `${ PROGRAMFILES } (x86)/WinGet/Packages` ) ) ;
171
181
}
172
182
} else {
173
- // Common paths for Unix-like systems
183
+ // Common locations for Unix-like systems.
174
184
[
175
185
'/usr/local/bin' ,
176
186
'/usr/bin' ,
177
187
'/opt/homebrew/bin' ,
178
188
'/home/linuxbrew/.linuxbrew/bin' ,
179
189
'/snap/nvim/current/usr/bin' ,
180
- ] . forEach ( p => paths . add ( p ) ) ;
190
+ ] . forEach ( p => dirs . add ( p ) ) ;
181
191
182
192
if ( HOME ) {
183
- paths . add ( normalizePath ( `${ HOME } /bin` ) ) ;
184
- paths . add ( normalizePath ( `${ HOME } /.linuxbrew/bin` ) ) ;
193
+ dirs . add ( normalizePath ( `${ HOME } /bin` ) ) ;
194
+ dirs . add ( normalizePath ( `${ HOME } /.linuxbrew/bin` ) ) ;
185
195
}
186
196
}
187
197
188
- return paths ;
198
+ return dirs ;
189
199
}
190
200
191
201
/**
@@ -194,13 +204,13 @@ function getPlatformSearchDirs(): Set<string> {
194
204
* @param opt.minVersion See {@link FindNvimOptions.minVersion}
195
205
* @param opt.orderBy See {@link FindNvimOptions.orderBy}
196
206
* @param opt.firstMatch See {@link FindNvimOptions.firstMatch}
197
- * @param opt.paths See {@link FindNvimOptions.paths }
207
+ * @param opt.cmds See {@link FindNvimOptions.cmds }
198
208
* @param opt.dirs See {@link FindNvimOptions.dirs}
199
209
*/
200
210
export function findNvim ( opt : FindNvimOptions = { } ) : Readonly < FindNvimResult > {
201
211
const platformDirs = getPlatformSearchDirs ( ) ;
202
212
const nvimExecutable = windows ? 'nvim.exe' : 'nvim' ;
203
- const normalizedPathsFromUser = ( opt . paths ?? [ ] ) . map ( normalizePath ) ;
213
+ const normalizedPathsFromUser = ( opt . cmds ?? [ ] ) . map ( a => normalizePath ) ;
204
214
205
215
const allPaths = new Set < string > ( [
206
216
...normalizedPathsFromUser ,
0 commit comments