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

Fix cargo module load when executable is not present. #19

Merged
merged 2 commits into from
Nov 29, 2023

Conversation

undyamon
Copy link
Contributor

Closes #17

local cargo_subcommands = {}

local ok, is_exe = pcall(vim.fn.executable, cmd)
Copy link
Owner

Choose a reason for hiding this comment

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

Maybe put Job:new here to avoid checking if it's an executable twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean something like this?

  local ok, job = pcall(Job.new, Job, {
    command = 'cargo',
    args = { '--list' },
    enabled_recording = true,
  })
  if not ok then
    utils.notify(job, vim.log.levels.WARN)
    return {}
  end
  job:sync()

  if job.code ~= 0 or job.signal ~= 0 then
    utils.notify('Unable to get list of available cargo subcommands', vim.log.levels.WARN)
    return {}
  end

Copy link
Owner

Choose a reason for hiding this comment

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

Yep!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed so I could test the config in nixos. Hold on a sec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

utils.notify(job, vim.log.levels.WARN)

This line dumps the stack trace as a warning the first time one uses auto (and it realizes cargo is not available). It is slightly annoying because it causes the classic Press ENTER or type command to continue.

Do you have a better idea on how to handle this? Sometimes it could be useful to get the warning so I don't think we should discard it.

Copy link
Owner

Choose a reason for hiding this comment

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

I think it's fine if user uses auto in a repo with Cargo.toml? But instead of stacktrace I would write something like 'unable to execute "cargo"'.

@Shatur Shatur merged commit cbd99ac into Shatur:master Nov 29, 2023
2 checks passed
@undyamon undyamon deleted the fix-missing-cargo branch January 29, 2024 16:13
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.

"auto" task not working when cargo not installed
2 participants