biomejs/biome-vscode

๐Ÿ› Format on save doesn't work if "editor.formatOnSaveMode" is set to "modifications"

Closed this issue ยท 3 comments

Extension version

2.1.2

Biome version

1.5.3

Operating system

  • Windows
  • macOS
  • Linux

Description

I'm not sure if it's indeed a bug or just a design decision, or maybe some incompatibility, but if you add "editor.formatOnSaveMode": "modifications" to your vscode settings, formatting on save stops working completely.

No suspect errors or warnings, I spent quite some time until I figure out that this option was breaking the extension. It would be good if we can add some info to the docs

764e5121-7526-46e9-bd80-efda59bb9b9e.mp4

Steps to reproduce

  1. Create a .vscode/settings.json file
{
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": "explicit",
    "source.organizeImports.biome": "explicit",
    "quickfix.biome": "explicit"
  },
  "editor.defaultFormatter": "biomejs.biome",
  "editor.formatOnSaveMode": "modifications"
}
  1. Try to format any file

Expected behavior

I expect the file to be formatted accordingly

Does this issue occur when using the CLI directly?

No

Logs

[Trace - 2:09:30 AM] Sending notification 'textDocument/didChange'.
Params: {
    "textDocument": {
        "uri": "file:///Users/luizfelicio/projects/personal/my-life/src/index.tsx",
        "version": 3
    },
    "contentChanges": [
        {
            "range": {
                "start": {
                    "line": 12,
                    "character": 0
                },
                "end": {
                    "line": 12,
                    "character": 0
                }
            },
            "rangeLength": 0,
            "text": "\n"
        }
    ]
}


[Trace - 2:09:30 AM] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "diagnostics": [],
    "uri": "file:///Users/luizfelicio/projects/personal/my-life/src/index.tsx",
    "version": 3
}


[Trace - 2:09:30 AM] Sending request 'textDocument/codeAction - (4)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/luizfelicio/projects/personal/my-life/src/index.tsx"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 23,
            "character": 0
        }
    },
    "context": {
        "diagnostics": [],
        "only": [
            "source.fixAll.eslint"
        ],
        "triggerKind": 2
    }
}


[Trace - 2:09:30 AM] Received response 'textDocument/codeAction - (4)' in 2ms.
Result: []


[Trace - 2:09:30 AM] Sending request 'textDocument/codeAction - (5)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/luizfelicio/projects/personal/my-life/src/index.tsx"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 23,
            "character": 0
        }
    },
    "context": {
        "diagnostics": [],
        "only": [
            "source.organizeImports.biome"
        ],
        "triggerKind": 2
    }
}


[Trace - 2:09:30 AM] Received response 'textDocument/codeAction - (5)' in 2ms.
Result: []


[Trace - 2:09:30 AM] Sending request 'textDocument/codeAction - (6)'.
Params: {
    "textDocument": {
        "uri": "file:///Users/luizfelicio/projects/personal/my-life/src/index.tsx"
    },
    "range": {
        "start": {
            "line": 0,
            "character": 0
        },
        "end": {
            "line": 23,
            "character": 0
        }
    },
    "context": {
        "diagnostics": [],
        "only": [
            "quickfix.biome"
        ],
        "triggerKind": 2
    }
}


[Trace - 2:09:30 AM] Received response 'textDocument/codeAction - (6)' in 2ms.
Result: []


[Trace - 2:09:30 AM] Sending notification 'textDocument/didSave'.
Params: {
    "textDocument": {
        "uri": "file:///Users/luizfelicio/projects/personal/my-life/src/index.tsx"
    }
}

Hey @luizeboli,

Setting editor.formatOnSaveMode to modifications requires source control to be enabled, and it won't work without it.

If you haven't already, could you run git init in your project and try again?

Screen.Recording.2024-02-17.at.07.36.44.mov

@nhedger I totally missed that ๐Ÿ˜… ... thanks for your explanation, it's working correctly. No bugs here..

Thanks, I appreciate the feedback!