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

feat(lsp): target architecture switching command for RustAnalyzer #541

Merged
merged 8 commits into from
Oct 17, 2024

Conversation

borngraced
Copy link
Contributor

@borngraced borngraced commented Oct 15, 2024

target_switch3.mp4

By default, RustAnalyzer uses the system architecture when analyzing and building projects. However, we often need to work with alternative targets, such as WebAssembly (wasm32-unknown-unknown). Without the ability to switch targets easily, we must manually reconfigure our rust-analyzer.config.target which can be inefficient.

Changes Made

• Added the :rustanalyzer target <target_arch> command:
• Accepts a valid rustc target (e.g., wasm32-unknown-unknown).
• Defaults to the system architecture if no target is provided.
• Notifies the user if an invalid target is supplied.
• Modified the restart_impl function to incorporate the new logic for setting and validating target architectures.

ref: https://doc.rust-lang.org/rustc/targets/built-in.html

Copy link
Contributor

Review Checklist

Does this PR follow the Contribution Guidelines? Following is a partial checklist:

Proper conventional commit scoping:

  • For example, fix(lsp): some lsp-related bugfix

  • Pull request title has the appropriate conventional commit prefix.

If applicable:

  • Tested
    • Tests have been added.
    • Tested manually (Steps to reproduce in PR description).
  • Updated documentation.

Copy link
Owner

@mrcjkb mrcjkb left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great 🙏 😄

lua/rustaceanvim/lsp/targets.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/targets.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
lua/rustaceanvim/lsp/init.lua Outdated Show resolved Hide resolved
return rustc_targets_cache
end

local result = vim.system({ 'rustc', '--print', 'target-list' }):wait()
Copy link
Owner

Choose a reason for hiding this comment

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

suggestion: vim.system():wait() blocks Neovim's event loop.
It's generally better to use vim.system and pass in a callback, which is a function(result) where result is a vim.SystemCompleted.

This means that this function has to be changed, e.g. to with_rustc_targets(callback: fun(targets)).
It's a bit of a refactor, but I think it's doable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

lua/rustaceanvim/lsp/targets.lua Outdated Show resolved Hide resolved
@borngraced
Copy link
Contributor Author

@mrcjkb I worked on the improvement fixes.

@mrcjkb mrcjkb changed the title implement target architecture switching command for RustAnalyzer feat(lsp): target architecture switching command for RustAnalyzer Oct 17, 2024
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.

2 participants