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

Define default directory for haskell-stack-ghc checker #1007

Merged
merged 4 commits into from Jul 12, 2016
Merged

Define default directory for haskell-stack-ghc checker #1007

merged 4 commits into from Jul 12, 2016

Conversation

@sergv
Copy link
Contributor

@sergv sergv commented Jul 9, 2016

Default directory is detected either by looking for stack.yaml or asking stack path --project-root for haskel-stack-ghc checker or by looking for cabal file in case of haskell-ghc checker.

@mrkkrp Please comment, if you think something should be done differently.

@@ -6976,6 +6976,36 @@ Otherwise return the previously used cache directory."
(or flycheck-haskell-ghc-cache-directory
(make-temp-file "flycheck-haskell-ghc-cache" 'directory))))

(defun flycheck-haskell--default-directory (checker)
"Come up with a sutable default directory for Haskell to run checker in."

This comment has been minimized.

@lunaryorn

lunaryorn Jul 10, 2016
Contributor

Come up sounds strange. Why not simply "find"?

Please also extend the docstring to explain what a "suitable" directory would be, i.e. document the behaviour of the function as well.

(replace-regexp-in-string
(rx (* (any " \t\n")) eos)
""
(shell-command-to-string "stack path --project-root"))))

This comment has been minimized.

@lunaryorn

lunaryorn Jul 10, 2016
Contributor

Please use process-lines instead of shell-command-to-string. We should not use shell commands without need.

(when (executable-find "stack")
(let ((stack-dir
(replace-regexp-in-string
(rx (* (any " \t\n")) eos)

This comment has been minimized.

@lunaryorn

lunaryorn Jul 10, 2016
Contributor

Why's this? Please add a comment explaining the reason for this substitution.

@lunaryorn
Copy link
Contributor

@lunaryorn lunaryorn commented Jul 10, 2016

Thanks. I've done a cursory review, will look at the details tomorrow.

@lunaryorn
Copy link
Contributor

@lunaryorn lunaryorn commented Jul 10, 2016

@flycheck/haskell @purcell Would you also take a look? Maybe also test this PR on different Haskell projects?

@sergv
Copy link
Contributor Author

@sergv sergv commented Jul 10, 2016

@lunaryorn I've amended commit with your suggestions.

@mrkkrp
Copy link
Contributor

@mrkkrp mrkkrp commented Jul 10, 2016

@sergv, Looks good, thank you for writing this! I'm looking forward to using it.

@purcell
Copy link
Contributor

@purcell purcell commented Jul 11, 2016

LGTM. I tried this patch on top of flycheck HEAD with a fairly vanilla stack project and all was well, so I'm pretty confident this will work.

@@ -6976,6 +6976,45 @@ Otherwise return the previously used cache directory."
(or flycheck-haskell-ghc-cache-directory
(make-temp-file "flycheck-haskell-ghc-cache" 'directory))))

(defun flycheck-haskell--find-default-directory (checker)
"Come up with a sutable default directory for Haskell to run

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

sutablesuitable

In case of `haskell-stack-ghc' checker it is directory with
stack.yaml file. If there's no stack.yaml file in any parent
directory, it will be the directory that \"stack path --project-root\"
command returs.

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

retursreturns

This comment has been minimized.

@purcell

purcell Jul 11, 2016
Contributor

Yep. And this docstring wouldn't pass checkdoc, so it needs a little work.

command returs.

For all other checkers, it is the closest parent directory that
contains cabal file."

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

"a cabal file" (maybe :)

(lambda (dir)
(not
(null
(directory-files dir

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

I think (not (null x)) is the same as x in this case

This comment has been minimized.

@sergv

sergv Jul 11, 2016
Author Contributor

That's true, but I tried to express the idea that we're only interested in whether the returned list is non-empty and not the list itself

This comment has been minimized.

@lunaryorn

lunaryorn Jul 11, 2016
Contributor

@sergv It's fine to just return the list in this case. The double negation doesn't really add anything imho.

".+\\.cabal\\'"
t ;; nosort
)))))))))

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

Do we really need this double implementation? Nothing in the docstring mention using haskell mode to find the cabal file; could we just use locate-dominating-file? Or is there a benefit to haskell-cabal-find-file? (If so, what happens if it returns null? Should we fall back to locate-dominating-file?)

This comment has been minimized.

@purcell

purcell Jul 11, 2016
Contributor

I think haskell-cabal-find-file doesn't add much beyond stopping upwards traversal if file/directory ownership changes. Which sounds questionable to me anyway. Probably best to avoid referring to anything in haskell-mode here IMO.

(null
(directory-files dir
nil ;; full
".+\\.cabal\\'"

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

I don't think you need the + in that regexp. (Btw, can a cabal file be called just .cabal?)

This comment has been minimized.

@purcell

purcell Jul 11, 2016
Contributor

haskell-mode uses (directory-files dir t ".\\.cabal\\'"), so it admits a.cabal, but not .cabal.

(let ((cabal-file (haskell-cabal-find-file)))
(when cabal-file
(file-name-directory cabal-file)))
(locate-dominating-file (file-name-directory (buffer-file-name))

This comment has been minimized.

@cpitclaudel

cpitclaudel Jul 11, 2016
Member

Maybe we could rewrap this to make the lambda more readable? (by adding a newline before (file-name...

@cpitclaudel
Copy link
Member

@cpitclaudel cpitclaudel commented Jul 11, 2016

I've added quick review notes as well. Thanks for this PR!

@cpitclaudel
Copy link
Member

@cpitclaudel cpitclaudel commented Jul 11, 2016

@purcell Thanks for the review-of-the-review :))

@sergv
Copy link
Contributor Author

@sergv sergv commented Jul 11, 2016

@cpitclaudel I've rebased on master and added commit that fixes review notes

(process-lines "stack" "path" "--project-root"))
(stack-dir
(when stack-output
(car stack-output))))

This comment has been minimized.

@lunaryorn

lunaryorn Jul 11, 2016
Contributor

@sergv The when guard is redundant. (car nil) is perfectly safe and evaluates to nil so it's perfectly safe to just do (car (process-lines …)).

@lunaryorn
Copy link
Contributor

@lunaryorn lunaryorn commented Jul 11, 2016

@sergv Would you add a note about this change to CHANGES.rst? I think it falls under Improvements: 😊

@lunaryorn
Copy link
Contributor

@lunaryorn lunaryorn commented Jul 12, 2016

LGTM. Thanks for the change 😊

I think though that #1012 should go in first.

@sergv sergv merged commit fa035f0 into flycheck:master Jul 12, 2016
2 checks passed
2 checks passed
approvals/lgtm this commit looks good
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sergv sergv deleted the sergv:stack-ghc-checker-default-directory branch Jul 12, 2016
lunaryorn added a commit that referenced this pull request Jul 12, 2016
@lunaryorn
Copy link
Contributor

@lunaryorn lunaryorn commented Jul 12, 2016

@sergv I think you forgot to rename :default-directory to :working-directory here before merging this PR. I fixed it in ceaf8c4. Could take another look?

@sergv
Copy link
Contributor Author

@sergv sergv commented Jul 12, 2016

@lunaryorn Indeed, I missed it. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants