Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zploskey opened this issue Oct 21, 2017 · 6 comments
Open

Comments

@zploskey
Copy link

zploskey commented Oct 21, 2017

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.

@chenglou
Copy link
Collaborator

cc @jordwalke

@zploskey
Copy link
Author

zploskey commented Oct 21, 2017

The other possibility is that prabirshrestha/vim-lsp should not be applying additional indentation to the results of refmt from the language client, I guess. I suspect maybe both of these things need some changes.

@zploskey
Copy link
Author

zploskey commented Oct 21, 2017

Indeed, autozimu/LanguageClient-neovim doesn't seem to have this problem when you run :call LanguageClient_textDocument_formatting().

@zploskey zploskey changed the title [indent] Over-indentation following bucklescript annotations [indent] Over-indentation creates weird interactions with LSP formatter Oct 21, 2017
@zploskey
Copy link
Author

zploskey commented Oct 21, 2017

This may not have anything to do with bucklescript annotations. Perhaps just long lines/functions. With vim-lsp this output from refmt --in-place:

external render :
  ReasonReact.reactElement =>
  Dom.element =>
  array Dom.element =>
  Dom.element =>
  array Dom.element =>
  unit =
  "render";

external _getElementsByClassName : string => array Dom.element = "document.getElementsByClassName";

external _getElementById : string => option Dom.element = "document.getElementById";

Formats to this:

external render :
  ReasonReact.reactElement =>
    Dom.element =>
      array Dom.element =>
        Dom.element =>
          array Dom.element =>
            unit =
              "render";

              external _getElementsByClassName : string => array Dom.element = "document.getElementsByClassName";

              external _getElementById : string => option Dom.element = "document.getElementById";

@jordwalke
Copy link
Contributor

Worth trying on the new syntax! If it's suitable, we can close.

@zploskey
Copy link
Author

zploskey commented Nov 2, 2017

Still seeing over-indentation with :LspDocumentFormat and when entering a new line at the end of any of these functions.

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

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants