Summary
Wire the existing Formatting LSP infrastructure to the editor so users can auto-format the current document with Shift+Alt+F.
Trigger
- Hotkey:
Shift+Alt+F - Format entire document (standard VS Code binding)
- Selection hotkey:
Ctrl+K Ctrl+F - Format selection (optional, uses range formatting)
Existing Infrastructure
| Layer |
Location |
Method |
Status |
| LSP Client |
LanguageServerClient.cs |
RequestFormattingAsync(), RequestRangeFormattingAsync() |
Exists |
| Feature Controller |
LspFeatureController.cs |
RequestFormattingAsync() |
Exists |
| Decoration Provider |
LanguageServerDecorationProvider.cs |
RequestFormattingAsync() |
Exists |
| Editor Binding |
EditorNode.cs |
Not bound |
Missing |
Implementation
1. Add Shift+Alt+F binding in SetupInputBindings (EditorNode.cs)
bindings.Shift().Alt().Key(Hex1bKey.F).Action(TriggerFormattingAsync, "Format document");
2. Add TriggerFormattingAsync method
- Call
provider.RequestFormattingAsync(tabSize, insertSpaces) with editor settings
- Receive
TextEdit[] back from the LS
- Sort edits in reverse document order (bottom-to-top) to preserve positions
- Apply each edit to the document via
State.ReplaceRange(start, end, newText)
- If
ReplaceRange does not exist, add it to EditorState
3. Apply TextEdits helper
Create a reusable ApplyTextEdits(TextEdit[]) method since rename, code actions, and formatting all need it:
private void ApplyTextEdits(TextEdit[] edits)
{
// Sort reverse to avoid position shifting
var sorted = edits.OrderByDescending(e => e.Range.Start.Line)
.ThenByDescending(e => e.Range.Start.Character);
foreach (var edit in sorted)
{
// Convert LSP 0-based positions to 1-based document positions
// Replace range with new text
}
}
4. Update README
- Document Shift+Alt+F hotkey
Visual Behavior
- User presses Shift+Alt+F
- The entire document is reformatted in-place
- Cursor position is preserved as closely as possible
Tests
- Shift+Alt+F applies formatting edits
- Edits are applied in correct reverse order
- Cursor position is preserved after formatting
- No-op when LS returns no edits
Summary
Wire the existing Formatting LSP infrastructure to the editor so users can auto-format the current document with Shift+Alt+F.
Trigger
Shift+Alt+F- Format entire document (standard VS Code binding)Ctrl+K Ctrl+F- Format selection (optional, uses range formatting)Existing Infrastructure
LanguageServerClient.csRequestFormattingAsync(),RequestRangeFormattingAsync()LspFeatureController.csRequestFormattingAsync()LanguageServerDecorationProvider.csRequestFormattingAsync()EditorNode.csImplementation
1. Add Shift+Alt+F binding in
SetupInputBindings(EditorNode.cs)2. Add
TriggerFormattingAsyncmethodprovider.RequestFormattingAsync(tabSize, insertSpaces)with editor settingsTextEdit[]back from the LSState.ReplaceRange(start, end, newText)ReplaceRangedoes not exist, add it toEditorState3. Apply TextEdits helper
Create a reusable
ApplyTextEdits(TextEdit[])method since rename, code actions, and formatting all need it:4. Update README
Visual Behavior
Tests