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

Add current working directory [:default-directory] property #973

Merged
merged 16 commits into from Jul 7, 2016

Conversation

Projects
None yet
4 participants
@sergv
Contributor

sergv commented May 17, 2016

Hi, this is a followup to #813. I cannot add new commits to that pull request so I'm creating a new one.

Since original pull request was stalled for quite some time with several unresolved review comments I decided to jump in and resolve any mentioned issues. This feature is pretty essential for Haskell checking, in my opinion.

Stylistic issues were resolved and, I hope, no new were introduced.

The problem with flycheck-fill-and-expand-error-file-names not having access to current working directory was fixed as well. The issue was critical for checkers that can report relative file names in their errors, but it didn't affect checkers that report absolute file names. So it was not as critical as last comment of #813 suggests, but it's fixed now anyway.

To fix it, I added default-directory field to flycheck-syntax-check structure and moved binding of default-directory variable out of flycheck-start-command-checker function into the flycheck-syntax-check-start function. This indirection obscures things a bit but allows to calculate default directory only once per cherker run. Since computing default directory may involve costly traversals of filesystem, it seems worth some additional obscurity.

I regret not adding any new test cases, but it seems to require some non-trivial effort - the core repository seems to contain only, well, core tests and no tests for specific checkers.

Edit (@lunaryorn): Dear Waffle, this connects to #312.

@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented May 18, 2016

@sergv Wow, thanks for taking up 👍 Really awesome work; at a cursory look I really like how you did things here. Also, many many thinks for fixing all those stylistic issues I left behind ☺️

I'll review and test this PR soon, but please be patient. I'm a little short of time this week, and likely won't get to review this PR until next week.

@sergv

This comment has been minimized.

Contributor

sergv commented May 22, 2016

I feel uneasy for hijacking this pull request with fix for #978, but the fix is slightly dependent on changes that introduced cwd argument in the flycheck-fix-error-filename function.

@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented May 23, 2016

@sergv Please remove that change from this PR. It's unrelated, and while I'm all in favour of a default-directory, I'm not convinced that replacing file names in error messages is a good idea.

Please let's discuss this separately, even if this means that the fix for #978 will be delayed until after this PR is merged.

@sergv

This comment has been minimized.

Contributor

sergv commented May 23, 2016

Okay, I removed the fix for #978 from here, it can wait until this PR is merged.

