Sarrus1 / sourcepawn-studio

VSCode extension for SourcePawn scripting
https://sarrus1.github.io/sourcepawn-studio/
MIT License
140 stars 22 forks source link

Autoformatter adds spaces around colon in variable declaration #350

Open pabertay opened 9 months ago

pabertay commented 9 months ago

Please forgive me as I am just a novice, I sincerely hope this isn't a waste of time due to my ignorance.

Basic informations

Further Information

I get a red line and error indication under variable declarations which have a space before the colon. The code still compiles without error, but the linter seems to not like it (not sure if I'm using 'linter' correctly here).

This is a minor issue because when I use autoformat in VS Code (Shift + Alt + F), the formatter adds a space around the colon in variable declarations. I get distracted by these red lines and have to keep deleting the spaces manually.

EDIT: Was wrong, code does not compile with spaces. Linter indicating error is correct, the problem is the auto formatter behaviour

e.g.

new Handle:g_hFile = INVALID_HANDLE;

which looks good in VS Code, ('Handle' is in green, not blue) becomes

new Handle : g_hFile = INVALID_HANDLE;

Now with an error indicated and 'Handle' coloured in blue.

To Reproduce

  1. Create a sp file in VS Code
  2. Declare a variable with no space before the colon, e.g., new Handle:g_hFile = INVALID_HANDLE;
  3. Use VS Code autoformatter (Shift + Alt + F in Windows)
  4. Observe red line and error

Expected behaviour

I presume there should be no error indicated, and the variable type should still be coloured green

Auto formatter should not add spaces here

Error messages

(ERROR (symbol))

Additional

I would like to know if I can make changes to the formatter settings JSON file to prevent spaces around colons in these variable declarations.

Sarrus1 commented 9 months ago

Hi, thanks for reporting this!

This is an error on my end. It means that the parser of the lsp (the backend of the extension) does not like Handle:variable.

I don't know of a setting that could help fix that in the formatter :/

Only temporary workaround until I fix this would be to use the new syntax, without the colon.

pabertay commented 9 months ago

Thanks for the quick response. I just realised that I was wrong fundamentally - this does not compile. I must have been not saving the file before running the compiler... always something simple! So the bug is not 'displaying an error when there is none' - there is rightfully an error indicated (but I'm sure you spotted this).

I appreciate your workaround suggestion, think I will go with that so I don't have to delete spaces manually. The other workaround would be to not use auto formatter of course 😜