Skip to content

Commit

Permalink
refactor(docs)!: rename types in LuaCATS annotations and vimdoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Jul 26, 2024
1 parent be9b723 commit c2a8fcb
Show file tree
Hide file tree
Showing 34 changed files with 487 additions and 336 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### BREAKING CHANGES

- Require Neovim `>= 0.10.0`.
- Rename types in LuaCATS annotations and vimdoc.

## [4.26.1] - 2024-07-10

Expand Down
229 changes: 141 additions & 88 deletions doc/rustaceanvim.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ftplugin/rust.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---@type RustaceanConfig
---@type rustaceanvim.Config
local config = require('rustaceanvim.config.internal')

if not vim.g.loaded_rustaceanvim then
Expand All @@ -8,7 +8,7 @@ if not vim.g.loaded_rustaceanvim then
vim.lsp.commands['rust-analyzer.runSingle'] = function(command)
local runnables = require('rustaceanvim.runnables')
local cached_commands = require('rustaceanvim.cached_commands')
---@type RARunnable[]
---@type rustaceanvim.RARunnable[]
local ra_runnables = command.arguments
local runnable = ra_runnables[1]
local cargo_args = runnable.args.cargoArgs
Expand Down
18 changes: 9 additions & 9 deletions lua/rustaceanvim/cached_commands.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
local M = {}

---@alias RARunnablesChoice { choice: integer, runnables: RARunnable[] }
---@alias rustaceanvim.RARunnablesChoice { choice: integer, runnables: rustaceanvim.RARunnable[] }

---@class CommandCache
---@class rustaceanvim.CommandCache
local cache = {
---@type RARunnableArgs | nil
---@type rustaceanvim.RARunnableArgs | nil
last_debuggable = nil,
---@type RARunnablesChoice
---@type rustaceanvim.RARunnablesChoice
last_runnable = nil,
---@type RARunnablesChoice
---@type rustaceanvim.RARunnablesChoice
last_testable = nil,
}

