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

Try js2-jump-to-definition first #10

Open
TatriX opened this issue May 26, 2017 · 8 comments
Open

Try js2-jump-to-definition first #10

TatriX opened this issue May 26, 2017 · 8 comments

Comments

@TatriX
Copy link
Contributor

TatriX commented May 26, 2017

js2-mode has a js2-jump-to-definition functions which can jump to a local definition.
Currently I'm using a bit hacky approach:

(defun my-js-jump-to-definition ()
  "Jump to a definition."
  (interactive)
  (condition-case-unless-debug nil
      (js2-jump-to-definition)
    (error
     (xref-pop-marker-stack)
     (xref-find-definitions (xref-backend-identifier-at-point (xref-find-backend))))))

The logic is simple: try jump with js2-mode ast, if it fails for whatever reason fallback to xref.
It would be cool if xref-js2 could use something like this for local jumps, because current behavior isn't quite good in my opinion.

@NicolasPetton
Copy link
Collaborator

Indeed, that'd be a good improvement!

@TatriX
Copy link
Contributor Author

TatriX commented May 30, 2017

Do you think this approach could be added to an xref-js2? If so I make a PR.

@NicolasPetton
Copy link
Collaborator

NicolasPetton commented May 30, 2017 via email

@TatriX
Copy link
Contributor Author

TatriX commented May 30, 2017

The problem is with (js2-jump-to-definition). Currently it jumps to a location.
To use it from the xref I need to get a location. Probably I can workaround it with save-excursion but I'm not sure what is the best way to implement it.

@NicolasPetton
Copy link
Collaborator

NicolasPetton commented May 30, 2017 via email

@Fuco1
Copy link

Fuco1 commented Feb 28, 2018

There's also https://github.com/jojojames/smart-jump which is used to configure these kinds of fallbacks. I think it would be better solution to use something like that instead of baking it into the package: different users might have different preferences.

As a side note, what advantage does it provide to use js2-jump-to-definition instead of just xref directly?

@TatriX
Copy link
Contributor Author

TatriX commented Feb 28, 2018

It uses js2-mode AST, so sometimes it can do a better job then grep.

@Fuco1
Copy link

Fuco1 commented Feb 28, 2018

I thought that this package also uses that to filter out noise. I personally use flow-minor-mode on many projects too so that's my "go to" choice for finding references. Which just shows that there is many possible workflows and many possible callbacks combinations.

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

No branches or pull requests

3 participants