-
-
Notifications
You must be signed in to change notification settings - Fork 156
Incremental parser #3011
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dantleech
wants to merge
10
commits into
master
Choose a base branch
from
incremental-parser
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Incremental parser #3011
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba952c1
Introduce experimental incremental parser updates
dantleech d30b781
Move classes
dantleech ddce347
Update composer
dantleech d7f9384
Refactor
dantleech 4b67364
Refactored to extract strategies
dantleech cf27958
Extract token strategy test
dantleech 93fd211
Extract compound node test
dantleech ba16755
Always log edit failure
dantleech 801b11c
Fix diagnostics on update
dantleech f450096
UPdate doc
dantleech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
lib/Extension/LanguageServerWorseReflection/Listener/IncrementalAstListener.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| <?php | ||
|
|
||
| namespace Phpactor\Extension\LanguageServerWorseReflection\Listener; | ||
|
|
||
| use Phpactor\Extension\LanguageServerBridge\Converter\RangeConverter; | ||
| use Phpactor\Extension\LanguageServerBridge\Converter\TextDocumentConverter; | ||
| use Phpactor\LanguageServer\Core\Workspace\Workspace; | ||
| use Phpactor\LanguageServer\Event\TextDocumentClosed; | ||
| use Phpactor\LanguageServer\Event\TextDocumentIncrementallyUpdated; | ||
| use Phpactor\LanguageServer\Event\TextDocumentOpened; | ||
| use Phpactor\LanguageServer\Event\TextDocumentUpdated; | ||
| use Phpactor\LanguageServerProtocol\TextDocumentContentChangeIncrementalEvent; | ||
| use Phpactor\TextDocument\TextDocumentBuilder; | ||
| use Phpactor\WorseReflection\Bridge\TolerantParser\AstProvider\IncrementalAstProvider; | ||
| use Psr\EventDispatcher\ListenerProviderInterface; | ||
| use Phpactor\TextDocument\TextDocumentUri; | ||
| use Phpactor\TextDocument\TextEdit; | ||
| use Phpactor\TextDocument\TextEdits; | ||
|
|
||
| final class IncrementalAstListener implements ListenerProviderInterface | ||
| { | ||
| public function __construct( | ||
| private IncrementalAstProvider $provider, | ||
| private Workspace $workspace, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @return iterable<mixed> | ||
| */ | ||
| public function getListenersForEvent(object $event): iterable | ||
| { | ||
| if ($event instanceof TextDocumentIncrementallyUpdated) { | ||
| yield $this->update(...); | ||
| return; | ||
| } | ||
|
|
||
| if ($event instanceof TextDocumentClosed) { | ||
| yield function (TextDocumentClosed $closed): void { | ||
| $this->workspace->remove($closed->identifier()); | ||
| $this->provider->close(TextDocumentUri::fromString($closed->identifier()->uri)); | ||
| }; | ||
| return; | ||
| } | ||
|
|
||
| if ($event instanceof TextDocumentOpened) { | ||
| yield function (TextDocumentOpened $opened): void { | ||
| $this->workspace->open($opened->textDocument()); | ||
| $this->provider->open(TextDocumentConverter::fromLspTextItem($opened->textDocument())); | ||
| }; | ||
| return; | ||
| } | ||
|
|
||
| if ($event instanceof TextDocumentUpdated) { | ||
| yield function (TextDocumentUpdated $updated): void { | ||
| $this->workspace->update($updated->identifier(), $updated->updatedText()); | ||
| $this->provider->open(TextDocumentBuilder::create($updated->updatedText())->uri($updated->identifier()->uri)->build()); | ||
| }; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| private function update(TextDocumentIncrementallyUpdated $event): void | ||
| { | ||
| $uri = TextDocumentUri::fromString($event->identifier()->uri); | ||
| $document = $this->workspace->get($event->identifier()->uri); | ||
|
|
||
| // convert the text edits | ||
| $content = $document->text; | ||
| $edits = array_map(function (TextDocumentContentChangeIncrementalEvent $event) use (&$content) { | ||
| $range = RangeConverter::toPhpactorRange($event->range, $content); | ||
| $edit = TextEdit::create( | ||
| $range->start(), | ||
| $range->length(), | ||
| $event->text | ||
| ); | ||
| $content = TextEdits::one($edit)->apply($content); | ||
dantleech marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return $edit; | ||
| }, $event->events()); | ||
|
|
||
| $uri = TextDocumentUri::fromString($uri); | ||
|
|
||
| $ast = $this->provider->update($uri, $edits); | ||
|
|
||
| $this->workspace->update( | ||
| $event->identifier(), | ||
| $ast->fileContents | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.