withered-magic / starpls

An LSP implementation for Starlark, the configuration language used by Bazel and Buck2.
Apache License 2.0
109 stars 11 forks source link

Unexpected indentation for blank lines between statements #247

Open hauserx opened 6 months ago

hauserx commented 6 months ago

Simple example:

def x():
    y = 4

    z = 2

Result:

image

withered-magic commented 6 months ago

Hmm, do you know what your indentation settings are for your editor, of if the indentation in the example is mixed (e.g. tabs for one line and spaces for another)? I'm not able to reproduce this running on VSCode with tabs converted to four spaces, which is how starpls treats tabs.

Alternatively, if you upload an example repro .bzl file, I can try looking to see if something unexpected is happening with indentation.

hauserx commented 6 months ago

I am using fresh install of neovim in WSL2 and looks by default it was using windows CRLF endlines... The issue is fixed by using unix endlines. So seems this issue maybe by under windows/when using CRLF endlines.

hauserx commented 6 months ago

Attaching small script to reproduce the issue: test_starpls_crlf.txt

Output:

Diagnostics: {
  "jsonrpc": "2.0",
  "method": "textDocument/publishDiagnostics",
  "params": {
    "diagnostics": [
      {
        "message": "Unexpected indentation",
        "range": {
          "end": {
            "character": 0,
            "line": 3
          },
          "start": {
            "character": 0,
            "line": 3
          }
        },
        "severity": 1,
        "source": "starpls"
      }
    ],
    "uri": "file:///fakepath/sample.bzl",
    "version": 1
  }
}
withered-magic commented 6 months ago

Thank you! I use WSL2 but not with CRLF line endings so admittedly haven't actually tested this too much 😅 I'll try to have a fix out soon, should be straightforward

albertocavalcante commented 3 months ago

It would be nice to have support for CRLF as this should be valid for Starlark files.

In the meantime I noticed that buildifier by default replaces CRLF with LF.

While this is not supported by starpls, I'm simply conveying using LF EOL for all starlark files with the below:

buildifier -config=off -r .

and at .vscode\settings.json:

"[starlark]": {
    "files.eol": "\n"
}