Skip to content

format on %raw would fill much blank lines #333

Closed

Description

@Mng12345

vscode settings.json

"[rescript]": {
    "editor.defaultFormatter": "chenglou92.rescript-vscode"
  },

when saving files which contains %raw embeded javascript, there would be much blank lines putted in the %raw block in vscode
before:

let parsePageUrls: unit => array<string> = %raw(`
  function () {
    const divs = document.getElementsByClassName("title")
    const urls = []
    for (let i=0; i<divs.length; i++) {
      const url = divs[i].getElementsByTagName("a")[0].href
      urls.push(url)
      console.log("push url: ", url)
    }
    return urls
  }
`)

after save file:

let parsePageUrls: unit => array<string> = %raw(` 

  function () {

    const divs = document.getElementsByClassName("title")

    const urls = []

    for (let i=0; i<divs.length; i++) { 

      const url = divs[i].getElementsByTagName("a")[0].href

      urls.push(url)

      console.log("push url: ", url)

    }

    return urls

  }

`)

The blank lines will become more when saving again.

let parsePageUrls: unit => array<string> = %raw(` 



  function () {



    const divs = document.getElementsByClassName("title")



    const urls = []



    for (let i=0; i<divs.length; i++) { 



      const url = divs[i].getElementsByTagName("a")[0].href



      urls.push(url)



      console.log("push url: ", url)



    }



    return urls



  }



`)

Activity

  1. Mng12345 commented on Jan 1, 2022

    @Mng12345
    Author

    Nobody here??

  2. amiralies commented on Jan 1, 2022

    @amiralies
    Contributor

    Can not reproduce this.
    Which OS do you use?

    is this happening using cli too?

    ./node_modules/.bin/rescript format <file.res>
  3. Mng12345 commented on Jan 1, 2022

    @Mng12345
    Author

    Can not reproduce this. Which OS do you use?

    is this happening using cli too?

    ./node_modules/.bin/rescript format <file.res>

    I am using windows10 x64, This is my settings.json in vscode

    "editor.formatOnSave": true,
      "editor.defaultFormatter": "esbenp.prettier-vscode",
      "[rescript]": {
        "editor.defaultFormatter": "chenglou92.rescript-vscode1"
      },

    The format result is normal when formatting by cli,

  4. amiralies commented on Jan 1, 2022

    @amiralies
    Contributor

    is this possible to test with rescript extension in isolation ? or disable other formatter plugins like prettier.
    and is this happening with normal formatting too (without format on save)

  5. Mng12345 commented on Jan 1, 2022

    @Mng12345
    Author

    is this possible to test with rescript extension in isolation ? or disable other formatter plugins like prettier. and is this happening with normal formatting too (without format on save)

    Normal format(with command line) is ok, The blank lines is getting more whether or not to disable prettier plugin.

  6. a-c-sreedhar-reddy commented on Jan 8, 2022

    @a-c-sreedhar-reddy
    Contributor

    Hi @Mng12345 Can you try removing all the other extensions from your vscode and just installing the rescript-vscode extension.

  7. added a commit that references this issue on Jan 18, 2022
  8. ryyppy commented on Jan 20, 2022

    @ryyppy
    Member

    @Mng12345 can you try switching to Unix line endings in your files? There's a setting in the VSCode footer (LF | CLRF)

    image

    Might be an encoding issue

  9. Mng12345 commented on Jan 20, 2022

    @Mng12345
    Author

    @Mng12345 can you try switching to Unix line endings in your files? There's a setting in the VSCode footer (LF | CLRF)

    image

    Might be an encoding issue

    Oh! Thank you, that fixed my problem!

  10. ryyppy commented on Jan 20, 2022

    @ryyppy
    Member

    Okay cool! I think there were several discussions on how to solve that issue, but there was no proper way to do it. So I guess the recommendation is to switch to LF (something that should be done anyway in a multi-OS environment).

    Will close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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