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

Improvements for REPL output pre-processing and locref navigation #2083

Merged
merged 9 commits into from Sep 5, 2017

Conversation

vspinu
Copy link
Contributor

@vspinu vspinu commented Aug 28, 2017

Improving on #2043 a bit for navigation. Pass through file metatdata when available from location references and no info from var names could be retrieved. cider-find-file does a good job in those cases.

cider-repl.el Outdated
(or (cider-sync-request:ns-path var)
(nrepl-dict-get (cider-sync-request:info var) "file"))
(plist-get loc :file))))
(file (or (when var
Copy link
Member

Choose a reason for hiding this comment

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

Who does this improve the code? Seems exactly the same to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference is that now :file metadata is picked up when first two resolutions fail (those within or). This happens when a var is a protocol method. This was also the original intention btw.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see your point now - var might be present, but its branch might return nil. Add some comments as it's somewhat hard to follow the what the assumptions here otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I used "var" loosely to refer to the variable at point, which need not correspond to clojure's var. Will add a couple of notes.

cider-repl.el Outdated
@@ -561,7 +561,7 @@ When there is a possible unfinished ansi control sequence,
(buffer-local-value 'cider-repl--ns-forms-plist connection)
ns)))))

(defvar cider-repl--root-ns-highlight-template "\\<\\(%s\\)[^$/: \t\n]+"
(defvar cider-repl--root-ns-highlight-template "\\<\\(%s\\)[^$/: \t\n()]+"
Copy link
Member

Choose a reason for hiding this comment

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

What's the purpose of this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improve original regexp. Currently things like ns1.foo.bar(file.clj:123) are highlighted all the way to 123. This change stops them at (.

Originally I thought all those reference have $ in their name, but that's not always the case.

cider-repl.el Outdated
@@ -1051,7 +1051,7 @@ regexes from `cider-locref-regexp-alist' to infer locations at point."
(nrepl-dict-get (cider-sync-request:info var) "file")))
(plist-get loc :file))))
(if file
(cider--jump-to-loc-from-info (nrepl-dict "file" file "line" line))
(cider--jump-to-loc-from-info (nrepl-dict "file" file "line" line) t)
Copy link
Member

Choose a reason for hiding this comment

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

I think it's subjective whether this is better or worse - in such cases I always add a defcustom.

P.S. Mind the commit message style. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not subjective. These pseudo links now behave like links in cider stacktrace buffer. Also like links in every other buffer which has a bunch of links in it (occur, grep, compilation etc) behave like that. It's common to click on multiple error references till you get what you want.

Mind the commit message style. 😃

What do you mean more concretely?

Copy link
Member

@xiongtx xiongtx Aug 29, 2017

Choose a reason for hiding this comment

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

What do you mean more concretely?

Follow this guide.

When clicked on locref in REPL, jump to other window.

doesn't adhere to #4 or #5.

Copy link
Contributor Author

@vspinu vspinu Aug 29, 2017

Choose a reason for hiding this comment

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

Ohh, dot at the end of the message. Fixing that :) The subject line is already in imperative mood.

Copy link
Member

Choose a reason for hiding this comment

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

The subject line is already in imperative mood.

I'm not a stickler for this stuff, but no, it's not.

Jump to other window when clicking on locref in REPL

would be.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed. The commit messages should ideally always start with a verb.

CHANGELOG.md Outdated
@@ -8,6 +8,7 @@

### Bugs Fixed

* Improve file retrieval when jumping to REPLs location references and Clojure vars cannot be resolved.
Copy link
Member

@bbatsov bbatsov Aug 30, 2017

Choose a reason for hiding this comment

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

How come you can just to something that's not resolved? I guess you made some mistake in the description here. Or this just for the scope of the REPL defs. Frankly I don't remember much this code and I don't have time to dive into it, but I still have to understand what exactly is this supposed to fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That code is recent. I added it in #2043 and now I am just improving on it.

I just said what I did there - when locrefs cannot be referenced from variables at point, use file metadata from the locrefs themselves. I can state it more generically "Improve locations lookup by using file metadata when available". Not accurate but conveys the improvement.

AFAIC, this need not be documented at all as being a small and technical fix on a recent change, but knowing how zealous you are on change-logs I added it.

@vspinu vspinu force-pushed the locref-file-fix branch 2 times, most recently from d7ab529 to 052d90b Compare August 30, 2017 19:44
@vspinu vspinu force-pushed the locref-file-fix branch 2 times, most recently from fc22b8d to 74fee61 Compare August 30, 2017 20:16
@vspinu
Copy link
Contributor Author

vspinu commented Aug 30, 2017

I am piling a bunch of related changes and improvements here. With a bit more doc this time, so should be self explanatory.

Also fixing failing tests to account for recent buttercup changes.

Two notable new features:

  • cider-preoutput-hook which implements a customizable pipeline of output pre-processing and includes most of our output pre-processing as "middleware".
  • cider-repl-highlight-spec-keywords pre-output processor which highlights clojure.spec "explain" keywords. Clojure spec explain output is extremely difficult to read.. Make it a bit easy by showing this:

spec-asert2

instead of

spec-asert1

@xiongtx
Copy link
Member

xiongtx commented Aug 30, 2017

I am piling a bunch of related changes and improvements here.

It'd be better to open more PRs. A bunch of unrelated changes in a single PR is hard to review.

@vspinu vspinu changed the title Rely on cider-find-file when locref of vars cannot be resolved Improvements for REPL output pre-processing and locref navigation Aug 30, 2017
 - Disallow highlight spilling over () as in ns.foo.bar(file.clj:123)).

 - Start matching at the beginning of the symbol, not word. Particularly inhibit
   matching of namespaced keywords (which could be many).
@vspinu vspinu force-pushed the locref-file-fix branch 2 times, most recently from 6437a59 to 8d59067 Compare August 30, 2017 22:15
This allows for customization of the modification of the REPL output before it
is inserted into the buffer.

New functions to be used as part of this hook:

  - cider-repl-add-locref-help-echo
  - cider-repl-highlight-current-project
@bbatsov bbatsov merged commit 7a72259 into clojure-emacs:master Sep 5, 2017
@vspinu vspinu deleted the locref-file-fix branch June 20, 2018 10:38
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.

None yet

3 participants