diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 69f7c1b9..df90aeec 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,14 +1,15 @@ name: ci on: - push: - branches: - - main - pull_request: - branches: - - main - schedule: - - cron: '0 0 * * *' + workflow_dispatch: + # push: + # branches: + # - main + # pull_request: + # branches: + # - main + # schedule: + # - cron: '0 0 * * *' jobs: test: diff --git a/crates/api/src/types/command_complete.rs b/crates/api/src/types/command_complete.rs index cd096597..02f8afd3 100644 --- a/crates/api/src/types/command_complete.rs +++ b/crates/api/src/types/command_complete.rs @@ -1,4 +1,18 @@ +#[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. +use std::fmt; + +#[cfg(not(feature = "neovim-0-12"))] // On 0.11 Only use serde::Serialize; +#[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. +use serde::{Deserialize, Serialize, de}; +#[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. +use types::{ + Function, + Object, + conversion::{self, FromObject, ToObject}, + serde::{Deserializer, Serializer}, +}; +#[cfg(not(feature = "neovim-0-12"))] // On 0.11 Only use types::{ Function, Object, @@ -6,6 +20,8 @@ use types::{ serde::Serializer, }; +type CustomListFunc = Function<(String, String, usize), Vec>; + /// See `:h command-complete` for details. #[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq, Hash, Serialize)] @@ -14,12 +30,17 @@ pub enum CommandComplete { Arglist, Augroup, Buffer, - Behave, + Breakpoint, Color, Command, Compiler, - Cscope, + #[serde(rename = "custom")] + CustomFromCompleteArg, + #[serde(rename = "customlist")] + CustomlistFromCompleteArg, + DiffBuffer, Dir, + DirInPath, Environment, Event, Expression, @@ -30,6 +51,7 @@ pub enum CommandComplete { Help, Highlight, History, + Keymap, Locale, Lua, Mapclear, @@ -38,7 +60,12 @@ pub enum CommandComplete { Messages, Option, Packadd, + #[cfg(feature = "neovim-0-12")] // On 0.12 and Nightly + Retab, + Runtime, + Scriptnames, Shellcmd, + Shellcmdline, Sign, Syntax, Syntime, @@ -48,7 +75,7 @@ pub enum CommandComplete { Var, /// See `:h command-completion-customlist` for details. - CustomList(Function<(String, String, usize), Vec>), + CustomList(CustomListFunc), } impl ToObject for CommandComplete { @@ -56,3 +83,107 @@ impl ToObject for CommandComplete { self.serialize(Serializer::new()).map_err(Into::into) } } + +#[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. +impl FromObject for CommandComplete { + fn from_object(obj: Object) -> Result { + Self::deserialize(Deserializer::new(obj)).map_err(Into::into) + } +} + +#[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. +impl<'de> de::Deserialize<'de> for CommandComplete { + fn deserialize(deserializer: D) -> Result + where + D: de::Deserializer<'de>, + { + struct CommandCompleteVisitor; + + impl de::Visitor<'_> for CommandCompleteVisitor { + type Value = CommandComplete; + + fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str( + "string or function (see `:help command-completion`)", + ) + } + + fn visit_str(self, v: &str) -> Result + where + E: de::Error, + { + match v { + "arglist" => return Ok(Self::Value::Arglist), + "augroup" => return Ok(Self::Value::Augroup), + "buffer" => return Ok(Self::Value::Buffer), + "breakpoint" => return Ok(Self::Value::Breakpoint), + "color" => return Ok(Self::Value::Color), + "command" => return Ok(Self::Value::Command), + "compiler" => return Ok(Self::Value::Compiler), + "custom" => return Ok(Self::Value::CustomFromCompleteArg), + "customlist" => { + return Ok(Self::Value::CustomlistFromCompleteArg); + }, + "diff_buffer" => return Ok(Self::Value::DiffBuffer), + "dir" => return Ok(Self::Value::Dir), + "dir_in_path" => return Ok(Self::Value::DirInPath), + "environment" => return Ok(Self::Value::Environment), + "event" => return Ok(Self::Value::Event), + "expression" => return Ok(Self::Value::Expression), + "file" => return Ok(Self::Value::File), + "file_in_path" => return Ok(Self::Value::FileInPath), + "filetype" => return Ok(Self::Value::Filetype), + "function" => return Ok(Self::Value::Function), + "help" => return Ok(Self::Value::Help), + "highlight" => return Ok(Self::Value::Highlight), + "history" => return Ok(Self::Value::History), + "keymap" => return Ok(Self::Value::Keymap), + "locale" => return Ok(Self::Value::Locale), + "lua" => return Ok(Self::Value::Lua), + "mapclear" => return Ok(Self::Value::Mapclear), + "mapping" => return Ok(Self::Value::Mapping), + "menu" => return Ok(Self::Value::Menu), + "messages" => return Ok(Self::Value::Messages), + "option" => return Ok(Self::Value::Option), + "packadd" => return Ok(Self::Value::Packadd), + #[cfg(feature = "neovim-0-12")] // On 0.12 and Nightly + "retab" => return Ok(Self::Value::Retab), + "runtime" => return Ok(Self::Value::Runtime), + "scriptnames" => return Ok(Self::Value::Scriptnames), + "shellcmd" => return Ok(Self::Value::Shellcmd), + "shellcmdline" => return Ok(Self::Value::Shellcmdline), + "sign" => return Ok(Self::Value::Sign), + "syntax" => return Ok(Self::Value::Syntax), + "syntime" => return Ok(Self::Value::Syntime), + "tag" => return Ok(Self::Value::Tag), + "tag_listfiles" => return Ok(Self::Value::TagListfiles), + "user" => return Ok(Self::Value::User), + "var" => return Ok(Self::Value::Var), + + _ => {}, + }; + + Err(E::invalid_value( + de::Unexpected::Str(v), + &"completion type (see `:help command-completion`)", + )) + } + + fn visit_f32(self, v: f32) -> Result + where + E: de::Error, + { + let lua_ref = Object::from_luaref(v as i32); + if let Ok(func) = CustomListFunc::from_object(lua_ref) { + return Ok(Self::Value::CustomList(func)); + } + Err(E::invalid_value( + de::Unexpected::Float(v as f64), + &"custom_list like completion function", + )) + } + } + + deserializer.deserialize_str(CommandCompleteVisitor) + } +} diff --git a/crates/api/src/types/command_infos.rs b/crates/api/src/types/command_infos.rs index 2d2f9696..5e1d7c4c 100644 --- a/crates/api/src/types/command_infos.rs +++ b/crates/api/src/types/command_infos.rs @@ -10,6 +10,8 @@ use types::{ }; use super::{CommandAddr, CommandArgs, CommandNArgs, CommandRange}; +#[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. +use crate::types::CommandComplete; #[non_exhaustive] #[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)] @@ -26,7 +28,10 @@ pub struct CommandInfos { /// Callback triggered by the command. pub callback: Option>, - /// Command complletion strategy. + /// Command completion strategy. + #[cfg(feature = "neovim-0-12")] // on 0.12 and Nightly. + pub complete: Option, + #[cfg(not(feature = "neovim-0-12"))] // On 0.11 Only pub complete: Option, /// TODO: docs