Completion: make the code more robust wrt contexts

Before calling a CompletionProvider function, be sure the context is
still valid. A CompletionProvider should also make the verification, but
since the verification was not possible before, old code can crash
without this commit.