ale icon indicating copy to clipboard operation
ale copied to clipboard

`ormolu` fixer doesn't work out of the box

Open eahlberg opened this issue 2 years ago • 2 comments

Information

VIM version VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Jan 01 1980 00:00:00) Included patches: 1-1441

Operating System: NixOS 23.05.589.a558f7ac29f (Stoat)

ormolu version:

> ormolu --version
ormolu 0.5.0.1 UNKNOWN UNKNOWN
using ghc-lib-parser 9.2.7.20230228

(I tested with ormolu v.0.3.1.0 which does not have this issue).

vim-ale version: I believe it is 2023-08-05 (this commit). From this nix channel (updated an hour ago at time of writing).

What went wrong

Ormolu fixer doesn't format the file. The command history contains the following line (note exit code 9). See :ALEInfo section below for full output.

(finished - exit code 9) ['/run/current-system/sw/bin/bash', '-c', '''ormolu'' < ''/tmp/vKSqUsU/5/About.hs''']

Reproducing the bug

  1. Enable the ormolu fixer, open a Haskell source file which isn't formatted according to ormolu's rules and save and trigger the formatting.
  2. Observe that the source file wasn't formatted.

:ALEInfo

Expand

Current Filetype: haskell Available Linters: ['cabal_ghc', 'cspell', 'ghc', 'ghc_mod', 'hdevtools', 'hie', 'hlint', 'hls', 'stack_build', 'stack_ghc'] Linter Aliases: 'cabal_ghc' -> ['cabal-ghc'] 'ghc_mod' -> ['ghc-mod'] 'stack_build' -> ['stack-build'] 'stack_ghc' -> ['stack-ghc'] Enabled Linters: ['hlint'] Ignored Linters: [] Suggested Fixers: 'brittany' - Fix Haskell files with brittany. 'floskell' - Fix Haskell files with floskell. 'fourmolu' - A formatter for Haskell source code. 'hfmt' - Fix Haskell files with hfmt. 'hindent' - Fix Haskell files with hindent. 'hlint' - Refactor Haskell files with hlint. 'ormolu' - A formatter for Haskell source code. 'remove_trailing_lines' - Remove all blank lines at the end of a file. 'stylish-haskell' - Refactor Haskell files with stylish-haskell. 'trim_whitespace' - Remove all trailing whitespace characters at the end of every line. Linter Variables:

let g:ale_haskell_cabal_ghc_options = '-fno-code -v0' let g:ale_haskell_hlint_executable = 'hlint' let g:ale_haskell_hlint_options = '' let g:ale_haskell_ormolu_executable = 'ormolu' let g:ale_haskell_ormolu_options = '' let g:ale_haskell_stack_build_options = '--fast' let g:ale_haskell_stack_ghc_options = '-fno-code -v0' 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_disable_lsp = 0 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': ['ormolu'], '*': ['remove_trailing_lines', 'trim_whitespace'], 'javascript': ['eslint']} 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 = 1 let g:ale_lint_on_filetype_changed = 1 let g:ale_lint_on_insert_leave = 1 let g:ale_lint_on_save = 1 let g:ale_lint_on_text_changed = 'normal' let g:ale_linter_aliases = {} let g:ale_linters = {'haskell': ['hlint'], 'sh': ['shellcheck'], 'javascript': ['eslint']} let g:ale_linters_explicit = 0 let g:ale_linters_ignore = {} let g:ale_list_vertical = 0 let g:ale_list_window_size = 10 let g:ale_loclist_msg_format = '%code: %%s' 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 = 0 let g:ale_pattern_options = v:null let g:ale_pattern_options_enabled = v:null let g:ale_root = {} 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_sign_highlight_linenrs = 0 let g:ale_statusline_format = v:null let g:ale_type_map = {} let g:ale_use_neovim_diagnostics_api = 0 let g:ale_use_global_executables = v:null let g:ale_virtualtext_cursor = 'all' let g:ale_warn_about_trailing_blank_lines = 1 let g:ale_warn_about_trailing_whitespace = 1 Command History:

(executable check - success) hlint (finished - exit code 0) ['/run/current-system/sw/bin/bash', '-c', '''hlint'' --color=never --json - < ''/tmp/vKSqUsU/1/About.hs''']

<<<OUTPUT STARTS>>> [] <<<OUTPUT ENDS>>>

(finished - exit code 9) ['/run/current-system/sw/bin/bash', '-c', '''ormolu'' < ''/tmp/vKSqUsU/5/About.hs'''] (finished - exit code 0) ['/run/current-system/sw/bin/bash', '-c', '''hlint'' --color=never --json - < ''/tmp/vKSqUsU/6/About.hs''']

<<<OUTPUT STARTS>>> [] <<<OUTPUT ENDS>>>

eahlberg avatar Aug 18 '23 13:08 eahlberg

When running ormolu from the command line in the way it seems to be invoked from ale:

> bash -c ormolu < src/File.hs
The --stdin-input-file option is necessary when using input from stdin and accounting for .cabal files

Therefore, a workaround is to configure ormolu like this:

let g:ale_haskell_ormolu_options="--stdin-input-file ."

Perhaps this should be the default? The option is used here in the fourmolu fixer, which I believe is similar. If that sounds reasonable, let me know and I can give a go at a PR.

eahlberg avatar Aug 18 '23 13:08 eahlberg

Hmm, if it indeed enough to fix the issue, I think you should very well send a PR :+1:

Jorenar avatar Nov 19 '23 13:11 Jorenar

Cool! I opened a PR here: https://github.com/dense-analysis/ale/pull/4654

eahlberg avatar Nov 22 '23 15:11 eahlberg