Fix handling of completions and tidy up code parser
Update test to reflect fixed completion