Skip to content
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

Handle schemes other than the file scheme #1620

Merged
merged 42 commits into from
May 29, 2021
Merged

Handle schemes other than the file scheme #1620

merged 42 commits into from
May 29, 2021

Conversation

rwols
Copy link
Member

@rwols rwols commented Mar 21, 2021

This is a draft where I'm updating the code to handle schemes other than file.

Points of concern:

  • goto def should handle arbitrary URIs
  • goto references should handle arbitrary URIs
  • restore output panel functionality of goto references
  • what about workspace symbols?
  • if a view is already open with the given URI, switch to that view
    instead of opening a new view.
    in another PR
  • arbitrary URI schemes are handled through AbstractPlugin.on_open_uri_async
  • related infos for diagnostics should work
  • SessionBuffer (or maybe DocumentSyncListener) should be aware of what
    its URI is. It currently only knows its filename. Most likely, this will
    result in us also being able to handle buffer-only views.
    in another PR
  • jump back history

This is a draft where I'm updating the code to handle schemes other than `file`.

Points of concern:

- [x] goto def should handle arbitrary URIs
- [x] goto references should handle arbitrary URIs
- [ ] restore output panel functionalit of goto references (or not?)
- [ ] what about workspace symbols?
- [ ] if a view is already open with the given URI, switch to that view
      instead of opening a new view.
- [x] arbitrary URI schemes are handled through AbstractPlugin.on_open_uri_async
- [ ] SessionBuffer (or maybe DocumentSyncListener) should be aware of what
      its URI is. It currently only knows its filename. Most likely, this will
      result in us also being able to handle buffer-only views.
@rwols
Copy link
Member Author

rwols commented Mar 21, 2021

So, textDocument/references understands arbitrary URIs now as well:

Schermopname.2021-03-21.om.22.12.51.mov

And if an URI is not a file:// URI it goes through the AbstractPlugin extension point.

@rwols
Copy link
Member Author

rwols commented Mar 21, 2021

plugin/core/sessions.py Outdated Show resolved Hide resolved
plugin/core/views.py Show resolved Hide resolved
@rwols
Copy link
Member Author

rwols commented May 6, 2021

Because on some places we use weak refs, on some places we don't and I cannot figure out when is expected to use weak refs, or when there is no need for them.

I'll write a wiki page about it if I can find the time. But basically, just never hold on to a session object. A sublime_plugin.TextCommand is instantiated once per view, and then kept alive for the duration of the view. Therefore, if you stash something in such a command via self.foo = bar, then the command will keep a reference to bar as long as the view lives.

You can test this by printing something in __init__ and __del__ of a text command.

@rwols rwols marked this pull request as ready for review May 8, 2021 10:06
@predragnikolic
Copy link
Member

I find the reference panel more useful than showing references in the quick panel.

Screenshot 2021-05-08 at 15 37 52

Pros of the reference panel:

  • Shows the symbol we are finding reference for
  • The count of references
  • A preview of each line
  • If you want to go to a reference you click it, or press a keybinding

Cons of the reference panel:

  • could not handle custom URIs

Screenshot 2021-05-08 at 15 36 43

Pros of the quick panel:

  • Can handle custom URIs.

Cons of the quick panel:

  • Doesn't shows the symbol we are finding reference for
  • Doesn't shows the count of references
  • While it doesn't shows a preview of each line in quick panel, if we press UP/DOWN arrows it will take us to that line, where we could see he line, unless the reference is at the top of the file... than the quick panel will cover it, so we won't be able to see it

For me the pros and cons of the reference panel are better that
the pros and cons of the quick panel.

Suggestion:
Show the references in the panel, and don't rely on ST result_file_regex, result_line_regex that are required for the next_result prev_result to work.
Instead add custom commands for navigation lsp_next_result, lsp_prev_result that would allow handling of custom URIs.


Also I noticed that the "show_references_in_quick_panel" was removed 9adb815 ,
but there is still one place in the code where that setting is just read:
https://github.com/sublimelsp/LSP/blob/st4000-exploration/plugin/core/types.py#L171
https://github.com/sublimelsp/LSP/blob/st4000-exploration/plugin/core/types.py#L203

@rwols
Copy link
Member Author

rwols commented May 9, 2021

Instead add custom commands for navigation lsp_next_result, lsp_prev_result that would allow handling of custom URIs.

This would still not allow clicking on the URI. As for the disadvantages of the quick panel:

Doesn't shows the symbol we are finding reference for

I guess it's possible to make use of the targetSelectionRange for LocationLinks and range for Locations.

Doesn't shows the count of references

Is that really important information?

While it doesn't shows a preview of each line in quick panel, if we press UP/DOWN arrows it will take us to that line, where we could see he line, unless the reference is at the top of the file... than the quick panel will cover it, so we won't be able to see it

The built-in Goto References also has this problem. I've been running with this branch for about a month now and it's honestly not that big of a problem.

Is it okay to at least roll with this for a while and see how we can improve it further? Given that panels don't understand URIs, I don't think panels have any future. That's really the bigger issue.

@rchl
Copy link
Member

rchl commented May 9, 2021

Given that panels don't understand URIs

I currently don't have opinion on the panel vs. quick panel but I don't think that that statement is true. A custom panel together with a custom mouse binding that triggers a custom command that parses the clicked text should be possible.

@predragnikolic
Copy link
Member

predragnikolic commented May 10, 2021

Is that really important information?

Not really.

I see that you put a lot of effort in this PR,
I also consider this a breaking change(for me) usability vise. The reference feature changed for me drastically, and I find the previous version(ref. panel) to work better for me that the newly introduced one (quick panel).

The main issue for me is the complete removal of the reference panel,
do you consider bringing back the show_references_in_quick_panel and letting the user decide what he wants?

@rwols
Copy link
Member Author

rwols commented May 10, 2021

It’s too much work/maintenance for me to maintain two very different presentations of the same information. So let’s go with the panel solution then and see if we can make it work.

@rchl
Copy link
Member

rchl commented May 12, 2021

The quick panel has the major advantage (IMO) that it's more keyboard-friendly. I can trigger Find references from the command palette, then filter results and go to a specific one I want. With the panel I have to go through all results with F4 which a) can open many files unnecessarily b) can take longer to find the right one if there are many results.

@rwols rwols changed the base branch from st4000-exploration to main May 21, 2021 16:58
@rwols rwols requested a review from predragnikolic May 27, 2021 19:39
predragnikolic
predragnikolic previously approved these changes May 27, 2021
Copy link
Member

@predragnikolic predragnikolic left a comment

Choose a reason for hiding this comment

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

Thanks for keeping the reference panel! :)

@rwols rwols merged commit cc8441d into main May 29, 2021
@rwols rwols deleted the feat/uri-handler branch May 29, 2021 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants