Skip to content

[indent] Over-indentation creates weird interactions with LSP formatter #10

@zploskey

Description

@zploskey

I think there is a problem with indentation after lines with bucklescript annotations. For example, with the file (example from near the beginning of reason-react, src/ReactDOMRe.re):

external render : ReasonReact.reactElement => Dom.element => unit =
  "render" [@@bs.val] [@@bs.module "react-dom"];

external _getElementsByClassName : string => array Dom.element =
  "document.getElementsByClassName" [@@bs.val];

external _getElementById : string => option Dom.element =
  "document.getElementById" [@@bs.val] [@@bs.return nullable];

If I go to the end of the first expression (after [@@bs.module "react-dom"];), and insert a new line, the new line is automatically indented by 2 spaces. I think it should not be indented at all, unless we're in a block, surrounded by { }.

This may not sound like a big deal, but it is causing reformatting with vim-lsp and ocaml-language-server using the :LspDocumentFormat command to indent lines following each expression with bucklescript annotations by an additional indentation level. So you wind up with some of these lines being 3 or 4 indentation levels deep when they should actually start at the beginning of the line, and do if you just run refmt --in-place on the file from outside the editor. It winds up looking like this:

external render : ReasonReact.reactElement => Dom.element => unit =
  "render" [@@bs.val] [@@bs.module "react-dom"];

  external _getElementsByClassName : string => array Dom.element =
    "document.getElementsByClassName" [@@bs.val];

    external _getElementById : string => option Dom.element =
      "document.getElementById" [@@bs.val] [@@bs.return nullable];

Moving indent/reason.vim somewhere else makes things indent normally. Looks like an issue with the indent configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions