Skip to content
This repository was archived by the owner on Mar 6, 2022. It is now read-only.

Add helper class for finding interesting offsets. - #26

Merged
dantleech merged 2 commits into
masterfrom
interesting-offset-finder
Oct 13, 2019
Merged

dantleech merged 2 commits into
masterfrom
interesting-offset-finder

Conversation

@dantleech

Copy link
Copy Markdown
Contributor

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
dantleech force-pushed the interesting-offset-finder branch from 7b43451 to 1f95fe9 Compare June 23, 2019 15:51
@dantleech

Copy link
Copy Markdown
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
dantleech force-pushed the interesting-offset-finder branch from 1f95fe9 to 3104e17 Compare June 23, 2019 15:53

$symbolType = $reflectionOffset->symbolContext()->symbol()->symbolType();

if ($symbolType != Symbol::UNKNOWN) {

@dantleech dantleech Jun 23, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could use strict operator here and inline the expression

$symbolType = $reflectionOffset->symbolContext()->symbol()->symbolType();

if ($symbolType != Symbol::UNKNOWN) {
return ByteOffset::fromInt($reflectionOffset->symbolContext()->symbol()->position()->start());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could save some chaining and use the $node->getStart() offset

@camilledejoye

Copy link
Copy Markdown
Contributor

Hi,

I think we should merge this in order to be able to merge phpactor/phpactor#784 as well.

@dantleech
dantleech merged commit 0cf4f20 into master Oct 13, 2019
@dantleech
dantleech deleted the interesting-offset-finder branch October 13, 2019 14:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants