feat: add format middleware when applying workflow edits

Description

This MR implements an alternative approach to auto-formatting edits applied by Duo Workflow or Duo Agentic Chat. Instead of a separate RPC message flow, a new ApplyEdit middleware has been created. This allows formatting the code right at the point we make the edit, before saving the file or displaying the diff view.

This MR relies on language server changes in gitlab-org/editor-extensions/gitlab-lsp!1923 (merged), which updated the LS to send through more specific edit ranges instead of a single 0, Infinity range covering the entire document.

Related Issues

Resolves #2027 (closed)

How has this been tested?

  • Enable the new feature flag: "gitlab.featureFlags.formatEdits": true,
  • Link LS branch from gitlab-org/editor-extensions/gitlab-lsp!1923 (merged) (assuming LS has not yet neeb released / updated) (LS is now updated in main)
  • Run agentic chat, trigger some file edit which contains poor formatting (e.g. prompt Duo to "indent my code with exactly 7 spaces" or some such)
  • Verify edited code is formatted as per your IDE config
  • If src/browser or src/common has been modified, please consider interoperability with the Web IDE. See Running the Extension in WebIDE.
  • Consider an end-to-end test for significant new features that aren't covered by integration tests.

Screenshots (if appropriate)

What CHANGELOG entry will this MR create?

  • fix: Bug fix fixes - a user-facing issue in production - included in changelog
  • feature: New feature - a user-facing change which adds functionality - included in changelog
  • BREAKING CHANGE: (fix or feature that would cause existing functionality to change) - should bump major version, mentioned in the changelog
  • None - other non-user-facing changes
Edited by Elwyn Benson

Merge request reports

Loading
Loading