Skip to content

Commit 20adbe8

Browse files
authored
fix: findNvim() fails if path has spaces #323
fix #319
1 parent 053a222 commit 20adbe8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

packages/neovim/src/utils/findNvim.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { execSync } from 'node:child_process';
1+
import { execFileSync } from 'node:child_process';
22
import { join, delimiter } from 'node:path';
33
import { constants, existsSync, accessSync } from 'node:fs';
44

@@ -125,13 +125,13 @@ export function findNvim(opt: FindNvimOptions = {}): Readonly<FindNvimResult> {
125125
const matches = new Array<NvimVersion>();
126126
const invalid = new Array<NvimVersion>();
127127
for (let i = 0; i !== pathLength; i = i + 1) {
128-
const possibleNvimPath = join(paths[i], windows ? 'nvim.exe' : 'nvim');
129-
if (existsSync(possibleNvimPath)) {
128+
const nvimPath = join(paths[i], windows ? 'nvim.exe' : 'nvim');
129+
if (existsSync(nvimPath)) {
130130
try {
131-
accessSync(possibleNvimPath, constants.X_OK);
132-
const nvimVersionFull = execSync(
133-
`${possibleNvimPath} --version`
134-
).toString();
131+
accessSync(nvimPath, constants.X_OK);
132+
const nvimVersionFull = execFileSync(nvimPath, [
133+
'--version',
134+
]).toString();
135135
const nvimVersionMatch = nvimVersionRegex.exec(nvimVersionFull);
136136
const buildTypeMatch = buildTypeRegex.exec(nvimVersionFull);
137137
const luaJitVersionMatch = luaJitVersionRegex.exec(nvimVersionFull);
@@ -142,22 +142,22 @@ export function findNvim(opt: FindNvimOptions = {}): Readonly<FindNvimResult> {
142142
) {
143143
invalid.push({
144144
nvimVersion: nvimVersionMatch[1],
145-
path: possibleNvimPath,
145+
path: nvimPath,
146146
buildType: buildTypeMatch[1],
147147
luaJitVersion: luaJitVersionMatch[1],
148148
});
149149
} else {
150150
matches.push({
151151
nvimVersion: nvimVersionMatch[1],
152-
path: possibleNvimPath,
152+
path: nvimPath,
153153
buildType: buildTypeMatch[1],
154154
luaJitVersion: luaJitVersionMatch[1],
155155
});
156156
}
157157
}
158158
} catch (e) {
159159
invalid.push({
160-
path: possibleNvimPath,
160+
path: nvimPath,
161161
error: e,
162162
});
163163
}

0 commit comments

Comments
 (0)