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

RFC: Add a special module method to check if the module is available #572

Open
lambdalisue opened this issue Jan 23, 2018 · 8 comments
Open
Assignees

Comments

@lambdalisue
Copy link
Member

Summary

Add '_vital_healthcheck' method which will be called when the module is imported and raise an error with a reason when the module does not work on the running Vim.

Detail

I would like to make modules which requires some requriments.
In that case, the module might not work on some Vim and I would like to skip the tests.

To achive that, I made a helper module import function like

https://github.com/lambdalisue/vital-Whisky/blob/master/autoload/healthcheck/vital.vim

However, it contains a dependency to the vim-themis just for testing.

So it would be nice if vital.vim itself has similar special method which is automatically called when the module is imported and raise an error with the reason.
With that new feature, vim-themis or its harmonic plugin can wrap vital#xxx#import and skip with a reason raised when the module is not available.

What do you think? Esp, @thinca

@tyru
Copy link
Member

tyru commented Feb 27, 2018

返り値で neovim が使えるかどうか判断するとしたら

  • どんな構造の値を投げるのか
  • エラーでない値は何なのか
    • v:null は Vim 8 からなので使えない

を決める必要がありそうです。
もしくはエラーの時だけ :throw してしまえば2番目のエラーでない値を決める必要は無くなりそう。

@lambdalisue
Copy link
Member Author

返り値で neovim が使えるかどうか判断するとしたら

neovim 以外にも様々な理由でモジュールは利用不可になるため、返り値では判断できないと思っています。
返り値で返すべきは「なぜ、利用できないのか?」の理由が良いと思います。

個人的には自動的に呼ばれる関数があり、その関数でエラーを投げたら利用不可くらいのゆるい感じがいいなかと思います。

@tyru
Copy link
Member

tyru commented Feb 28, 2018

neovim 以外にも様々な理由でモジュールは利用不可になるため、返り値では判断できないと思っています。
返り値で返すべきは「なぜ、利用できないのか?」の理由が良いと思います。

理由を :throw する、という事でしょうか?(s/返り値で返すべき/例外で返すべき/ ?)

ゆるい感じ

自分もそんな感じでいいと思います。

あと投げる値の構造は個人的には文字列でいいと思います(他に含める情報が思い当たらない)。

@tyru
Copy link
Member

tyru commented Feb 28, 2018

ただ例外を投げるとなるとそもそも _vital_healthcheck って新しく追加する必要がない気がします。
_vital_created_vital_loaded で例外投げれば使用不可能だと判断する、で良いような(autoload/vital/_vital.vim の修正のみで良い)。

@ujihisa
Copy link
Member

ujihisa commented Feb 28, 2018

良さそう > 例外投げるならわざわざ確認用メソッドではなくload時で的な

@thinca
Copy link
Member

thinca commented Mar 1, 2018

特殊な関数 _vital_healthcheck (仮) は、利用不可な理由(文字列)の配列を返す。
vital loader はこの関数をチェックし、利用不可であれば例外を投げる。
が、良さそう。

@ujihisa
Copy link
Member

ujihisa commented Mar 1, 2018

名前案の第一候補: get_unavailable_reasons()
reject_reasons()

@lambdalisue
Copy link
Member Author

名前候補 _vital_validate でいいのではと思ってきた

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

4 participants