Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

lsp_format_document breaks formatting when executed right after editing code #2578

Open
MrFoxPro opened this issue Dec 11, 2024 · 3 comments
Labels

Comments

@MrFoxPro
Copy link

MrFoxPro commented Dec 11, 2024

lsp_format_document.mp4

Seems like server is not fast enough to parse document after change and applies formatting to old version?

Environment:

  • OS: Arch Linux 6.12.1
  • Sublime Text version: 4180
  • LSP version: 2.2.0, 2.3.0
  • Language servers used: vstls, also tried LSP-typescript package
@jwortmann
Copy link
Member

Seems like server is not fast enough to parse document after change and applies formatting to old version?

I'd say this looks more like textDocument/formatting is accidentally sent before textDocument/didChange (the didChange notification is debounced by 300 ms), so I think the server is doing the right thing. We should probably call purge_changes for the SessionBuffer before running the formatting request in

class LspFormatDocumentCommand(LspTextCommand):

and in
class LspFormatDocumentRangeCommand(LspTextCommand):

Next time ideally also post a copy of the logs directly, that would be easier than trying to read the logs from the video :)

@rchl
Copy link
Member

rchl commented Dec 11, 2024

Yes. I came to the same conclusion on discord where it was reported first

@jwortmann jwortmann added the bug label Dec 19, 2024
@du-song
Copy link

du-song commented Feb 21, 2025

I ran into a bug(?): with lsp_ruff and lsp_pyright installed,

    "lsp_format_on_save": true,
    "lsp_code_actions_on_save": {
        "source.fixAll": true,
        "source.organizeImports": true,
    },

try saving this py file

import csv
import tempfile
import shutil
import os
C = 1
class CsvExporter:
    D = os.DirEntry
    X = tempfile

becomes

import tempfile
import os
import shutil
import tempfile

    D = os.DirEntry
    X = tempfile

I was suggested on Discord that this might the same bug, any plan on fixing this?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants