Open mirumirumi opened 1 week ago
Looks like you're using a fairly old version. Have you tried updating to see if it fixes your issue ?
@nhedger Are you talking about @biomejs/biome? As I explained before, the CLI has nothing to do with this case. I just reinstalled the latest version (1.9.0) and the bug is still there.
edited: Biome version updated
Sorry, I definitely read this a bit too quickly.
Not saying it's impossible, but the extension seems unlikely to be responsible for this. There are a couple of things we could do to check.
Try installing the extension in a fresh VS Code instance with nothing else installed (using an insider version of VS Code for example).
Set biome_lsp.trace.server
to verbose
, run the steps in order, check the Biome LSP trace output, and paste it here.
Also, please provide a minimal reproduction of this issue in the form of a git repository. You can use npm create @biomejs/biome-reproduction
to scaffold a git repository quickly.
I'll try right away!
@nhedger
I found the cause. I tried a clean VSCode and biome/reproduction environment as you suggested and reproduced it by adding “editor.formatOnType”: true
in settings.json of VSCode (of course the default formatter is set to Biome). Everything else is left as default.
This would still be a bug as a function of the formatter, right?
The repository is here: https://github.com/mirumirumi/biome-repro-1726462751533
Set biome_lsp.trace.server to verbose, run the steps in order, check the Biome LSP trace output, and paste it here.
I understand where to set the log level to verbose, but I don't know how to get the actual logs. The command is biome lsp-proxy
? biome start
?
I'm not using formatOnType myself, I'll have a try with your reproduction.
I understand where to set the log level to verbose, but I don't know how to get the actual logs. The command is biome lsp-proxy? biome start?
When inside VS Code, open the OUTPUT
panel, and select Biome LSP trace
I can reproduce the behavior.
When formatting manually the following snippet, nothing changes, as expected:
const a = 3;
if (!a) {
// type here: ()
console.log(55);
}
2024-09-16 10:02:37.055 [info] [Trace - 10:02:37 AM] Sending request 'textDocument/formatting - (9)'.
2024-09-16 10:02:37.055 [info] Params: {
"textDocument": {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts"
},
"options": {
"tabSize": 4,
"insertSpaces": false
}
}
2024-09-16 10:02:37.056 [info] [Trace - 10:02:37 AM] Received response 'textDocument/formatting - (9)' in 1ms.
2024-09-16 10:02:37.057 [info] Result: [
{
"range": {
"start": {
"line": 0,
"character": 0
},
"end": {
"line": 7,
"character": 0
}
},
"newText": "const a = 3;\n\nif (!a) {\n\t// type here: ()\n\tconsole.log(55);\n}\n"
}
]
formatOnType
When using formatOnType, and typing ()
after here:
, it gets reformatted to:
const a = 3;
if (!a) {// type here: ()
console.log(55);
}
2024-09-16 10:04:18.917 [info] [Trace - 10:04:18 AM] Sending notification 'textDocument/didChange'.
2024-09-16 10:04:18.917 [info] Params: {
"textDocument": {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts",
"version": 31
},
"contentChanges": [
{
"range": {
"start": {
"line": 3,
"character": 15
},
"end": {
"line": 3,
"character": 15
}
},
"rangeLength": 0,
"text": "()"
}
]
}
2024-09-16 10:04:18.919 [info] [Trace - 10:04:18 AM] Received notification 'textDocument/publishDiagnostics'.
2024-09-16 10:04:18.919 [info] Params: {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts",
"diagnostics": [],
"version": 31
}
2024-09-16 10:04:19.290 [info] [Trace - 10:04:19 AM] Sending notification 'textDocument/didChange'.
2024-09-16 10:04:19.303 [info] Params: {
"textDocument": {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts",
"version": 32
},
"contentChanges": [
{
"range": {
"start": {
"line": 3,
"character": 16
},
"end": {
"line": 3,
"character": 17
}
},
"rangeLength": 1,
"text": ")"
}
]
}
2024-09-16 10:04:19.305 [info] [Trace - 10:04:19 AM] Sending request 'textDocument/onTypeFormatting - (10)'.
2024-09-16 10:04:19.305 [info] Params: {
"textDocument": {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts"
},
"position": {
"line": 3,
"character": 17
},
"ch": ")",
"options": {
"tabSize": 4,
"insertSpaces": false
}
}
2024-09-16 10:04:19.306 [info] [Trace - 10:04:19 AM] Received notification 'textDocument/publishDiagnostics'.
2024-09-16 10:04:19.306 [info] Params: {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts",
"diagnostics": [],
"version": 32
}
2024-09-16 10:04:19.306 [info] [Trace - 10:04:19 AM] Received response 'textDocument/onTypeFormatting - (10)' in 1ms.
2024-09-16 10:04:19.307 [info] Result: [
{
"range": {
"start": {
"line": 2,
"character": 9
},
"end": {
"line": 4,
"character": 8
}
},
"newText": "// type here: ()\n\tconsole"
}
]
2024-09-16 10:04:19.315 [info] [Trace - 10:04:19 AM] Sending notification 'textDocument/didChange'.
2024-09-16 10:04:19.315 [info] Params: {
"textDocument": {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts",
"version": 33
},
"contentChanges": [
{
"range": {
"start": {
"line": 2,
"character": 9
},
"end": {
"line": 3,
"character": 1
}
},
"rangeLength": 2,
"text": ""
}
]
}
2024-09-16 10:04:19.318 [info] [Trace - 10:04:19 AM] Received notification 'textDocument/publishDiagnostics'.
2024-09-16 10:04:19.318 [info] Params: {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts",
"diagnostics": [],
"version": 33
}
2024-09-16 10:04:20.344 [info] [Trace - 10:04:20 AM] Sending notification 'textDocument/didSave'.
2024-09-16 10:04:20.344 [info] Params: {
"textDocument": {
"uri": "file:///Users/nicolas/code/repro/biome-repro-1726462751533/src/index.ts"
}
}
It looks like the textDocument/onTypeFormatting
response returns an incorrect line index.
2024-09-16 10:04:19.306 [info] [Trace - 10:04:19 AM] Received response 'textDocument/onTypeFormatting - (10)' in 1ms.
2024-09-16 10:04:19.307 [info] Result: [
{
"range": {
"start": {
"line": 2,
"character": 9
},
"end": {
"line": 4,
"character": 8
}
},
"newText": "// type here: ()\n\tconsole"
}
]
I would expect range.start.line
to be 3
here (zero-based line index).
This seems to trigger on the )
character.
VS Code version
1.93.0
Extension version
2.3.0
Biome version
1.9.0
Operating system
Description
When typing a comment line, if you input
()
within the comment, it unexpectedly moves to the end of the nearest non-empty line of code above it (please refer to the attached video).This bug does not occur with regular end-of-line comments. It is consistently reproducible only with standalone comment lines (lines starting with
//
or/* */
comment blocks).This issue arises when the Biome.js VS Code extension is enabled. To the best of my knowledge, the core @biomejs/biome package installed in
node_modules
is not related to this problem. The bug occurs when the Biome.js VS Code extension is turned on and disappears when it's turned off.Steps to reproduce
//
or/* */
.(
. The editor will likely auto-insert the closing parenthesis)
.)
.The bug occurs at the moment you manually input the closing parenthesis, even if it was already auto-inserted by the editor.
https://github.com/user-attachments/assets/3ee5ee93-bbb6-441e-ac94-28736cc56cf3
Expected behavior
Nothing should happen.
Does this issue occur when using the CLI directly?
No
Link to a minimal reproduction
No response
Logs
No response