Skip to content

Add support for the "textDocument/formatting" verb #576

New issue

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

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

Already on GitHub? Sign in to your account

Closed
vonlost opened this issue Jun 29, 2022 · 6 comments · Fixed by #769
Closed

Add support for the "textDocument/formatting" verb #576

vonlost opened this issue Jun 29, 2022 · 6 comments · Fixed by #769

Comments

@vonlost
Copy link

vonlost commented Jun 29, 2022

Sorry if this request is covered elsewhere.

@ahoppen
Copy link
Member

ahoppen commented Jun 29, 2022

I don’t think we’ve got a bug report for this. It’s very related to #496.

@ahoppen
Copy link
Member

ahoppen commented Jun 29, 2022

rdar://96159694

@fwcd
Copy link
Member

fwcd commented Jul 5, 2022

I think the DocumentFormattingRequest represents this LSP method, there is some ongoing work at #361 to implement this via swift-format.

@siegel
Copy link
Contributor

siegel commented Jul 5, 2022

@fwcd which version of Xcode does this correspond to?

As of Xcode 13.4 (13F17a), sourcekit-lsp is not advertising support for textDocument/formatting in its capabilities:

{
    codeActionProvider =     {
    };
    colorProvider = 1;
    completionProvider =     {
        resolveProvider = 0;
        triggerCharacters =         (
            "."
        );
    };
    definitionProvider = 1;
    documentHighlightProvider = 1;
    documentSymbolProvider = 1;
    executeCommandProvider =     {
        commands =         (
            "semantic.refactor.command"
        );
    };
    foldingRangeProvider = 1;
    hoverProvider = 1;
    implementationProvider = 1;
    referencesProvider = 1;
    textDocumentSync =     {
        change = 2;
        openClose = 1;
        save =         {
            includeText = 0;
        };
        willSave = 1;
        willSaveWaitUntil = 0;
    };
    workspaceSymbolProvider = 1;
}

@fwcd
Copy link
Member

fwcd commented Jul 5, 2022

Yes, IIUC the provider is not registered since the request is yet to be implemented (WIP at #361), only the request structures have been merged already.

gnomesysadmins pushed a commit to GNOME/gnome-builder that referenced this issue Feb 18, 2023
@t-benze
Copy link

t-benze commented Jun 1, 2023

For anyone having the problem that sourcekit is not able to perform the code format action. If you happen to use neovim, there's one working solution (as a workaround) using this null-ls plugin.

There're a few steps to set up:

  1. follow the instruction to install swift-format.
  2. make sure the swift-format executable is locatable from $PATH.
  3. install the null-ls neovim plugin and configure swift-format, for example
local null_ls = require("null-ls")
local swift_format = require("null-ls.builtins.formatting.swift-format")
null_ls.register({swift_format})

ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Jul 13, 2023
Since swift-syntax no longer depends on the C++ parser library and thus swift-format also doesn’t, we can use swift-format to format an entire document.

Fixes swiftlang#576
rdar://96159694
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Jul 13, 2023
Since swift-syntax no longer depends on the C++ parser library and thus swift-format also doesn’t, we can use swift-format to format an entire document.

Fixes swiftlang#576
rdar://96159694
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Jul 13, 2023
Since swift-syntax no longer depends on the C++ parser library and thus swift-format also doesn’t, we can use swift-format to format an entire document.

Fixes swiftlang#576
rdar://96159694
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Jan 18, 2024
Depend on the swift-format library to discover and write the swift-format configuration file. Invoke swift-format from the toolchain to actually format a document. This makes sure that the formatting of SourceKit-LSP and the swift-format executable in the toolchain never get out of sync.

Fixes swiftlang#576
rdar://96159694
ahoppen added a commit to ahoppen/sourcekit-lsp that referenced this issue Jan 24, 2024
Depend on the swift-format library to discover and write the swift-format configuration file. Invoke swift-format from the toolchain to actually format a document. This makes sure that the formatting of SourceKit-LSP and the swift-format executable in the toolchain never get out of sync.

Fixes swiftlang#576
rdar://96159694
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants