dense-analysis / ale

Check syntax in Vim/Neovim asynchronously and fix files, with Language Server Protocol (LSP) support
BSD 2-Clause "Simplified" License
13.58k stars 1.44k forks source link

Cabal ghc check report import error when it shouldn't #2554

Open WnP opened 5 years ago

WnP commented 5 years ago

Information

▶ nvim --version
NVIM v0.3.5
Build type: Release
LuaJIT 2.1.0-beta3
Compilation: /usr/lib/ccache/bin/cc -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe  -g -Wconversion -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -O2 -DNDEBUG -DMIN_LOG_LEVEL=3 -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fdiagnostics-color=auto -Wno-array-bounds -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -I/builddir/neovim-0.3.5/build/config -I/builddir/neovim-0.3.5/src -I/usr/include -I/builddir/neovim-0.3.5/build/src/nvim/auto -I/builddir/neovim-0.3.5/build/include
Compiled by void-buildslave@a-hel-fi

Features: +acl +iconv -jemalloc +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Operating System:

▶ uname -a
Linux modular 4.19.47_1 #1 SMP PREEMPT Sat Jun 1 07:32:05 UTC 2019 x86_64 GNU/Linux

▶ cat /etc/*release*
NAME="void"
ID="void"
DISTRIB_ID="void"
PRETTY_NAME="void"

What went wrong

Haskell cabal ghc checker return import error on sub module source:

Could not find module 'Foo.Bar’

Reproducing the bug

Project structure:

src
├── Foo
│   ├── Bar.hs
│   └── Baz.hs
└── Main.hs

when editing Main.hs which import Foo.Bar there is no issue, but when editing Foo.Baz which import Foo.Bar then the error occure.

I've made a git bisect to find when this issue was added, and it came from PR #2345, commit 2eb68f6d23f51c33f3d64a15172c869e71d7829b, prior to that PR / commit this issue is not present.

So ale v2.4.0 is not affected.

:ALEInfo

 Current Filetype: 
Available Linters: []
  Enabled Linters: []
 Suggested Fixers: 
  'remove_trailing_lines' - Remove all blank lines at the end of a file.
  'trim_whitespace' - Remove all trailing whitespace characters at the end of every line.
 Linter Variables:

 Global Variables:

let g:ale_cache_executable_check_failures = v:null
let g:ale_change_sign_column_color = 0
let g:ale_command_wrapper = ''
let g:ale_completion_delay = v:null
let g:ale_completion_enabled = 0
let g:ale_completion_max_suggestions = v:null
let g:ale_echo_cursor = 1
let g:ale_echo_msg_error_str = 'Error'
let g:ale_echo_msg_format = '%code: %%s'
let g:ale_echo_msg_info_str = 'Info'
let g:ale_echo_msg_warning_str = 'Warning'
let g:ale_enabled = 1
let g:ale_fix_on_save = 1
let g:ale_fixers = {'haskell': ['hfmt'], 'sh': ['shfmt'], 'python': ['black', 'isort']}
let g:ale_history_enabled = 1
let g:ale_history_log_output = 1
let g:ale_keep_list_window_open = 0
let g:ale_lint_delay = 200
let g:ale_lint_on_enter = 0
let g:ale_lint_on_filetype_changed = 1
let g:ale_lint_on_insert_leave = 0
let g:ale_lint_on_save = 1
let g:ale_lint_on_text_changed = 'never'
let g:ale_linter_aliases = {}
let g:ale_linters = {'haskell': ['cabal-ghc', 'hlint', 'hdevtools'], 'python': ['flake8']}
let g:ale_linters_explicit = 0
let g:ale_list_vertical = 0
let g:ale_list_window_size = 10
let g:ale_loclist_msg_format = '%code: %%s'
let g:ale_lsp_root = {}
let g:ale_max_buffer_history_size = 20
let g:ale_max_signs = -1
let g:ale_maximum_file_size = v:null
let g:ale_open_list = 'on_save'
let g:ale_pattern_options = v:null
let g:ale_pattern_options_enabled = v:null
let g:ale_set_balloons = 0
let g:ale_set_highlights = 1
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_set_signs = 1
let g:ale_sign_column_always = 0
let g:ale_sign_error = '>>'
let g:ale_sign_info = '--'
let g:ale_sign_offset = 1000000
let g:ale_sign_style_error = '>>'
let g:ale_sign_style_warning = '--'
let g:ale_sign_warning = '--'
let g:ale_statusline_format = v:null
let g:ale_type_map = {}
let g:ale_use_global_executables = v:null
let g:ale_virtualtext_cursor = 0
let g:ale_warn_about_trailing_blank_lines = 1
let g:ale_warn_about_trailing_whitespace = 1
  Command History:
RyanSquared commented 5 years ago

What is the working directory you're in when you're editing Foo/Baz.hs? This is usually caused by the "project root" directory being different from the current directory, such as if you were to cd into the directory, and edit the file from there.

WnP commented 5 years ago

Hi @RyanSquared I've try from src directory and src parent directory (which is the project's root directory)

On v2.4.0 this error occure when I'm not in src directory, right now whatever the directory I'm in this error is raised

ford-prefect commented 5 years ago

I can see this as well. From the project root, I get these import errors. If I cd into the src directory, they are gone.

WnP commented 5 years ago

@ford-prefect which release/version have you tested?

ford-prefect commented 5 years ago

Not sure which things you want, so here goes:

ale: commit aae6d30b1ec135e37ec3bea1885d161c6174572b cabal-install: 2.4.1.0 ghc: 8.6.5

Happens with vim 8.1 and nvim 0.3.8.

ulidtko commented 4 years ago

The fix in 2eb68f6 is incorrect.

ale#path#BufferCdString is not a good way to locate the project root — the directory containing foopkg.cabal.

For stack ghc and cabal exec -- ghc to work, the CWD must be at the project root — not the dirname of the currently edited file.

Locating the project root dir is tricky (esp. if you want it reused cross-languages). One way:

Since this logic is so tricky and fragile, the best method is actually allowing the user to set it; i.e. use Vim's CWD for project root. I.e. exactly what 2eb68f6 broke while trying to fix.

I'd recommend reverting 2eb68f6 ASAP, and try to arrive at a better solution later.

samhh commented 4 years ago

I'm seeing this too. It's also manifesting as ALE being unaware of enabled extensions until my PWD matches the directory of the active buffer.