---@param choice integer
---@param runnables RARunnable[]
---@param runnables rustaceanvim.RARunnable[]
M.set_last_runnable = function(choice, runnables)
cache.last_runnable = {
choice = choice,
Expand All @@ -22,15 +22,15 @@ M.set_last_runnable = function(choice, runnables)
end

---@param choice integer
---@param runnables RARunnable[]
---@param runnables rustaceanvim.RARunnable[]
M.set_last_testable = function(choice, runnables)
cache.last_testable = {
choice = choice,
runnables = runnables,
}
end

---@param args RARunnableArgs
---@param args rustaceanvim.RARunnableArgs
M.set_last_debuggable = function(args)
cache.last_debuggable = args
end
Expand All @@ -50,7 +50,7 @@ M.execute_last_debuggable = function(executableArgsOverride)
end
end

---@param choice RARunnablesChoice
---@param choice rustaceanvim.RARunnablesChoice
---@param executableArgsOverride? string[]
local function override_executable_args_if_set(choice, executableArgsOverride)
if type(executableArgsOverride) == 'table' and #executableArgsOverride > 0 then
Expand Down
2 changes: 1 addition & 1 deletion lua/rustaceanvim/cargo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ end

---Attempts to find the root for an existing active client. If no existing
---client root is found, returns the result of evaluating `config.root_dir`.
---@param config RustaceanLspClientConfig
---@param config rustaceanvim.lsp.ClientConfig
---@param file_name string
---@return string | nil root_dir
function cargo.get_config_root_dir(config, file_name)
Expand Down
34 changes: 17 additions & 17 deletions lua/rustaceanvim/commands/code_action_group.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ local ui = require('rustaceanvim.ui')
local config = require('rustaceanvim.config.internal')
local M = {}

---@class RACodeAction
---@class rustaceanvim.RACodeAction
---@field kind string
---@field group? string
---@field edit? table
---@field command? { command: string } | string

---@class RACommand
---@class rustaceanvim.RACommand
---@field title string
---@field group? string
---@field command string
---@field arguments? any[]

---@param action RACodeAction | RACommand
---@param action rustaceanvim.RACodeAction | rustaceanvim.RACommand
---@param client lsp.Client
---@param ctx table
function M.apply_action(action, client, ctx)
Expand All @@ -32,7 +32,7 @@ function M.apply_action(action, client, ctx)
end
end

---@alias action_tuple { [1]: number, [2]: RACodeAction|RACommand }
---@alias action_tuple { [1]: number, [2]: rustaceanvim.RACodeAction|rustaceanvim.RACommand }

---@param action_tuple action_tuple | nil
---@param ctx table
Expand All @@ -48,7 +48,7 @@ function M.on_user_choice(action_tuple, ctx)
end
if not action.edit and type(code_action_provider) == 'table' and code_action_provider.resolveProvider then
client.request('codeAction/resolve', action, function(err, resolved_action)
---@cast resolved_action RACodeAction|RACommand
---@cast resolved_action rustaceanvim.RACodeAction|rustaceanvim.RACommand
if err then
vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
return
Expand All @@ -60,12 +60,12 @@ function M.on_user_choice(action_tuple, ctx)
end
end

---@class CodeActionWindowGeometry
---@class rustaceanvim.CodeActionWindowGeometry
---@field width integer

---@param action_tuples action_tuple[]
---@param is_group boolean
---@return CodeActionWindowGeometry
---@return rustaceanvim.CodeActionWindowGeometry
local function compute_width(action_tuples, is_group)
local width = 0

Expand Down Expand Up @@ -106,10 +106,10 @@ local function on_primary_quit()
M.cleanup()
end

---@class RACodeActionResult
---@field result? RACodeAction[] | RACommand[]
---@class rustaceanvim.RACodeActionResult
---@field result? rustaceanvim.RACodeAction[] | rustaceanvim.RACommand[]

---@param results { [number]: RACodeActionResult }
---@param results { [number]: rustaceanvim.RACodeActionResult }
---@param ctx table
local function on_code_action_results(results, ctx)
local cur_win = vim.api.nvim_get_current_win()
Expand All @@ -129,7 +129,7 @@ local function on_code_action_results(results, ctx)

M.state.primary.geometry = compute_width(action_tuples, true)
---@alias grouped_actions_tbl { actions: action_tuple[], idx: integer | nil }
---@class PartitionedActions
---@class rustaceanvim.PartitionedActions
M.state.actions = {
grouped = {},
ungrouped = {},
Expand Down Expand Up @@ -332,16 +332,16 @@ function M.on_cursor_move()
end
end

---@class CodeActionWindowState
---@class rustaceanvim.CodeActionWindowState
---@field bufnr integer | nil
---@field winnr integer | nil
---@field geometry CodeActionWindowGeometry | nil
---@field geometry rustaceanvim.CodeActionWindowGeometry | nil
---@field clear fun()

---@class CodeActionInternalState
---@class rustaceanvim.CodeActionInternalState
M.state = {
ctx = {},
---@type PartitionedActions
---@type rustaceanvim.PartitionedActions
actions = {
---@type grouped_actions_tbl[]
grouped = {},
Expand All @@ -350,7 +350,7 @@ M.state = {
},
---@type number | nil
active_group_index = nil,
---@type CodeActionWindowState
---@type rustaceanvim.CodeActionWindowState
primary = {
bufnr = nil,
winnr = nil,
Expand All @@ -361,7 +361,7 @@ M.state = {
M.state.primary.winnr = nil
end,
},
---@type CodeActionWindowState
---@type rustaceanvim.CodeActionWindowState
secondary = {
bufnr = nil,
winnr = nil,
Expand Down
22 changes: 11 additions & 11 deletions lua/rustaceanvim/commands/debuggables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ end
---@type { [string]: boolean? } Used to prevent this plugin from adding the same configuration twice
local _dap_configuration_added = {}

---@param args RARunnableArgs
---@param args rustaceanvim.RARunnableArgs
---@return string
local function build_label(args)
local ret = ''
Expand All @@ -35,7 +35,7 @@ local function build_label(args)
return ret
end

---@param result RARunnable[]
---@param result rustaceanvim.RARunnable[]
---@return string[] option_strings
local function get_options(result)
---@type string[]
Expand All @@ -53,7 +53,7 @@ local function get_options(result)
return option_strings
end

---@param args RARunnableArgs
---@param args rustaceanvim.RARunnableArgs
---@return boolean
local function is_valid_test(args)
local is_not_cargo_check = args.cargoArgs[1] ~= 'check'
Expand All @@ -66,11 +66,11 @@ end
-- This function also makes it so that the debuggable commands are more
-- debugging friendly. For example, we move cargo run to cargo build, and cargo
-- test to cargo test --no-run.
---@param result RARunnable[]
---@param result rustaceanvim.RARunnable[]
local function sanitize_results_for_debugging(result)
---@type RARunnable[]
---@type rustaceanvim.RARunnable[]
local ret = vim.tbl_filter(function(value)
---@cast value RARunnable
---@cast value rustaceanvim.RARunnable
return is_valid_test(value.args)
end, result or {})

Expand All @@ -95,7 +95,7 @@ local function dap_run(args)
end
end

---@param debuggables RARunnable[]
---@param debuggables rustaceanvim.RARunnable[]
---@param executableArgsOverride? string[]
local function ui_select_debuggable(debuggables, executableArgsOverride)
debuggables = ra_runnables.apply_exec_args_override(executableArgsOverride, debuggables)
Expand All @@ -112,7 +112,7 @@ local function ui_select_debuggable(debuggables, executableArgsOverride)
end)
end

---@param debuggables RARunnable[]
---@param debuggables rustaceanvim.RARunnable[]
local function add_debuggables_to_nvim_dap(debuggables)
local ok, dap = pcall(require, 'dap')
if not ok then
Expand All @@ -132,7 +132,7 @@ local function add_debuggables_to_nvim_dap(debuggables)
end
end

---@param debuggables RARunnable[]
---@param debuggables rustaceanvim.RARunnable[]
---@param executableArgsOverride? string[]
local function debug_at_cursor_position(debuggables, executableArgsOverride)
if debuggables == nil then
Expand All @@ -148,10 +148,10 @@ local function debug_at_cursor_position(debuggables, executableArgsOverride)
dap_run(args)
end

---@param callback fun(result:RARunnable[])
---@param callback fun(result:rustaceanvim.RARunnable[])
local function mk_handler(callback)
return function(_, result, _, _)
---@cast result RARunnable[]
---@cast result rustaceanvim.RARunnable[]
if result == nil then
return
end
Expand Down
2 changes: 1 addition & 1 deletion lua/rustaceanvim/commands/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local ui = require('rustaceanvim.ui')

local rustc = 'rustc'

---@class DiagnosticWindowState
---@class rustaceanvim.diagnostic.WindowState
local _window_state = {
---@type integer | nil
float_winnr = nil,
Expand Down
6 changes: 3 additions & 3 deletions lua/rustaceanvim/commands/expand_macro.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
---@type integer | nil
local latest_buf_id = nil

---@class RAMacroExpansionResult
---@class rustaceanvim.RAMacroExpansionResult
---@field name string
---@field expansion string

Expand All @@ -22,7 +22,7 @@ local latest_buf_id = nil
-- {
-- $crate::io::_eprint(std::fmt::Arguments::new_v1(&[], &[std::fmt::ArgumentV1::new(&(err),std::fmt::Display::fmt),]));
-- }
---@param result RAMacroExpansionResult
---@param result rustaceanvim.RAMacroExpansionResult
---@return string[]
local function parse_lines(result)
local ret = {}
Expand All @@ -42,7 +42,7 @@ local function parse_lines(result)
return ret
end

---@param result? RAMacroExpansionResult
---@param result? rustaceanvim.RAMacroExpansionResult
local function handler(_, result)
-- echo a message when result is nil (meaning no macro under cursor) and
-- exit
Expand Down
4 changes: 2 additions & 2 deletions lua/rustaceanvim/commands/fly_check.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ local M = {}

local rl = require('rustaceanvim.rust_analyzer')

---@alias flyCheckCommand 'run' | 'clear' | 'cancel'
---@alias rustaceanvim.flyCheckCommand 'run' | 'clear' | 'cancel'

---@param cmd flyCheckCommand
---@param cmd rustaceanvim.flyCheckCommand
function M.fly_check(cmd)
local params = cmd == 'run' and vim.lsp.util.make_text_document_params() or {}
rl.notify('rust-analyzer/' .. cmd .. 'Flycheck', params)
Expand Down
10 changes: 5 additions & 5 deletions lua/rustaceanvim/commands/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@

local config = require('rustaceanvim.config.internal')

---@class RustaceanCommands
---@class rustaceanvim.Commands
local M = {}

local rust_lsp_cmd_name = 'RustLsp'
local rustc_cmd_name = 'Rustc'

---@class command_tbl
---@class rustaceanvim.command_tbl
---@field impl fun(args: string[], opts: vim.api.keyset.user_command) The command implementation
---@field complete? fun(subcmd_arg_lead: string): string[] Command completions callback, taking the lead of the subcommand's arguments
---@field bang? boolean Whether this command supports a bang!

---@type command_tbl[]
---@type rustaceanvim.command_tbl[]
local rustlsp_command_tbl = {
codeAction = {
impl = function(_)
Expand Down Expand Up @@ -278,7 +278,7 @@ local rustlsp_command_tbl = {
},
}

---@type command_tbl[]
---@type rustaceanvim.command_tbl[]
local rustc_command_tbl = {
unpretty = {
impl = function(args)
Expand Down Expand Up @@ -309,7 +309,7 @@ local rustc_command_tbl = {
},
}

---@param command_tbl command_tbl
---@param command_tbl rustaceanvim.command_tbl
---@param opts table
---@see vim.api.nvim_create_user_command
local function run_command(command_tbl, cmd_name, opts)
Expand Down
4 changes: 2 additions & 2 deletions lua/rustaceanvim/commands/rustc_unpretty.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ M.available_unpretty = {
'stable-mir',
'mir-cfg',
}
---@alias rustcir_level 'normal'| 'identified'| 'expanded'| 'expanded,identified'| 'expanded,hygiene'| 'ast-tree'| 'ast-tree,expanded'| 'hir'| 'hir,identified'| 'hir,typed'| 'hir-tree'| 'thir-tree'| 'thir-flat'| 'mir'| 'stable-mir'| 'mir-cfg'
---@alias rustaceanvim.rustcir.level 'normal'| 'identified'| 'expanded'| 'expanded,identified'| 'expanded,hygiene'| 'ast-tree'| 'ast-tree,expanded'| 'hir'| 'hir,identified'| 'hir,typed'| 'hir-tree'| 'thir-tree'| 'thir-flat'| 'mir'| 'stable-mir'| 'mir-cfg'

---@type integer | nil
local latest_buf_id = nil
Expand Down Expand Up @@ -92,7 +92,7 @@ local function handler(sc)
vim.api.nvim_buf_set_lines(latest_buf_id, 0, 0, false, lines)
end

---@param level rustcir_level
---@param level rustaceanvim.rustcir.level
function M.rustc_unpretty(level)
if #api.nvim_get_runtime_file('parser/rust.so', true) == 0 then
vim.notify("a treesitter parser for Rust is required for 'rustc unpretty'", vim.log.levels.ERROR)
Expand Down
Loading

0 comments on commit c2a8fcb

Please sign in to comment.