Repository: phpactor/phpactor (php)

Issue:
Error when going to definition at the end of file
For the file and cursor:
```php
<?php

$asd = 5;
$asd = 4;<>
```
I get this output:
```
[Trace - 3:48:13 PM] Sending request 'textDocument/definition - (36)'.
Params: {
    "textDocument": {
        "uri": "file:///root/test/test.php"
    },
    "position": {
        "line": 3,
        "character": 9
    }
}


[Trace - 3:48:13 PM] Received response 'textDocument/definition - (36)' in 3ms. Request failed: Exception [OutOfBoundsException] Byte offset 27 is larger than text length 26 at /root/.shared_extensions/phpactor2/lib/TextDocument/Util/WordAtOffset.php#42 (-32603).
Error data: "#0 /root/.shared_extensions/phpactor2/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php(73): Phpactor\\TextDocument\\Util\\WordAtOffset->__invoke('<?php\\n\\n$asd = 5...', 27)\n#1 /root/.shared_extensions/phpactor2/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php(44): Phpactor\\WorseReferenceFinder\\WorsePlainTextClassDefinitionLocator->extractWord(Object(Phpactor\\TextDocument\\StandardTextDocument), Object(Phpactor\\TextDocument\\ByteOffset))\n#2 /root/.shared_extensions/phpactor2/lib/ReferenceFinder/ChainDefinitionLocationProvider.php(34): Phpactor\\WorseReferenceFinder\\WorsePlainTextClassDefinitionLocator->locateDefinition(Object(Phpactor\\TextDocument\\StandardTextDocument), Object(Phpactor\\TextDocument\\ByteOffset))\n#3 /root/.shared_extensions/phpactor2/lib/Extension/LanguageServerReferenceFinder/Handler/GotoDefinitionHandler.php(62): Phpactor\\ReferenceFinder\\ChainDefinitionLocationProvider->locateDefinition(Object(Phpactor\\TextDocument\\StandardTextDocument), Object(Phpactor\\TextDocument\\ByteOffset))\n#4 [internal function]: Phpactor\\Extension\\LanguageServerReferenceFinder\\Handler\\GotoDefinitionHandler->Phpactor\\Extension\\LanguageServerReferenceFinder\\Handler\\{closure}()\n#5 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()\n#6 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\\Coroutine->__construct(Object(Generator))\n#7 /root/.shared_extensions/phpactor2/lib/Extension/LanguageServerReferenceFinder/Handler/GotoDefinitionHandler.php(93): Amp\\call(Object(Closure))\n#8 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Handler/HandlerMethodRunner.php(86): Phpactor\\Extension\\LanguageServerReferenceFinder\\Handler\\GotoDefinitionHandler->definition(Object(Phpactor\\LanguageServerProtocol\\DefinitionParams), Object(Amp\\CancellationToken@anonymous))\n#9 [internal function]: Phpactor\\LanguageServer\\Core\\Handler\\HandlerMethodRunner->Phpactor\\LanguageServer\\Core\\Handler\\{closure}()\n#10 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()\n#11 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\\Coroutine->__construct(Object(Generator))\n#12 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Handler/HandlerMethodRunner.php(102): Amp\\call(Object(Closure))\n#13 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/HandlerMiddleware.php(38): Phpactor\\LanguageServer\\Core\\Handler\\HandlerMethodRunner->dispatch(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#14 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\HandlerMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#15 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ResponseHandlingMiddleware.php(35): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#16 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\ResponseHandlingMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#17 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/MethodAliasMiddleware.php(37): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#18 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\MethodAliasMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#19 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/CancellationMiddleware.php(49): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#20 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\CancellationMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#21 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ShutdownMiddleware.php(68): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#22 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\ShutdownMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#23 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/InitializeMiddleware.php(68): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#24 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\InitializeMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#25 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ErrorHandlingMiddleware.php(39): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#26 [internal function]: Phpactor\\LanguageServer\\Middleware\\ErrorHandlingMiddleware->Phpactor\\LanguageServer\\Middleware\\{closure}()\n#27 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()\n#28 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\\Coroutine->__construct(Object(Generator))\n#29 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ErrorHandlingMiddleware.php(64): Amp\\call(Object(Closure))\n#30 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\\LanguageServer\\Middleware\\ErrorHandlingMiddleware->process(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage), Object(Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler))\n#31 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Dispatcher/Dispatcher/MiddlewareDispatcher.php(29): Phpactor\\LanguageServer\\Core\\Middleware\\RequestHandler->handle(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#32 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(221): Phpactor\\LanguageServer\\Core\\Dispatcher\\Dispatcher\\MiddlewareDispatcher->dispatch(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#33 [internal function]: Phpactor\\LanguageServer\\Core\\Server\\LanguageServer->Phpactor\\LanguageServer\\Core\\Server\\{closure}()\n#34 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()\n#35 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\\Coroutine->__construct(Object(Generator))\n#36 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(121): Amp\\call(Object(Closure))\n#37 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(238): Amp\\asyncCall(Object(Closure))\n#38 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(212): Phpactor\\LanguageServer\\Core\\Server\\LanguageServer->dispatchRequest(Object(Phpactor\\LanguageServer\\Core\\Server\\Transmitter\\ConnectionMessageTransmitter), Object(Phpactor\\LanguageServer\\Core\\Dispatcher\\Dispatcher\\MiddlewareDispatcher), Object(Phpactor\\LanguageServer\\Core\\Server\\StreamProvider\\Connection), Object(Phpactor\\LanguageServer\\Core\\Rpc\\RequestMessage))\n#39 [internal function]: Phpactor\\LanguageServer\\Core\\Server\\LanguageServer->Phpactor\\LanguageServer\\Core\\Server\\{closure}()\n#40 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RawMessage))\n#41 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\\Coroutine->Amp\\{closure}(NULL, Object(Phpactor\\LanguageServer\\Core\\Rpc\\RawMessage))\n#42 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(123): Amp\\Coroutine->resolve(Object(Phpactor\\LanguageServer\\Core\\Rpc\\RawMessage))\n#43 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\\Coroutine->Amp\\{closure}(NULL, 'Content-Length:...')\n#44 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Deferred.php(53): Amp\\Promise@anonymous->resolve('Content-Length:...')\n#45 /root/.shared_extensions/phpactor2/vendor/amphp/byte-stream/lib/ResourceInputStream.php(101): Amp\\Deferred->resolve('Content-Length:...')\n#46 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/NativeDriver.php(327): Amp\\ByteStream\\ResourceInputStream::Amp\\ByteStream\\{closure}('a', Resource id #1, NULL)\n#47 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/NativeDriver.php(127): Amp\\Loop\\NativeDriver->selectStreams(Array, Array, 0.1)\n#48 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\\Loop\\NativeDriver->dispatch(true)\n#49 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\\Loop\\Driver->tick()\n#50 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop.php(95): Amp\\Loop\\Driver->run()\n#51 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(112): Amp\\Loop::run(Object(Closure))\n#52 /root/.shared_extensions/phpactor2/lib/Extension/LanguageServer/Command/StartCommand.php(54): Phpactor\\LanguageServer\\Core\\Server\\LanguageServer->run()\n#53 /root/.shared_extensions/phpactor2/vendor/symfony/console/Command/Command.php(298): Phpactor\\Extension\\LanguageServer\\Command\\StartCommand->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#54 /root/.shared_extensions/phpactor2/vendor/symfony/console/Application.php(1015): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#55 /root/.shared_extensions/phpactor2/vendor/symfony/console/Application.php(299): Symfony\\Component\\Console\\Application->doRunCommand(Object(Phpactor\\Extension\\LanguageServer\\Command\\StartCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#56 /root/.shared_extensions/phpactor2/lib/Application.php(48): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#57 /root/.shared_extensions/phpactor2/vendor/symfony/console/Application.php(171): Phpactor\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#58 /root/.shared_extensions/phpactor2/bin/phpactor(47): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))\n#59 {main}"


[Error - 3:48:13 PM] Request textDocument/definition failed.
  Message: Exception [OutOfBoundsException] Byte offset 27 is larger than text length 26 at /root/.shared_extensions/phpactor2/lib/TextDocument/Util/WordAtOffset.php#42
  Code: -32603 
#0 /root/.shared_extensions/phpactor2/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php(73): Phpactor\TextDocument\Util\WordAtOffset->__invoke('<?php\n\n$asd = 5...', 27)
#1 /root/.shared_extensions/phpactor2/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php(44): Phpactor\WorseReferenceFinder\WorsePlainTextClassDefinitionLocator->extractWord(Object(Phpactor\TextDocument\StandardTextDocument), Object(Phpactor\TextDocument\ByteOffset))
#2 /root/.shared_extensions/phpactor2/lib/ReferenceFinder/ChainDefinitionLocationProvider.php(34): Phpactor\WorseReferenceFinder\WorsePlainTextClassDefinitionLocator->locateDefinition(Object(Phpactor\TextDocument\StandardTextDocument), Object(Phpactor\TextDocument\ByteOffset))
#3 /root/.shared_extensions/phpactor2/lib/Extension/LanguageServerReferenceFinder/Handler/GotoDefinitionHandler.php(62): Phpactor\ReferenceFinder\ChainDefinitionLocationProvider->locateDefinition(Object(Phpactor\TextDocument\StandardTextDocument), Object(Phpactor\TextDocument\ByteOffset))
#4 [internal function]: Phpactor\Extension\LanguageServerReferenceFinder\Handler\GotoDefinitionHandler->Phpactor\Extension\LanguageServerReferenceFinder\Handler\{closure}()
#5 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()
#6 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\Coroutine->__construct(Object(Generator))
#7 /root/.shared_extensions/phpactor2/lib/Extension/LanguageServerReferenceFinder/Handler/GotoDefinitionHandler.php(93): Amp\call(Object(Closure))
#8 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Handler/HandlerMethodRunner.php(86): Phpactor\Extension\LanguageServerReferenceFinder\Handler\GotoDefinitionHandler->definition(Object(Phpactor\LanguageServerProtocol\DefinitionParams), Object(Amp\CancellationToken@anonymous))
#9 [internal function]: Phpactor\LanguageServer\Core\Handler\HandlerMethodRunner->Phpactor\LanguageServer\Core\Handler\{closure}()
#10 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()
#11 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\Coroutine->__construct(Object(Generator))
#12 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Handler/HandlerMethodRunner.php(102): Amp\call(Object(Closure))
#13 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/HandlerMiddleware.php(38): Phpactor\LanguageServer\Core\Handler\HandlerMethodRunner->dispatch(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#14 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\HandlerMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#15 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ResponseHandlingMiddleware.php(35): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#16 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\ResponseHandlingMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#17 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/MethodAliasMiddleware.php(37): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#18 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\MethodAliasMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#19 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/CancellationMiddleware.php(49): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#20 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\CancellationMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#21 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ShutdownMiddleware.php(68): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#22 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\ShutdownMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#23 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/InitializeMiddleware.php(68): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#24 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\InitializeMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#25 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ErrorHandlingMiddleware.php(39): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#26 [internal function]: Phpactor\LanguageServer\Middleware\ErrorHandlingMiddleware->Phpactor\LanguageServer\Middleware\{closure}()
#27 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()
#28 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\Coroutine->__construct(Object(Generator))
#29 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Middleware/ErrorHandlingMiddleware.php(64): Amp\call(Object(Closure))
#30 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Middleware/RequestHandler.php(37): Phpactor\LanguageServer\Middleware\ErrorHandlingMiddleware->process(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage), Object(Phpactor\LanguageServer\Core\Middleware\RequestHandler))
#31 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Dispatcher/Dispatcher/MiddlewareDispatcher.php(29): Phpactor\LanguageServer\Core\Middleware\RequestHandler->handle(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#32 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(221): Phpactor\LanguageServer\Core\Dispatcher\Dispatcher\MiddlewareDispatcher->dispatch(Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#33 [internal function]: Phpactor\LanguageServer\Core\Server\LanguageServer->Phpactor\LanguageServer\Core\Server\{closure}()
#34 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(67): Generator->current()
#35 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(96): Amp\Coroutine->__construct(Object(Generator))
#36 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/functions.php(121): Amp\call(Object(Closure))
#37 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(238): Amp\asyncCall(Object(Closure))
#38 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(212): Phpactor\LanguageServer\Core\Server\LanguageServer->dispatchRequest(Object(Phpactor\LanguageServer\Core\Server\Transmitter\ConnectionMessageTransmitter), Object(Phpactor\LanguageServer\Core\Dispatcher\Dispatcher\MiddlewareDispatcher), Object(Phpactor\LanguageServer\Core\Server\StreamProvider\Connection), Object(Phpactor\LanguageServer\Core\Rpc\RequestMessage))
#39 [internal function]: Phpactor\LanguageServer\Core\Server\LanguageServer->Phpactor\LanguageServer\Core\Server\{closure}()
#40 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(118): Generator->send(Object(Phpactor\LanguageServer\Core\Rpc\RawMessage))
#41 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, Object(Phpactor\LanguageServer\Core\Rpc\RawMessage))
#42 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Coroutine.php(123): Amp\Coroutine->resolve(Object(Phpactor\LanguageServer\Core\Rpc\RawMessage))
#43 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Internal/Placeholder.php(149): Amp\Coroutine->Amp\{closure}(NULL, 'Content-Length:...')
#44 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Deferred.php(53): Amp\Promise@anonymous->resolve('Content-Length:...')
#45 /root/.shared_extensions/phpactor2/vendor/amphp/byte-stream/lib/ResourceInputStream.php(101): Amp\Deferred->resolve('Content-Length:...')
#46 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/NativeDriver.php(327): Amp\ByteStream\ResourceInputStream::Amp\ByteStream\{closure}('a', Resource id #1, NULL)
#47 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/NativeDriver.php(127): Amp\Loop\NativeDriver->selectStreams(Array, Array, 0.1)
#48 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/Driver.php(138): Amp\Loop\NativeDriver->dispatch(true)
#49 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop/Driver.php(72): Amp\Loop\Driver->tick()
#50 /root/.shared_extensions/phpactor2/vendor/amphp/amp/lib/Loop.php(95): Amp\Loop\Driver->run()
#51 /root/.shared_extensions/phpactor2/vendor/phpactor/language-server/lib/Core/Server/LanguageServer.php(112): Amp\Loop::run(Object(Closure))
#52 /root/.shared_extensions/phpactor2/lib/Extension/LanguageServer/Command/StartCommand.php(54): Phpactor\LanguageServer\Core\Server\LanguageServer->run()
#53 /root/.shared_extensions/phpactor2/vendor/symfony/console/Command/Command.php(298): Phpactor\Extension\LanguageServer\Command\StartCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#54 /root/.shared_extensions/phpactor2/vendor/symfony/console/Application.php(1015): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#55 /root/.shared_extensions/phpactor2/vendor/symfony/console/Application.php(299): Symfony\Component\Console\Application->doRunCommand(Object(Phpactor\Extension\LanguageServer\Command\StartCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#56 /root/.shared_extensions/phpactor2/lib/Application.php(48): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#57 /root/.shared_extensions/phpactor2/vendor/symfony/console/Application.php(171): Phpactor\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#58 /root/.shared_extensions/phpactor2/bin/phpactor(47): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#59 {main}

```

Pull request description:
Gh 1743
Fixes #1743 

Patch:
diff --git a/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php b/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php
index 43307635..54c668a8 100644
--- a/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php
+++ b/lib/WorseReferenceFinder/WorsePlainTextClassDefinitionLocator.php
@@ -68,9 +68,14 @@ class WorsePlainTextClassDefinitionLocator implements DefinitionLocator
 
     private function extractWord(TextDocument $document, ByteOffset $byteOffset): string
     {
+        $offset = $byteOffset->toInt() + 1;
+        $docLength = strlen($document->__toString());
+        if ($offset > $docLength) {
+            $offset = $docLength;
+        }
         return (new WordAtOffset(
             WordAtOffset::SPLIT_QUALIFIED_PHP_NAME
-        ))->__invoke($document->__toString(), $byteOffset->toInt() + 1);
+        ))->__invoke($document->__toString(), $offset);
     }
 
     private function resolveClassName(TextDocument $document, ByteOffset $byteOffset, string $word): string


Test patch:
diff --git a/lib/WorseReferenceFinder/Tests/Unit/WorsePlainTextDefinitionLocatorTest.php b/lib/WorseReferenceFinder/Tests/Unit/WorsePlainTextDefinitionLocatorTest.php
index e5c345b2..9ecaf371 100644
--- a/lib/WorseReferenceFinder/Tests/Unit/WorsePlainTextDefinitionLocatorTest.php
+++ b/lib/WorseReferenceFinder/Tests/Unit/WorsePlainTextDefinitionLocatorTest.php
@@ -35,6 +35,12 @@ class WorsePlainTextDefinitionLocatorTest extends DefinitionLocatorTestCase
         $this->locate('', 'Hello this i<>s ');
     }
 
+    public function testLastOffset(): void
+    {
+        $this->expectException(CouldNotLocateDefinition::class);
+        $this->locate('', 'Hello this is <>');
+    }
+
     /**
      * @return Generator<mixed>
      */