Repository navigation
bug: Blank line at EOF with powershell_es #274
Description
Activity
No biggy. The main reason I was using
conform.nvimwas because of how easy custom formatters (mainlystylua) can be integrated. I just figuredlua_lsprovides me with the necessary options I use forstyluaout of the box, so I was able to ditchconform.nvimalltogether. You might still want to look into this. Otherwise cool plugin, I might come back later in case I have something that has no built in formatting via lsp. Cheers.Not sure if this is helpful in your situation but I could not get the LSP formatting to work with powershell_es. As a workaround, I'm using a custom formatter based on
Invoke-Formatterfrom the PSScriptAnalyzer module.Here is my conform configuration:
https://github.com/scottmckendry/Windots/blob/main/nvim/lua/plugins/conform.luaSo far it's been fairly reliable, my only qualm is that it does not support Unicode characters, so no emojis or nerd font icons in scripts :(
I have a suspicion about what is happening, but I'll need some more logs to confirm it. Could you format a small file that exhibits this error with
log_level = vim.log.levels.TRACEand provide the logs? I just need to see what the raw output of the LSP format operation is.- addedquestionFurther information is requestedFurther information is requested
on Jan 21, 2024 I know this was originally raised for the PowerShell LSP formatter, but I'm having a very similar problem with the Bicep LSP with conform where new lines are inserted just before the final closing brace. For example, the file looks like this before saving:
resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) { name: 'deleteLock' scope: resourceGroup() properties: { level: 'CanNotDelete' } }
After saving, it looks like this:
resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) { name: 'deleteLock' scope: resourceGroup() properties: { level: 'CanNotDelete' } }
Then from the second save onwards there are two new lines at this position:
resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) { name: 'deleteLock' scope: resourceGroup() properties: { level: 'CanNotDelete' } }
The resulting logs of three saves in a row on the example above:
07:06:14[DEBUG] Running formatters on C:\Users\Scott\Git\Windots\test.bicep: {} 07:06:14[DEBUG] Running LSP formatter on C:\Users\Scott\Git\Windots\test.bicep 07:06:14[DEBUG] Converting full-file LSP format to piecewise format 07:06:14[TRACE] Applying formatting to C:\Users\Scott\Git\Windots\test.bicep 07:06:14[TRACE] Comparing lines { "resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) {", " name: 'deleteLock'", " scope: resourceGroup()", " properties: {", " level: 'CanNotDelete'", " }", "}" } and { "resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) {\r", " name: 'deleteLock'\r", " scope: resourceGroup()\r", " properties: {\r", " level: 'CanNotDelete'\r", " }\r", "}" } 07:06:14[TRACE] Diff indices { { 1, 6, 1, 6 } } 07:06:14[TRACE] Applying text edits: { { newText = "\r\n name: 'deleteLock'\r\n scope: resourceGroup()\r\n properties: {\r\n level: 'CanNotDelete'\r\n }\r", range = { ["end"] = { character = 5, line = 5 }, start = { character = 84, line = 0 } } } } 07:06:14[TRACE] Done formatting C:\Users\Scott\Git\Windots\test.bicep 07:06:17[DEBUG] Running formatters on C:\Users\Scott\Git\Windots\test.bicep: {} 07:06:17[DEBUG] Running LSP formatter on C:\Users\Scott\Git\Windots\test.bicep 07:06:17[DEBUG] Converting full-file LSP format to piecewise format 07:06:17[TRACE] Applying formatting to C:\Users\Scott\Git\Windots\test.bicep 07:06:17[TRACE] Comparing lines { "resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) {", " name: 'deleteLock'", " scope: resourceGroup()", " properties: {", " level: 'CanNotDelete'", " }", "", "}" } and { "resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) {\r", " name: 'deleteLock'\r", " scope: resourceGroup()\r", " properties: {\r", " level: 'CanNotDelete'\r", " }\r", "\r", "}" } 07:06:17[TRACE] Diff indices { { 1, 7, 1, 7 } } 07:06:17[TRACE] Applying text edits: { { newText = "\r\n name: 'deleteLock'\r\n scope: resourceGroup()\r\n properties: {\r\n level: 'CanNotDelete'\r\n }\r\n\r", range = { ["end"] = { character = 0, line = 6 }, start = { character = 84, line = 0 } } } } 07:06:17[TRACE] Done formatting C:\Users\Scott\Git\Windots\test.bicep 07:07:08[DEBUG] Running formatters on C:\Users\Scott\Git\Windots\test.bicep: {} 07:07:08[DEBUG] Running LSP formatter on C:\Users\Scott\Git\Windots\test.bicep 07:07:08[DEBUG] Converting full-file LSP format to piecewise format 07:07:08[TRACE] Applying formatting to C:\Users\Scott\Git\Windots\test.bicep 07:07:08[TRACE] Comparing lines { "resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) {", " name: 'deleteLock'", " scope: resourceGroup()", " properties: {", " level: 'CanNotDelete'", " }", "", "", "}" } and { "resource rgDeleteLock 'Microsoft.Authorization/locks@2016-09-01' = if (deleteLock) {\r", " name: 'deleteLock'\r", " scope: resourceGroup()\r", " properties: {\r", " level: 'CanNotDelete'\r", " }\r", "\r", "}" } 07:07:08[TRACE] Diff indices { { 1, 8, 1, 7 } } 07:07:08[TRACE] Applying text edits: { { newText = "\r\n name: 'deleteLock'\r\n scope: resourceGroup()\r\n properties: {\r\n level: 'CanNotDelete'\r\n }\r\n\r", range = { ["end"] = { character = 0, line = 7 }, start = { character = 84, line = 0 } } } } 07:07:08[TRACE] Done formatting C:\Users\Scott\Git\Windots\test.bicepLet me know if any further info is required.
- removedquestionFurther information is requestedFurther information is requested
on Jan 21, 2024 - added a commit that references this issue
on Jan 21, 2024 Thanks for the logs! This confirms my suspicion that it is related to the line endings. I've pushed up what I believe to be a fix. Could you give it a try?
- addedquestionFurther information is requestedFurther information is requested
on Jan 21, 2024 Brilliant! That's fixed it for the Bicep LSP. @MarcoBuess may be able to advise RE PowerShell.
- removedquestionFurther information is requestedFurther information is requested
on Jan 21, 2024 Will close as fixed. Feel free to re-open if issue persists
Neovim version (nvim -v)
0.9.4
Operating system/version
Windows 10.0.19045
Add the debug logs
log_level = vim.log.levels.DEBUGand pasted the log contents below.Log file
Describe the bug
When using format on save, a new line gets added at EOF. Disabling
conform.nvimand formatting withvim.lsp.buf.format()doesn't show this behavior.What is the severity of this bug?
minor (annoyance)
Steps To Reproduce
.ps1fileformat_on_saveenabled.Expected Behavior
Code gets formatted but no new line added at EOF.
Minimal example file
Write-Output -InputObject "Hello, World!"
Minimal init.lua
Additional context
No response