Brittany config indentation is not respected
Subject of the issue
Formatting a project with local brittany configuration works, but the indentation is suprisingly changed. With lconfig_indentAmount: 2 one would expect 2 space indentation, but it was 4 in my case.
I changed different configuration options, to verify the file is taken into account. It is.
There is this part of the brittany formatting provider:
https://github.com/andys8/haskell-language-server/blob/91d2711f3899c3c44d48c44ede0932e961bf63ba/plugins/default/src/Ide/Plugin/Brittany.hs#L72-L84
It passes a user config with highest priority to overwrite the tab size.
{ _conf_layout =
mempty { _lconfig_indentAmount = opt (coerce tabSize)
}
, _conf_forward =
(mempty :: CForwardOptions Option)
{ _options_ghc = opt (runIdentity ( _options_ghc forwardOptionsSyntaxExtsEnabled))
}
}
I think the tab size is either some default or can be influenced with defining an .editorconfig file. There was no .editorconfig before, but with adding a file like the tab size can again be set to the value defined in brittany.yaml.
[*.hs]
indent_style = space
indent_size = 2
Your environment
haskell-langauge-server 0.5.1.0 Vim 8.2 1-1704
Steps to reproduce
Tell us how to reproduce this issue.
Expected behaviour
- Use the
brittany.yamlas is - Or state that several configurations are in conflict
Actual behaviour
Used a different indentation.
Include debug information
Local brittany.yaml:
conf_debug:
dconf_roundtrip_exactprint_only: false
dconf_dump_bridoc_simpl_par: false
dconf_dump_ast_unknown: false
dconf_dump_bridoc_simpl_floating: false
dconf_dump_config: false
dconf_dump_bridoc_raw: false
dconf_dump_bridoc_final: false
dconf_dump_bridoc_simpl_alt: false
dconf_dump_bridoc_simpl_indent: false
dconf_dump_annotations: false
dconf_dump_bridoc_simpl_columns: false
dconf_dump_ast_full: false
conf_forward:
options_ghc: []
conf_errorHandling:
econf_ExactPrintFallback: ExactPrintFallbackModeInline
econf_Werror: false
econf_omit_output_valid_check: false
econf_produceOutputOnErrors: false
conf_preprocessor:
ppconf_CPPMode: CPPModeAbort
ppconf_hackAroundIncludes: false
conf_obfuscate: false
conf_roundtrip_exactprint_only: false
conf_version: 1
conf_layout:
lconfig_reformatModulePreamble: true
lconfig_altChooser:
tag: AltChooserBoundedSearch
contents: 3
lconfig_allowSingleLineExportList: false
lconfig_importColumn: 50
lconfig_hangingTypeSignature: false
lconfig_importAsColumn: 50
lconfig_alignmentLimit: 30
lconfig_allowHangingQuasiQuotes: true
lconfig_indentListSpecial: true
lconfig_indentAmount: 2
lconfig_alignmentBreakOnMultiline: true
lconfig_cols: 80
lconfig_indentPolicy: IndentPolicyFree
lconfig_indentWhereSpecial: true
lconfig_columnAlignMode:
tag: ColumnAlignModeMajority
contents: 0.7
I experience the same issue with emacs 28.1 with HLS 1.4. tab-width is set to 2, but it does not help. How to explicitly force 2 space indentation with HLS & brittany?
@andys8, you're right.
diff --git a/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs b/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs
index c4d4d7aa..2c7a0ad7 100644
--- a/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs
+++ b/plugins/hls-brittany-plugin/src/Ide/Plugin/Brittany.hs
@@ -100,12 +100,9 @@ runBrittany :: Int -- ^ tab size
-> Maybe FilePath -- ^ local config file
-> Text -- ^ text to format
-> IO (Either [BrittanyError] Text)
-runBrittany tabSize df confPath text = do
+runBrittany _tabSize df confPath text = do
let cfg = mempty
- { _conf_layout =
- mempty { _lconfig_indentAmount = opt (Last tabSize)
- }
- , _conf_forward =
+ { _conf_forward =
(mempty :: CForwardOptions Option)
{ _options_ghc = opt (getExtensions df)
}
This works for me as a workaround.
It breaks tests, so build with tests disabled, i.e. pkgs.haskell.lib.dontCheck in Nix.
I think the issue is that the lsp-client sends an indentation size with every formatting request. It looks like this is mandatory https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_formatting
Maybe we can raise an issue with LSP?
Relevant VSCode settings:
- "Editor: Tab Size"
- "Editor: Detect Indentation"
brittany plugin is gone