Closed JonnyRa closed 5 years ago
I'll say that's a bug and it can be fixed by changing the working directory. That could be done with a command_callback
function and ale#path#BufferCdString
. Something like this:
'command_callback': {buffer -> ale#path#BufferCdString(buffer) . 'stack ghc -- -fno-code -v0 %t'},
Thanks for the response
I'll give that a try in my local copy and see if it fixes the issue
does it use the vim working directory by default? I'm pretty sure that'd work fine aswell.
Cheers
Jonny
That sets the working directory to be the directory that the file is in all the time, with cd ... &&
does that include when it gets copied to tmp?
I think it'd actually be better to either set it to the vim working directory or possibly to the buffer's original location. Does that call do the latter? I'm not sure which is the right answer as I can't reproduce those specific errors by calling stack ghc from the command line
Is the default behaviour without the extra command to use :pwd
as the working directory?
It sets it to the directory the file is in, which should be inside the project. Give it a try and see how well it works. It tends to work for most tools.
The default is that the working directory is effectively random, as it's :pwd
at the time the command runs, which could be at any time.
Hi @w0rp . First of all, thanks for a great plugin.
I had a similar issue as OP and was able to work around it by following your suggestion to change the working directory to this file: https://github.com/w0rp/ale/blob/master/ale_linters/haskell/stack_ghc.vim
I can make a PR for this but I'm not sure if it should be changed for everybody, or if it would make more sense to make this behaviour configurable.
What's the usual approach?
The usual approach is to use the ale#path#BufferCdString(a:buffer)
function to set the working directory to the directory the file is in, or similar. See other linters for examples. Feel free to create a pull request.
I'm still having this issue.
There seems to be an issue with the stack_ghc
linter that isn't present in the ghcid
running inside vim (via the plugin). The linter claims that local modules that are imported cannot be resolved.
.vimrc setup
let g:ale_linters = {}
let g:ale_linters.haskell = ['stack_ghc', 'hlint']
let g:ale_haskell_stack_ghc_options = '
\ -threaded
\ -rtsopts
\ -with-rtsopts=-N
\ -Wall
\ -Wcompat
\ -Wincomplete-record-updates
\ -Wincomplete-uni-patterns
\ -Wredundant-constraints
\ -Wmissing-import-lists
\ -Wmissing-export-lists
\'
let g:ghcid_command = 'stack exec ghcid --'
In the following file, I'm importing the Models
module.
# DatabaseThings.hs
9 -- import Database.Beam.Sqlite
10 import qualified Data.Time.Clock as Time (UTCTime)
11 import Database.Beam (Columnar, Generic, Identity, PrimaryKey)
✘ 12 import Models (Content)
#### this error shows
Could not find module ‘Models’ Perhaps you meant Module (needs flag -package-key ghc-8.6... import Models (Content) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Running ghcid
in either vim or the terminal shows no issue.
All good (2 modules, at 18:47:24)
Here is the directory structure
├── src
│ ├── DatabaseThings.hs
│ └── Models.hs
It seems as if the linter is potentially not running in the pwd
of the project, but that's just my guess.
This also isn't resolved for me, I never really got my head around what is happening and I couldn't reproduce the error just using stack and running with different working directories.
I don't think the suggested patch helped but am unsure whether I am running a locally patched version (which still has the problem) or whether I updated ALE at some point
I'd like to try and fix this, but I'm pretty unfamiliar with the syntax used in these files. Can you give me some pointers on how to make this compile?
" Author: w0rp <devw0rp@gmail.com>
" Description: ghc for Haskell files, using Stack
call ale#Set('haskell_stack_ghc_options', '-fno-code -v0')
function! ale_linters#haskell#stack_ghc#GetCommand(buffer) abort
return ale#handlers#haskell#GetStackExecutable(a:buffer)
\ . ' ghc -- '
\ . ale#Var(a:buffer, 'haskell_stack_ghc_options')
\ . ' %t'
endfunction
call ale#linter#Define('haskell', {
\ 'name': 'stack_ghc',
\ 'aliases': ['stack-ghc'],
\ 'output_stream': 'stderr',
\ 'executable': function('ale#handlers#haskell#GetStackExecutable'),
\ 'command': function('ale_linters#haskell#stack_ghc#GetCommand'),
\ 'callback': 'ale#handlers#haskell#HandleGHCFormat',
\ 'command_callback': {buffer -> ale#path#BufferCdString(buffer) . 'stack ghc -- -fno-code -v0 %t'}
\})
That Map takes strings and functions it seems.
Information
VIM version VIM - Vi IMproved 8.1 (2018 May 18, compiled Jun 26 2018 09:35:41)
Included patches: 1-116
Operating System: Ubuntu 18.04
:ALEInfo
What went wrong
That (repeated) import error is incorrect - the code compiles fine. You can safely ignore the hdevtools related stuff.
The stack-ghc linter is the most useful one but it sometimes produces errors where there should be none. They typically seem to relate to files inside the same package as the target file - eg other files outside the package will be fine.
The bug is intermittent - I believe it only happens when temporary files are used and I think it could possibly be fixed by supplying stack with a working directory, however I've done a bit of digging and am struggling to reproduce the same output when calling stack-ghc on a copy of the file directly.
Could you help me understand what ALE does? I've been reading the source a bit but been finding it a bit hard to follow and haven't seen anything about working directories.
I saved a copy of the file in question to the same tmp path in the hope of recreating the issue.
I've been running stack ghc like this
bash -c 'stack ghc -- -fno-code -v0 /tmp/vgbPARv/729/ImportSpec.hs'
which is more or less what I copied from the log above.The two ways I've tried running stack-ghc on the same file are:
Since I can't reproduce the output with stack ghc I came to the conclusion that ale must be running stack differently than either of the above.
Could you help shed some light?
If I can reproduce the errors/environment I should be able to help suggest how to run stack ghc to fix this issue/maybe even go in and update the linter myself and submit a pull request.
Btw I love ALE, it's a massive boost to the usefulness of vim when writing Haskell even with this niggle. Nice one for writing such a useful plugin :)
Cheers
Jonny