Sublime Text 2 plugin for Drupal
I had previously created a simple Drush based script to recursively scan a Drupal project and create a Sublime Text 2 autocompletions file from all functions the scan found. Unfortunately this file was not unique to each project and needed to be generated each time anything changed. So I wanted to get around the problem by creating a plugin which leverages the ST2 API.
The plugin uses the on_query_completions method of the ST2 API to inject a project specific JSON array of completions. This array is generated each time a file is saved by scanning up the project tree until a Sublime Text project file is found where it then recursively scans each .module, .inc and .php file for functions and assembles a JSON formatted completions file. This completions file is stored alongside your ST2 project file.
For this plugin to work you must save your ST2 project file in the root of your Drupal project (at the same level as index.php, CHANGELOG.txt etc). You will also want to exclude the completions file from any VCS you use. In git you could add the following to your gitignore file:*.sublime-projectcompletions
As I have an SSD based computer the completions file is generated very quickly and using threading there is no noticeable loss of speed in ST2 while it generates. I haven’t tested on non SSD enabled machines so some feedback would be very useful. If anyone with better Python skills than me can optimise the code or offer solutions I’d be very grateful.
The plugin has been submitted to ST2’s excellent package control repository. From there it should be easy to install but until it appears you can also manually install it from github: https://github.com/tanc/st2-drupal-autocomplete.