"Position out of bounds" logic exception happens in rare cases
This seems to happen in rare cases. At first I assumed this was related to the file containing errors, php-parser then generating error nodes and the namespaces of the file not correctly being analyzed, but it seems to also happen for valid PHP code.
A location where I could reproduce this: go to LintCommandTest
and duplicate the line false,
multiple times (can be done by Ctrl-C
without any selection followed by Ctrl-V
, creating the new lines is important).
Normally the namespace indexing visitor should always ensure the last line of the file is used for the last namespace, so there should never be any position in a file where no namespace is present in the index. The error occurs because this apparantly isn't the case somewhere (hence the logic exception).
It seems to happen when retrieving signature help (call tips). It is very possible that via the base package signature help requests are being sent during the copy operation and these are being processed before the changes to the file were processed via a reindex command.
Normally changes should always be indexed before operating on them, but we'd need to think of a performant way to do this without hanging up the editor by spamming index requests for every minor change. It might be a good idea to take a look as to how the language server protocol suggests handling this. Another option would be to alert the server that a file changed without indexing it, so it knows that it must reindex the source code (that is passed along with the signature help request and might be different from the last indexed source code) before operating on it. Blindly indexing all the source code that is sent for every request to the server would result in a large performance penalty, so that is not an option.