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

nvim version from env #207

Merged
merged 12 commits into from
Jul 17, 2023
Merged

Conversation

tsukinoko-kun
Copy link
Contributor

@tsukinoko-kun tsukinoko-kun commented Jul 11, 2023

closes #146

I'm still working on it.

The version comparison is currently just a placeholder for the correct implementation.

I would appreciate any feedback to know if I'm on the right path here. @justinmk

@tsukinoko-kun tsukinoko-kun marked this pull request as ready for review July 12, 2023 21:38
@tsukinoko-kun
Copy link
Contributor Author

api/Buffer.test.ts sometimes fails on macos 11 with node 14. However, I don't see any connection with my changes.

accessSync(possibleNvimPath, constants.X_OK);
const nvimVersionFull = execSync(
`${possibleNvimPath} --version`
).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvim --api-info returns a msgpack object that includes a version dict. That avoids needing to parse nvim --version though I suppose that output isn't likely to change.

}

/**
* Get the highest matching nvim version from the environment.
Copy link
Member

@justinmk justinmk Jul 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "find the highest" version logic seems nice, but it might be worth dropping it to simplify the code. Instead, if the first nvim found doesn't meet the minimum version, the caller can simply report this to the user (mentioning the found nvim path and version).

fwiw, Nvim 0.9+ includes vim.version.parse(). Could eventually use that to avoid rolling our own semver parsing here.

Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! If you want to keep the version-comparison logic, that's not a blocker. The other comments hopefully are not much trouble.

@tsukinoko-kun
Copy link
Contributor Author

Is it worth adding a dependency like msgpackr to use the --api-info option instead of --version?

We have no control over the code in a dependency like this. This would bypass our linter rules.

I could write a more lightweight version of this that only does what we need here, but I don't think this is worth the effort.

@justinmk
Copy link
Member

Is it worth adding a dependency like msgpackr to use the --api-info option instead of --version?

Not worth adding a new dependency. But maybe (separate PR) worth replacing our old dependency (which was not particularly fast)?

"@msgpack/msgpack": "^2.7.1",

@tsukinoko-kun
Copy link
Contributor Author

The currently used msgpack causes problems. I would add the feature using --api-info later.

@tsukinoko-kun
Copy link
Contributor Author

Is there anything else you want me to change so this PR can be merged @justinmk ?

export function getNvimFromEnv(
opt: GetNvimFromEnvOptions = {}
): Readonly<GetNvimFromEnvResult> {
const paths = process.env.PATH.split(delimiter);
Copy link
Member

@justinmk justinmk Jul 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$PATH is likely not sufficient, especially for applications such as https://github.com/vscode-neovim/vscode-neovim which are started in GUI contexts and often (macOS, at least) the user's terminal $PATH is much different than whatever GUI apps are started with.

Thus we also need to search "common locations". These are the ones I know of:

/usr/local/bin/
/usr/bin
/opt/homebrew/bin
/home/linuxbrew/.linuxbrew/bin
$HOME/.linuxbrew/bin
$HOME/bin

Ironically on Windows I think we can depend on $PATH. I assume that winget and scoop setup $PATH, which gets broadcast to GUI programs on Windows. Else we may also need to add those locations. But that could be improved later.

@justinmk justinmk merged commit b5456fc into neovim:master Jul 17, 2023
@justinmk
Copy link
Member

justinmk commented Jul 17, 2023

Great work, thanks!

Merging, but I think the "common locations" will be needed for this to be maximally useful. #267

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API: "find Nvim" function
2 participants