Skip to content

fix(lsp): honor per-server formatting toggle#1958

Merged
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/lsp-formatting-toggle
Mar 17, 2026
Merged

fix(lsp): honor per-server formatting toggle#1958
bajrangCoder merged 2 commits intoAcode-Foundation:mainfrom
bajrangCoder:fix/lsp-formatting-toggle

Conversation

@bajrangCoder
Copy link
Member

No description provided.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 17, 2026

Greptile Summary

This PR implements per-server control over the built-in LSP formatting feature by introducing a formatting flag in BuiltinExtensionsConfig. When formatting: false is set for a server, its keyboard shortcut (formatKeymap) is omitted from the editor keymaps, the server is skipped in formatDocument iteration, and its languages are excluded from the Acode formatter registration.

The previously duplicated supportsBuiltinFormatting helper (noted in a prior review) has been extracted into a new formattingSupport.ts module and imported in both clientManager.ts and formatter.ts, correctly eliminating the dual-maintenance risk.

Key changes:

  • New src/cm/lsp/formattingSupport.ts — shared supportsBuiltinFormatting predicate.
  • types.ts — adds formatting?: boolean to BuiltinExtensionsConfig.
  • clientManager.ts — conditionally includes formatKeymap in keymaps; guards formatDocument loop with supportsBuiltinFormatting; passes formatting flag into buildBuiltinExtensions.
  • formatter.ts — filters servers by supportsBuiltinFormatting during language-set registration and during the pre-check in the formatter callback.

Confidence Score: 5/5

  • This PR is safe to merge — the changes are well-scoped, address a prior review comment, and introduce no new risk.
  • All three enforcement points (keymap exclusion, formatDocument loop guard, formatter registration) are consistent with each other and with the shared supportsBuiltinFormatting predicate. The flag defaults to true, preserving existing behaviour for servers that omit it. No logic gaps or edge-case regressions were identified.
  • No files require special attention.

Important Files Changed

Filename Overview
src/cm/lsp/formattingSupport.ts New shared utility module extracting supportsBuiltinFormatting into a single source of truth, directly addressing the prior review comment about duplication.
src/cm/lsp/types.ts Adds formatting?: boolean to BuiltinExtensionsConfig — minimal, correct change to the interface that enables the per-server toggle.
src/cm/lsp/clientManager.ts Guards formatDocument loop with supportsBuiltinFormatting, conditionally includes formatKeymap in keymaps, and threads the formatting flag through buildBuiltinExtensions; logic is sound.
src/cm/lsp/formatter.ts Filters out formatting-disabled servers both during language-set construction and in the pre-check before delegating to lspClientManager.formatDocument; clean and consistent.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User triggers format] --> B[formatter.ts callback]
    B --> C{metadata available?}
    C -- No --> D[toast: LSP formatter unavailable]
    C -- Yes --> E{languageId resolved?}
    E -- No --> F[toast: Unknown language]
    E -- Yes --> G[getServersForLanguage\n.filter supportsBuiltinFormatting]
    G --> H{servers.length > 0?}
    H -- No --> I[toast: No LSP formatter available]
    H -- Yes --> J[lspClientManager.formatDocument]

    J --> K[getServersForLanguage]
    K --> L{supportsBuiltinFormatting?}
    L -- No --> M[skip server]
    L -- Yes --> N[ensureClient]
    N --> O{documentFormattingProvider\ncapability?}
    O -- No --> M
    O -- Yes --> P[send textDocument/formatting]
    P --> Q{edits returned?}
    Q -- No --> R[return true no-op]
    Q -- Yes --> S[applyTextEdits]
    S --> T[return true]

    style D fill:#f99
    style F fill:#f99
    style I fill:#f99
    style M fill:#eee
Loading

Last reviewed commit: fb40b99

@bajrangCoder
Copy link
Member Author

@greptileai

@bajrangCoder bajrangCoder merged commit 645c353 into Acode-Foundation:main Mar 17, 2026
7 checks passed
@bajrangCoder bajrangCoder deleted the fix/lsp-formatting-toggle branch March 17, 2026 12:47
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 this pull request may close these issues.

1 participant