Neovim 主机插件 Elixir 。
示例代码;
defmodule AutoComplete do use NVim.Plugin deffunc elixir_complete("1",_,cursor,line,state), eval: "col('.')", eval: "getline('.')" do cursor = cursor - 1 # because we are in insert mode [tomatch] = Regex.run(~r"[\w\.:]*$",String.slice(line,0..cursor-1)) cursor - String.length(tomatch) end deffunc elixir_complete(_,base,_,_,state), eval: "col('.')", eval: "getline('.')" do case (base |> to_char_list |> Enum.reverse |> IEx.Autocomplete.expand) do {:no,_,_}-> [base] # no expand {:yes,comp,[]}->["#{base}#{comp}"] #simple expand, no choices {:yes,_,alts}-> # multiple choices Enum.map(alts,fn comp-> {base,comp} = {String.replace(base,~r"[^.]*$",""), to_string(comp)} case Regex.run(~r"^(.*)/([0-9]+)$",comp) do # first see if these choices are module or function [_,function,arity]-> # it is a function completion replace = base<>function module = if String.last(base) == ".", do: Module.concat([String.slice(base,0..-2)]), else: Kernel if (docs=Code.get_docs(module,:docs)) && (doc=List.keyfind(docs,{:"#{function}",elem(Integer.parse(arity),0)},0)) && (docmd=elem(doc,4)) do %{"word"=>replace,"kind"=> if(elem(doc,2)==:def, do: "f", else: "m"), "abbr"=>comp,"info"=>docmd} else %{"word"=>replace,"abbr"=>comp} end nil-> # it is a module completion module = base<>comp case Code.get_docs(Module.concat([module]),:moduledoc) do {_,moduledoc} -> %{"word"=>module,"info"=>moduledoc} _ -> %{"word"=>module} end end end) end end defautocmd file_type(state), pattern: "elixir", async: true do {:ok,nil} = NVim.vim_command("filetype plugin on") {:ok,nil} = NVim.vim_command("set omnifunc=ElixirComplete") state endend