Skip to content

Fix haskell-ident-at-point uses and haskell-ident-pos-at-point behavior #603

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

Merged
merged 4 commits into from
Apr 25, 2015

Conversation

antalsz
Copy link
Contributor

@antalsz antalsz commented Apr 25, 2015

The documentation mandates that haskell-ident-at-point and haskell-ident-pos-at-point return nil if there is no identifier at point. However:

  1. Apparently, at some point haskell-ident-at-point instead returned "" in that case.
  2. Currently, haskell-ident-pos-at-point instead returns a cons cell of the form (n . n) in that case.

This pull request fixes two things:

  1. Some code assumed that haskell-ident-at-point always returned a string; these assumptions have all been fixed. (Commit f8521d9.)
  2. haskell-ident-pos-at-point now returns nil correctly, and any code relying on the old behavior was fixed. (Commit 6a3257c.)

(Fixing haskell-ident-pos-at-point indirectly fixes haskell-spanable-pos-at-point in the same way.)

This directly fixes issue #334. It also indirectly solves the problem in pull requests #601 and #602: haskell-contextual-space was comparing haskell-ident-at-point to "" instead of nil at one point.

antalsz added 2 commits April 25, 2015 03:53
The documentation mandates that `haskell-ident-at-point` return nil when
there is no identifier at point; however, apparently, it instead
returned `""` in that case at some point, and so some code made faulty
assumptions based on that.
The documentation mandates that `haskell-ident-pos-at-point` return nil
when there is no identifier at point; however, it instead returned a
cons cell of the form `(n . n)`.  This is now fixed, and any code that
relied on this behavior has been changed.

This also therefore fixes `haskell-spanable-pos-at-point` in the same
way.
@geraldus
Copy link
Contributor

Awesome! (: Great job!

@gracjan
Copy link
Contributor

gracjan commented Apr 25, 2015

Awesome!

One more thing: there is a tests/haskell-mode-tests.el that has some unit tests for haskell-ident-at-point. Can you:

  • add a test case for haskell-ident-at-point really returning nil when it should

  • add a test case for haskell-ident-pos-at-point returning non-nil

  • add a test case for haskell-ident-pos-at-point returning nil

  • add a test case for haskell-spanable-pos-at-point returning non-nil

  • add a test case for haskell-spanable-pos-at-point returning nil

    ?

@@ -312,7 +312,7 @@
(let ((ident (haskell-ident-at-point))
(tags-file-name (haskell-session-tags-filename (haskell-session)))
(tags-revert-without-query t))
(when (not (string= "" (haskell-string-trim ident)))
(when (and (stringp ident) (not (string= "" (haskell-string-trim ident))))
Copy link
Contributor

Choose a reason for hiding this comment

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

Change:

(when (and (stringp ident) (not (string= "" (haskell-string-trim ident)))

into

(when (and ident (not (string= "" (haskell-string-trim ident)))

ident should be either nil or string at this point. I would prefer it to crash if it is something else rather than silently swallow wrong type.

antalsz added 2 commits April 25, 2015 05:45
As gracjan requested in haskell#603, I

> * add[ed] a test case for haskell-ident-at-point really returning nil when it should
> * add[ed] a test case for haskell-ident-pos-at-point returning non-nil
> * add[ed] a test case for haskell-ident-pos-at-point returning nil
> * add[ed] a test case for haskell-spanable-pos-at-point returning non-nil
> * add[ed] a test case for haskell-spanable-pos-at-point returning nil

I added some somewhat detailed `nil`-checking, a couple quick tests for
`haskell-{ident,spanable}-pos-at-point` that just try the same unicode
identifiers, and then some tests to distinguish
`haskell-spanable-pos-at-point` by using an identifier in backticks.

Any test for `haskell-ident-at-point` could also be a test for the other
two, so that's a potential source of more tests; however, the
definitions of the functions in terms of `haskell-ident-pos-at-point`
are so simple that this didn't seem to add much (especially given the
sheer amount of test duplication).
`haskell-mode-jump-to-tag` will now crash if given a non-`nil`
non-string (inside `haskell-string-trim`), as gracjan requested in haskell#603.
@antalsz
Copy link
Contributor Author

antalsz commented Apr 25, 2015

@gracjan: Done with both. I could add even more tests if you felt that was important (see the commit message for c4cbd61), but I don't think testing haskell-{ident,spanable}-pos-at-point on the same input as haskell-ident-at-point is deeply valuable.

gracjan added a commit that referenced this pull request Apr 25, 2015
Fix `haskell-ident-at-point` uses and `haskell-ident-pos-at-point` behavior
@gracjan gracjan merged commit 6f2c6c7 into haskell:master Apr 25, 2015
@antalsz antalsz deleted the pr-fix-at-point branch April 25, 2015 18:09
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