elixir-tools / elixir-tools.nvim

Neovim plugin for Elixir
MIT License
398 stars 29 forks source link

Gracefully handle latest_release check when offline #130

Closed binarytemple closed 1 year ago

binarytemple commented 1 year ago

Currently, if you attempt to start elixir-tools when offline, this error is generated:

Failed to run `config` for elixir.nvim
.../.local/share/nvim/lazy/elixir.nvim/lua/elixir/utils.lua:30: Expected value but found T_END at character 1
# stacktrace:
  - /elixir.nvim/lua/elixir/utils.lua:30 _in_ **latest_release**
  - /elixir.nvim/lua/elixir/init.lua:44 _in_ **setup**
  - ~/.config/nvim/lua/custom/plugins.lua:288 _in_ **config**
  - ~/brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:22
  - ~/brew/Cellar/neovim/0.9.1/share/nvim/runtime/filetype.lua:21
Press ENTER or type command to continue

With this change, if you attempt to start elixir-tools when offline, the following messages will instead be printed to the status line:

Failed request to Github to fetch version information for latest release of elixir-tools/credo-language-server
Failed request to Github to fetch version information for latest release of elixir-tools/next-ls
Client 1 quit with exit code 1 and signal 0
mhanberg commented 1 year ago

Thank you! I was just thinking about this the other day while on airplane wifi.

Would you mind seeing how to write a test for this?

Also it might be worth switching to vim.fn.jobstart since it can give you the actual exit code. I can't remember if it can be synchronous tho.

As an aside I should probably add a setting to disable automatic release fetching.

mhanberg commented 1 year ago

I think the bin scripts should default to not including the version in the dep spec if it's not a valid version in the env var.

So it will just use the cached version

binarytemple commented 1 year ago

Thank you! I was just thinking about this the other day while on airplane wifi.

Me too, oh the joys of flying from Stansted!

Would you mind seeing how to write a test for this?

My first lua code ever, literally copying info from the :help command, might take a while, need a big sleep first.

Also it might be worth switching to vim.fn.jobstart since it can give you the actual exit code. I can't remember if it can be synchronous tho.

Again, complete idiot here, I’ll need to read that up.

As an aside I should probably add a setting to disable automatic release fetching.

So long as it’s graceful, shouldn’t be a big deal, maybe it would be good to cache the info and serve stale version when online?

mhanberg commented 1 year ago

No worries on the unit test.

Once I get back to a computer I'll test locally and can merge. Can adjust the apis used later.

mhanberg commented 1 year ago

@binarytemple I made some changes that caches the latest-release result and falls back to it if the call to github fails.