samaaron/sonic-pi — pull request #159 by jweather (2014-10-16 03:44:09+00:00)
Title: Context-aware autocompletion

Autocompletion has landed, with support for:

* all SPi keywords, synths, and FX names (generated at build time by qt-doc.rb)
* all built-in sample names (scanned at runtime from etc/samples)
* chord and scale names (hardcoded in sonicpiapis.cpp for now)
* FX arg names (generated at build time by qt-doc.rb)

It would be fantastic to include synth arg names, but it would require guessing about what the current synth is -- should we scan backwards in the text for the last use_synth/with_synth or are we more likely to be wrong than right? I also thought about only completing the "core" synth args, but that may produce confusion if users think those are the only args available.

The parsing is naive, and will be thrown off by stuff like "chord [:E3, :B3].choose, " since it doesn't think you're on the second argument anymore. I'm not trying to catch special cases like these -- an AST parser is the right place to do that.

Structurally, this involved subclassing QsciScintilla to implement apiContext() so we get more than just the previous word for context, and subclassing QsciAbstractAPIs to implement a context parser (well, guesser).