-
-
Notifications
You must be signed in to change notification settings - Fork 114
feat(lsp): target architecture switching command for RustAnalyzer
#541
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
Changes from 3 commits
4eacda9
cc3bbf4
2803c7c
9dcaecb
b43edb2
c4896e7
288a760
6859b18
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| local T = {} | ||
|
|
||
| local rustc_targets_cache = nil | ||
|
|
||
| --- Get rustc targets, use cache if available | ||
| ---@return table<string, boolean> | ||
| local function get_rustc_targets() | ||
| if rustc_targets_cache then | ||
| return rustc_targets_cache | ||
| end | ||
|
|
||
| local result = vim.system({ 'rustc', '--print', 'target-list' }):wait() | ||
|
||
| if result.code ~= 0 then | ||
| error('Failed to retrieve rustc targets: ' .. result.stderr) | ||
| end | ||
|
|
||
| rustc_targets_cache = {} | ||
| for line in result.stdout:gmatch('[^\r\n]+') do | ||
| rustc_targets_cache[line] = true | ||
| end | ||
|
|
||
| return rustc_targets_cache | ||
| end | ||
|
|
||
| --- Validates if the provided target is a valid Rust compiler (rustc) target. | ||
| --- If no target is provided, it defaults to the system's architecture. | ||
| ---@param target? string | ||
| ---@return boolean | ||
| function T.target_is_valid_rustc_target(target) | ||
borngraced marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if target == nil then | ||
| return true | ||
| end | ||
|
|
||
| local success, targets = pcall(get_rustc_targets) | ||
| if not success then | ||
| vim.notify('Error retrieving rustc targets: ' .. tostring(targets), vim.log.levels.ERROR) | ||
| return false | ||
| end | ||
|
|
||
| return targets[target] or false | ||
| end | ||
|
|
||
| return T | ||
Uh oh!
There was an error while loading. Please reload this page.