(list (flycheck-ert-resource-filename "foo")
absolute-fn
absolute-fn

This comment has been minimized.

@lunaryorn

lunaryorn Jun 2, 2016

Contributor

This looks like a spurious whitespace change?

This comment has been minimized.

@sergv

sergv Jun 2, 2016

Contributor

Good catch but actually it isn't a whitespace change - the inline list gets compared against errors list, which has 4 entries now.

This comment has been minimized.

@lunaryorn

lunaryorn Jun 3, 2016

Contributor

Oh dear, I should have taken a better look. Sorry for the noise 😊

flycheck.el Outdated
not a relative one."
(let* ((cwd (flycheck-checker-get checker 'default-directory))
(default-directory (or (and (functionp cwd) (funcall cwd))
(and (stringp cwd) (file-truename cwd))

This comment has been minimized.

@lunaryorn

lunaryorn Jun 5, 2016

Contributor

I don't think that this feature has any use. Why would you ever want to give a constant string?

I think we can safely remove this part.

@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented Jun 5, 2016

@sergv Can you please also remove b281f2c from this PR? While it's a good intention it clutters the diff and makes it harder to review the important parts of this PR.


I've taken some time to think about the general structure of this PR, and I think that it makes the default directory too, well, "global".

I don't think that it should be a property of generic syntax checkers—it only makes sense for command syntax checkers in my opinion. Hence I don't think it should be part of the syntax check structure as well.

Instead, I'd prefer if default-directory was only part of flycheck-define-command-checker, and stored in the process object returned by this function. I think it'd be easy enough to attach the working directory with (process-put process 'flycheck-default-directory default-directory), and later use process-get to extract it.

Could you try to refactor the PR accordingly?

@sergv

This comment has been minimized.

Contributor

sergv commented Jun 5, 2016

@lunaryorn I was under the impression that unresolved stylistic problems of #813 were, at least in part, blocking the review of the PR. I can remove the fixes and move them to another PR or I can move the commit to be the last commit, so you'll be able to review meaningful part at the beginning without clutter. Which way would be the best?

I'll try refactoring PR and move default-directory into flycheck-define-command-checker soon.

@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented Jun 5, 2016

@sergv Sure, but there are many stylistics changes in this PR that are not related to the actual diff. For instance, you added periods to a couple of comments that weren't touched by this PR in any other way. That's not a bad thing per se, but it's cluttering the PR a bit.

It'd be great of you could limit the diff to those parts that are actually changed as part of implementing the default-directory property. If it's too hard though leave the stylistic fixes in; it's ok.

Thanks for your great work on this PR!

@sergv sergv force-pushed the sergv:cwd branch 2 times, most recently from f8ddec4 to 25c5340 Jun 8, 2016

@sergv

This comment has been minimized.

Contributor

sergv commented Jun 8, 2016

@lunaryorn I rebased all the changes on latest master. I also reordered commits so that stylistic fixes are at the top and can be easily ignored via git diff 99c26f6..cwd^, for example. In addition, I moved default-directory setting back into checker process object and disallowed non-function values of :default-directory setting3.

flycheck.el Outdated
@@ -4257,6 +4263,27 @@ universal prefix arg, and only the id with normal prefix arg."
(`(eval ,_) t)
(_ nil)))
(defun flycheck-default-directory-wrapper (checker)

This comment has been minimized.

@lunaryorn

lunaryorn Jul 1, 2016

Contributor

I don't like the name of this function :) It's too generic.

Can we come up with a better one? E.g. flycheck-compute-default-directory, or so?

flycheck.el Outdated
Work out the working directory from which the CHECKER command
will be called. The default is the `default-directory' of the source-buffer
from which flycheck is calling the checker.

This comment has been minimized.

@lunaryorn

lunaryorn Jul 1, 2016

Contributor

Wrapping looks off here. Please rewrap the docstring.

flycheck.el Outdated
(defun flycheck-default-directory-wrapper (checker)
"Function returning apropriate current working directory.
Work out the working directory from which the CHECKER command

This comment has been minimized.

@lunaryorn

lunaryorn Jul 1, 2016

Contributor

Maybe "Compute" rather than "work out"?

s3bs and others added some commits Nov 30, 2015

adding the posibility so that :cwd can be a function that returns an …
…absolut paath from which the checker command will be executed.
removing the :environment property
It will live on separate branch cwd-env.
flycheck-fix-error-filename now takes cwd
adding code so that flycheck-fix-error-filename can use relative
file names, which are relative to cwd.
Rename cwd variable names and property names for clarity.
:cwd property has been renamed to :default-directory.  Add doc strings
and a check if defined :default-directory exists.
remove #' (sharp quote) for default-directory property
remove the sharp quote in flycheck-define-checker macro
for passing on the default-directory property to flycheck-define-command checker. This avoids a problem encountered with lambda functions.

@sergv sergv force-pushed the sergv:cwd branch from 8b855f5 to efb9399 Jul 7, 2016

@sergv

This comment has been minimized.

Contributor

sergv commented Jul 7, 2016

@lunaryorn However, it seems new approval is needed after rebase. Can you please approve again?

@sergv sergv merged commit 472eb7c into flycheck:master Jul 7, 2016

2 checks passed

approvals/lgtm this commit looks good
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@sergv

This comment has been minimized.

Contributor

sergv commented Jul 7, 2016

@lunaryorn For some reason, github still created a merge commit. Not sure what to do about it.

@sergv sergv deleted the sergv:cwd branch Jul 7, 2016

@mrkkrp

This comment has been minimized.

Contributor

mrkkrp commented Jul 7, 2016

Now that we have this merged, we can make ghc and ghc-stack be called as if from root directory of project, right? Is there any plans to do this change, or if you point where to look how this new feature works I can open a PR myself.

@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented Jul 7, 2016

@sergv Merge commits are fine for larger branches such as this 😊

@mrkkrp This branch adds a new default-directory property to syntax checker definitions. Refer to the docstrings for details.

I don't plan to update any syntax checkers following this change but if you think it's reasonable to change some syntax checkers please go ahead an open a pull request.

lunaryorn added a commit that referenced this pull request Jul 7, 2016

Enrich interface of default-directory function
Pass it the syntax checker being used to allow dispatching on the
checker and permit it to return nil to fall back to the normal default
directory.

See GH-973
@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented Jul 7, 2016

@sergv I've changed the interface of the :default-directory function. It now takes the syntax checker symbol as argument, to allow to reuse the same function for multiple checkers while optionally dispatching on the syntax checker, and it may return nil now to fall back to the normal default directory, for instance in case a project file isn't found. I think these changes are reasonable, do you agree?

Meanwhile, would you please take a look at #1005? This change seems to have broken generic syntax checkers.

@sergv

This comment has been minimized.

Contributor

sergv commented Jul 7, 2016

@lunaryorn The change to :default-directory looks reasonable. I'll look at #1005.

@lunaryorn @mrkkrp Regarding default-directory property for haskell-stack-ghc checker, I can submit one. However this would probably mean that we should add :default-directory argument to flycheck-define-checker macro since haskell-stack-ghc is defined using it. Would you agree with such addition, @lunaryorn?

@lunaryorn

This comment has been minimized.

Contributor

lunaryorn commented Jul 7, 2016

@sergv Yes the macro should support all properties of flycheck-define-generic-checker. It'd be great if you could make this change as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment