starpls icon indicating copy to clipboard operation
starpls copied to clipboard

Unexpected indentation for blank lines between statements

Open hauserx opened this issue 1 year ago • 5 comments

Simple example:

def x():
    y = 4

    z = 2

Result:

image

hauserx avatar May 09 '24 10:05 hauserx

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.

withered-magic avatar May 09 '24 10:05 withered-magic

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 avatar May 09 '24 11:05 hauserx

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
  }
}

hauserx avatar May 09 '24 15:05 hauserx

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

withered-magic avatar May 09 '24 16:05 withered-magic

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"
}

albertocavalcante avatar Aug 02 '24 14:08 albertocavalcante

Sorry for the slow turnaround here, but this should be fixed on latest main now!

cc @hauserx @albertocavalcante

withered-magic avatar Dec 01 '24 23:12 withered-magic