Skip to content

Context menu: Unknown symbol (or whitespace) should assume parent context. #777

Closed

Description

@dantleech

e.g. if invoking context menu on whitespace in between class members, assume the context is "class".

Activity

  1. camilledejoye commented on Jun 15, 2019

    @camilledejoye
    Contributor

    So I wanted to gave it a try.
    I managed to get the ContextMenuHandler to look for a parent if there is no available symbol under the cursor.
    It appears to work nicely, if you are on a valid symbol it's used. Otherwise we look the parent and if it's a valid symbol it's used, and again until there is no parent left.

    The problem is that when I open the context menu for the class but with the cursor on a blank line and I ask to find the references then we got an error because the handler for the reference finder will receive the offset of the cursor, not the class.

    What I would like to do is to provide the "new offset" to the actionSelectionAction method instead of forwarding the one in the arguments.
    So that the action will received the right offset.
    But I can't manage to find a reliable way to retrieve an Offset from a RelfectionOffset.
    All we got is a Position but it doesn't seem reliable to take the start position as offset, neither as the end.

    Do I miss something about Position and Offset ?

  2. dantleech commented on Jun 16, 2019

    @dantleech
    CollaboratorAuthor

    Haven't got access to computer at the moment, but using the class start position should be fine. Why is of unreliable?

  3. camilledejoye commented on Jun 17, 2019

    @camilledejoye
    Contributor

    For know it seems to work.

    But in a previous version of the generate accessor PR, I was using the reflection to find a property by it's name (in the handler) and then provide the start position as the offset of the property to generate it's accessor.
    If I'm not mistaken, then visibility is the start position but if you try to reflection from the offset of the visibility you end up with an unknown symbol.

    For this PR it doesn't seem to be a problem, it works for class and methods.
    I just wanted to get your opinion on how to pass from a Position to an Offset because it's unclear to me at the time.

  4. dantleech commented on Jun 18, 2019

    @dantleech
    CollaboratorAuthor

    hmm, Position offers both startPosition and fullStartPosition. The fullStartPosition includes any leading whitespace and comments. startPosition should always work (that should be the start of the class keyword I think).

  5. camilledejoye commented on Jun 18, 2019

    @camilledejoye
    Contributor

    By memory the start of

    private $property;

    Is on the first p of the line, the visibility.
    If you put your cursor on a property visibility and class phpactor#Hover() your will have a <unknown> <unknown> as a response.
    Which is kind of strange because if you do it on a method visibility, it works.

  6. dantleech commented on Jun 18, 2019

    @dantleech
    CollaboratorAuthor

    hm, sounds like an unrelated bug maybe? Probably WorseReflection related?

  7. dantleech commented on Feb 29, 2020

    @dantleech
    CollaboratorAuthor

    Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions