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

Initial attempts to add more haskell rules #180

Merged
merged 6 commits into from
Dec 13, 2017

Conversation

volhovm
Copy link
Contributor

@volhovm volhovm commented Dec 2, 2017

Alright, so I want to extend haskell support a little bit at least. This PR is currently WIP, because there are things I'm stuck with and I'd like somebody to help me (maybe). The main one is: does ag support multiline matching? I see a proof (here ggreer/the_silver_searcher#682) that it does, but for some reasons my tests show otherwise.

@coveralls
Copy link

coveralls commented Dec 2, 2017

Coverage Status

Coverage remained the same at 97.314% when pulling 4a22321 on volhovm:master into c4b3e4b on jacktasia:master.

@jacktasia
Copy link
Owner

Thanks for the PR! To answer your question: my understanding is ag does have multiline support. Can you expand on your tests that show otherwise? I think #102 was the last time this came up so @netromdk may know more than me.

Thanks again!

@netromdk
Copy link
Contributor

netromdk commented Dec 3, 2017

Yes, ag supports multiline matching. When I run your query on CLI then it works fine:

% ag "data.*{((.|\\s)*?::(.|\\s)*?,)*\\s*(test)\\b\\s*::(.|\\s)*}" test/test.hs
1:data Mem = Mem { mda :: A
2: , test :: Kek
3:  ,
4: aoeu :: E }

I put data Mem = Mem { mda :: A\n , test :: Kek\n ,\n aoeu :: E } in the file.

It fails through the :tests( .. ), though:

TEST: ’data Mem = Mem { mda :: A
 , test :: Kek
  ,
 aoeu :: E }’
INPUT: ’data Mem = Mem { mda :: A
 , test :: Kek
  ,
 aoeu :: E }’
CMD: ’ag --nocolor --nogroup data.\*\{\(\(.\|\\s\)\*\?\:\:\(.\|\\s\)\*\?\,\)\*\\s\*\(test\)\\b\\s\*\:\:\(.\|\\s\)\*\}’
RESP: ’’

@volhovm
Copy link
Contributor Author

volhovm commented Dec 3, 2017

Alright, so as far as I've managed to figure out: ag doesn't support multiline when input is coming from stdin, so it has nothing to do with dumb-jump itself. IDK if it's possible to fix. Maybe we can change ag tests so they read things from the file directly (somehow, i'm not an elisp expert)?

@netromdk
Copy link
Contributor

netromdk commented Dec 3, 2017

I actually did the same thing for git-grep: dumb-jump-run-git-grep-test. Maybe it could just be renamed to something like dumb-jump-run-test-from-file and be used inside dumb-jump-test-ag-rules. But then the temp file should be named something more general, of course. But I haven't tested it for ag in this multiline situation.

@netromdk
Copy link
Contributor

netromdk commented Dec 4, 2017

Okay, if you do the following then it all works:

@@ -1212,9 +1212,9 @@ Optionally pass t for RUN-NOT-TESTS to see a list of all failed rules"
       (lambda (rule)
         (-mapcat
           (lambda (test)
-            (let* ((cmd (concat "ag --nocolor --nogroup "
+            (let* ((cmd (concat "ag --nocolor --nogroup --nonumber "
                                 (shell-quote-argument (dumb-jump-populate-regex (plist-get rule :regex) "test" 'ag))))
-                   (resp (dumb-jump-run-test test cmd)))
+                   (resp (dumb-jump-run-git-grep-test test cmd)))
               (when (or
                      (and (not run-not-tests) (not (s-contains? test resp)))
                      (and run-not-tests (> (length resp) 0)))

Except, of course, that dumb-jump-run-git-grep-test should be renamed as we talked about.

The deal was that while running this test it cannot show the line numbers, like:

1:data Mem = Mem { mda :: A
2: , test :: Kek
3:  ,
4: aoeu :: E }

That's why it needs --nonumber only for running the tests.

Edit: And it only starts showing line numbers when matching multiline input from stdin.

@volhovm
Copy link
Contributor Author

volhovm commented Dec 4, 2017

Thank you, @netromdk. This is very helpful and I'll adopt it soon. I don't have a lot of time these days (was unsuccessfully testing my changes today) but I hope to finish this PR soon :)

@volhovm
Copy link
Contributor Author

volhovm commented Dec 7, 2017

So I figured out I had a configuration mistake: my dumb-jump-force-searcher was set to auto which defaulted to git grep (though it wasn't obvious at all, i thought ag is preferred since it's more powerful).
I've solved the tests problem (yay, thanks everybody) and I will work on refining regexps themselves a little bit more.

@coveralls
Copy link

coveralls commented Dec 7, 2017

Coverage Status

Coverage increased (+0.008%) to 97.323% when pulling 91b6a3e on volhovm:master into c4b3e4b on jacktasia:master.

dumb-jump.el Outdated
@@ -1168,21 +1166,31 @@ If `nil` always show list of more than 1 match."
"Use TEST as the standard input for the CMD."
(with-temp-buffer
(insert test)
(shell-command-on-region (point-min) (point-max) cmd nil t)
(shell-command-on-region (point-min) (point-max) cmd (current-buffer) t)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it necessary to use (current-buffer)? I can see in the doc on shell-command-on-region that:

If the value is nil, use the buffer ‘Shell Command Output’.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, right!

@netromdk
Copy link
Contributor

netromdk commented Dec 7, 2017

Looks great! :)

@volhovm
Copy link
Contributor Author

volhovm commented Dec 7, 2017

@netromdk is there any way i can match on something different from JJJ? Haskell types start with a capital letter, so Command rule should be different from command. I don't want some rules to fire up if substituted JJJ doesn't follow the internal predicate itself.

(i guess it's not possible, but asking anyway)

@netromdk
Copy link
Contributor

netromdk commented Dec 7, 2017

Well, "JJJ" is just substituted the search term but it's up to the regexp to worry about case sensitivity. ag uses smart case by default, for instance:

  -S --smart-case         Match case insensitively unless PATTERN contains
                          uppercase characters (Enabled by default)

I think most rules kind of assume case-insensitivity. But at least for ag it should match correctly given "Command" or "command" in your case, but that's only when the regexp contains either "Command" or "command" because otherwise it would just substitute in the search term which doesn't directly affect the rule around it's case-matching mode.

Off the top of my head; If we wanted to support this then the rule itself would have to be annotated with a case-matching mode, "like starts with capital letter", which is matched against the value substituting in for "JJJ". This annotation could actually be a regexp in itself to weed out which search terms are even tried with the rule.

Food for thought.

What do you think about that, @jacktasia btw?

@volhovm
Copy link
Contributor Author

volhovm commented Dec 7, 2017

I'm a little bit stuck. I have a set of rules. Pattern a is matched by regex/rule A. I add another rule B (which is not related to A) and a is not matched by anything anymore. b is also not matched by B (but when the exact same string appears in tests, it is).

Any ideas what it can be? Maybe there's some magic about the way rules are matched? It seems that adding extra rule (which perfectly works on tests i provide) ruins everything.

@netromdk
Copy link
Contributor

netromdk commented Dec 7, 2017

That sounds weird, @volhovm. Do you mean it doesn't work with the inline rules but it works when you "jump" inside Emacs? And could you give an example of what's not working in code/examples.

@coveralls
Copy link

coveralls commented Dec 13, 2017

Coverage Status

Changes Unknown when pulling ccb69df on volhovm:master into ** on jacktasia:master**.

@coveralls
Copy link

coveralls commented Dec 13, 2017

Coverage Status

Changes Unknown when pulling ccb69df on volhovm:master into ** on jacktasia:master**.

@volhovm
Copy link
Contributor Author

volhovm commented Dec 13, 2017

I think I'm actually done with this PR. Rules cover 99% of things i want, they work fast. I don't see any obvious problems.

@coveralls
Copy link

coveralls commented Dec 13, 2017

Coverage Status

Changes Unknown when pulling 66cead4 on volhovm:master into ** on jacktasia:master**.

Copy link
Contributor

@netromdk netromdk left a comment

Choose a reason for hiding this comment

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

Looks good. I'm looking forward to using your rules on my own Haskell programs!

dumb-jump.el Outdated
@@ -699,7 +699,7 @@ or most optimal searcher."
:tests ("newtype Test a = Something { b :: Kek }"
"data Test a b = Somecase a | Othercase b"
"type family Test (x :: *) (xs :: [*]) :: Nat where"
"data family Test"
"data family Test "
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this space on purpose?

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 believe that every identifier should be followed by a space or eof. \b doesn't work because in haskell we have a lot of things like Identifier and Identifier', so matching first will match second also.

@jacktasia
Copy link
Owner

@volhovm Thanks for all the work on this. I'll be merging it as soon as I get back to a computer. @netromdk Thanks so much for reviewing and helping on this and everything else you've done for dumb jump

@netromdk
Copy link
Contributor

Oh, it's no problem. You're welcome :)

@jacktasia jacktasia merged commit a289063 into jacktasia:master Dec 13, 2017
@jacktasia
Copy link
Owner

Thanks again!

dleslie pushed a commit to dleslie/dumb-jump that referenced this pull request Dec 14, 2017
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.

4 participants