haskell-language-server icon indicating copy to clipboard operation
haskell-language-server copied to clipboard

Brittany config indentation is not respected

Open andys8 opened this issue 5 years ago • 3 comments

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.yaml as 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

andys8 avatar Oct 27 '20 17:10 andys8

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?

AleXoundOS avatar Aug 01 '22 22:08 AleXoundOS

@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.

AleXoundOS avatar Aug 01 '22 23:08 AleXoundOS

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?

fendor avatar Aug 02 '22 06:08 fendor

Relevant VSCode settings:

  • "Editor: Tab Size"
  • "Editor: Detect Indentation"

DenisGorbachev avatar Dec 08 '23 03:12 DenisGorbachev

brittany plugin is gone

michaelpj avatar Jan 11 '24 09:01 michaelpj