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

[Question] Is there a way to reliably recall the executable files installed by the installer? #777

Closed
mikoto2000 opened this issue Oct 8, 2024 · 11 comments

Comments

@mikoto2000
Copy link
Contributor

Is there a way to reliably recall the executable files installed by the installer?
(* not the executable in the path)

I try :LspInstallServer rust-analyzer, but rustup's default install rust is put dummy rust-analyzer in PATH.
(See: rust-lang/rustup#3846)

So, vim-lsp will also occur the following error.

error: Unknown binary 'rust-analyzer' in official toolchain 'stable-xxxx'.
To install, run `rustup component add rust-analyzer`.

lsp_settings#exec_path('rust-analyzer') is first search PATH environment.

\ 'cmd': {server_info->lsp_settings#get('rust-analyzer', 'cmd', [lsp_settings#exec_path('rust-analyzer')]+lsp_settings#get('rust-analyzer', 'args', []))},

function! lsp_settings#exec_path(cmd) abort

Can I call executable without PATH environment?

@mattn
Copy link
Owner

mattn commented Oct 8, 2024

Are you using windows-gnu toolchain? So, rust-analyzer does not provided for gnu toolchain. But you can use msvc toolchain instead. If you are using x86-64 arch PC, please install rust-analyzer-x86_64-pc-windows-msvc.zip, and put rust-analyzer.exe into your PATH somewhere. It should work since rust-analyzer works as single binary.

@mikoto2000
Copy link
Contributor Author

Thank you for your comment.
I understood install(put a PATH location) rust-analyzer single binary to be can running lsp.

However, I was concerned that the installed binary of vim-lsp-setting might not be used (highly).
For example, rust-analizer is placed as a single binary with install-rust-analizer.(sh|cmd), but if there is a binary with the same name on the path, it will not be used. (This resulted in the creation of this issue.)

Shouldn't we prioritize the ones installed via the installer over the ones on the path?

@mattn
Copy link
Owner

mattn commented Oct 8, 2024

Then, you should uninstall the binary LspUninstallServer rust-analyzer. vim-lsp-settings should use the executable found in the PATH.

@mikoto2000
Copy link
Contributor Author

Sorry, I'm confused.

I thought vim-lsp-settings was designed to use binaries installed with install-xxx.(sh|cmd).
Are the binaries installed by the installer not used?

I thought it was designed to first look for PATH, and if it wasn't found in PATH, it would use the binary installed by the installer.
I thought it would be better to prioritize what the installer installed.

† I'd like to talk about the design of vim-lsp-settings, not just rust-analyzer.

I'm sorry, I can't write in English well, so I will write in Japanese.

vim-lsp-settings は、 PATH にあるか探し、 PATH に無ければインストーラーがインストールしたバイナリを実行するものだと思っていました。
そうであれば、(インストーラーを作った時に動作確認したであろう、)インストーラーがインストールしたバイナリを使う方が問題が少なくなるのではと思いました。

@mattn
Copy link
Owner

mattn commented Oct 11, 2024

作っておいてアレなんですが、たしかインストーラが使われていたらそちらを、無ければパス内のものを、という動きにしていた気がしています。

@mikoto2000
Copy link
Contributor Author

あれ?そうなのですか、私の勘違いでしたか。もう一度挙動とソースを確認してみます。
コメントありがとうございます。

@mikoto2000
Copy link
Contributor Author

間違えて閉じてしまいました...

確認したところ、初期実装(?)の頃から「まず PATH を探して、無ければ g:lsp_settings_servers_dir から探す」という順序になっているようでした。

■ 現在の実装

PATH, g:lsp_settings_extrapaths の両方に無い場合、インストールされたものを使う実装。

function! lsp_settings#exec_path(cmd) abort
let l:paths = []
if has('win32')
for l:path in split($PATH, ';')
if l:path[len(l:path) - 1:] == "\\"
call add(l:paths, l:path[:len(l:path)-2])
elseif !empty(l:path)
call add(l:paths, l:path)
endif
endfor
else
let l:paths = split($PATH, ':')
endif
let l:paths = join(l:paths, ',')
let l:path = globpath(l:paths, a:cmd, 1)
if !has('win32')
if !empty(l:path)
return lsp_settings#utils#first_one(l:path)
endif
else
for l:ext in ['.exe', '.cmd', '.bat']
let l:path = globpath(l:paths, a:cmd . l:ext, 1)
if !empty(l:path)
return lsp_settings#utils#first_one(l:path)
endif
endfor
endif
let l:paths = get(g:, 'lsp_settings_extra_paths', '')
if type(l:paths) == type([])
let l:paths = join(l:paths, ',') . ','
endif
if !has('win32')
let l:paths .= lsp_settings#servers_dir() . '/' . a:cmd
return lsp_settings#utils#first_one(globpath(l:paths, a:cmd, 1))
endif
let l:paths .= lsp_settings#servers_dir() . '\' . a:cmd
for l:ext in ['.exe', '.cmd', '.bat']
let l:path = globpath(l:paths, a:cmd . l:ext, 1)
if !empty(l:path)
return lsp_settings#utils#first_one(l:path)
endif
endfor
return ''
endfunction

■ 初期(?)実装

PATH から探す処理の後ろに追加する形で初期(?)実装が行われている。

fef383e#diff-d7bcd9bf24c66b67490ed72182bce5de4a813ddbdd141d1fa21511bf8b5ee981R19

https://github.com/mattn/vim-lsp-settings/blob/fef383ee4daca1b856d7f001b6696bb210a1442c/autoload/lsp_settings.vim

@mikoto2000 mikoto2000 reopened this Oct 12, 2024
@mikoto2000
Copy link
Contributor Author

本来の優先順位としては、 「インストールされたもの > g:lsp_settings_extra_paths のもの > PATH 内のもの」という感じでしょうか?

@mattn
Copy link
Owner

mattn commented Oct 18, 2024

LspSettingsGlobalEdit で cmd を直接パス指定するのではだめでしょうか?

@mattn
Copy link
Owner

mattn commented Oct 18, 2024

例えばこういう感じに。
image

@mikoto2000
Copy link
Contributor Author

せっかくインストールしたものが使われないのがもったいないと思いましたが、こういう状況になるのは rust-analyzer くらいですかね。

それを考えると確かに設定や環境でカバーするほうが良いと思えてきました。
cmd のパス指定を試してみます!ありがとうございます!

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

No branches or pull requests

2 participants