This repository was archived by the owner on Mar 6, 2022. It is now read-only.
Repository navigation
Add helper class for finding interesting offsets. - #26
Merged
Merged
Conversation
dantleech
force-pushed
the
interesting-offset-finder
branch
from
June 23, 2019 15:51
7b43451 to
1f95fe9
Compare
Contributor
Author
|
cc @elythyr |
This helper class is intended to facilitate finding things of interest nearest to the cursor. The use case is related to context-menu functionality - if the cursor is in a position which is not interesting (e.g. whitespace) then search up the AST to find something interesting (e.g. the class declaration). The current implementation is quite dumb (but maybe clever enough) - it traverses the ancestors of the node at the given offset until one is found which is not an unknown symbol. Other implementations might query all the refactorings to find out the closest thing to which one could be applied, or a more strict rule-based implementation which could return an offset of the first ancestor with whitelisted node types.
dantleech
force-pushed
the
interesting-offset-finder
branch
from
June 23, 2019 15:53
1f95fe9 to
3104e17
Compare
dantleech
commented
Jun 23, 2019
|
|
||
| $symbolType = $reflectionOffset->symbolContext()->symbol()->symbolType(); | ||
|
|
||
| if ($symbolType != Symbol::UNKNOWN) { |
Contributor
Author
There was a problem hiding this comment.
could use strict operator here and inline the expression
dantleech
commented
Jun 23, 2019
| $symbolType = $reflectionOffset->symbolContext()->symbol()->symbolType(); | ||
|
|
||
| if ($symbolType != Symbol::UNKNOWN) { | ||
| return ByteOffset::fromInt($reflectionOffset->symbolContext()->symbol()->position()->start()); |
Contributor
Author
There was a problem hiding this comment.
could save some chaining and use the $node->getStart() offset
Contributor
|
Hi, I think we should merge this in order to be able to merge phpactor/phpactor#784 as well. |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This helper class is intended to facilitate finding things of interest
nearest to the cursor. The use case is related to context-menu
functionality - if the cursor is in a position which is not interesting
(e.g. whitespace) then search up the AST to find something interesting
(e.g. the class declaration).
The current implementation is quite dumb (but maybe clever enough) - it
traverses the ancestors of the node at the given offset until one is
found which is not an unknown symbol.
Other implementations might query all the refactorings to find out the
closest thing to which one could be applied, or a more strict rule-based
implementation which could return an offset of the first ancestor with
whitelisted node types.