An Erlang Contextual Code Completion Library

I have developed contextual code completion for Erlang using Erlang itself. My library includes a module that generates completion suggestion structures and a front-end module that converts these into TextMate snippets. It would be relatively easy for someone familiar with distel to write a front-end module for Emacs. The TextMate integration also includes a TCP server process written in Erlang and a Python client that sends completion requests.

The complete:string/2 function is designed to take the local module and the text before the caret and provide a set of completions relevant to the context. It uses erl_scan:string/1 to get a set of syntax tokens for the context. By reversing the list of syntax tokens I can look back from the caret and determine what kind of completions to generate.

If for example the input was "lists:f" the reversed set of tokens would be [{atom,1,f},{':',1},{atom,1,lists}||_]. The set of completions in this case would be all the functions exported by module lists. A sample of the return value is {1,[{call,{flatten,1},{call,{flatten,2}},{call,{foldl,3}},{call,{foldr,3}}|_]}. After getting a set of completions it generates a set of menu options with tm_complete:menu/1. It prompts the TextMate user by passing this list to tm_menu:selection/1 and then matching the menu option selected with the underlying completion chosen. In the case that the user selects "flatten/2" the underlying completion option is identified as {call,{flatten,2}}. Passing the prefix length (1 because letter f is already typed) and this completion to tm_complete:snippet/2 function generates the TextMate snippet "latten(${1:Arg1}, ${2:Arg2})".

The entire code base and development history is available at the Erlang Code Completion project on GitHub. I will gladly assist anyone who is eager to integrate Erlang code completion into their favorite editor or IDE. The ins and out of developing extensions/plug-ins for your editor or IDE are your domain and I will unfortunately not be able to help there.

NOTE: As of this writing this is not yet part of the standard Erlang.tmbundle available in the TextMate bundle repository. I have forwarded a patch for it to textmate-dev@lists.macromates.com. I have also individually requested that Mietek Bąk (the Erlang.tmbundle maintainer) review my patch and commit it if he deems it fit.