feat(lsp): add document color chips with regex fallback#2533
Conversation
Implement textDocument/documentColor and colorPresentation for LSP color previews, share chip UI with the regex colorView, and keep regex as a fallback for ranges the server does not cover.
Greptile SummaryThis PR adds full LSP
Confidence Score: 5/5Safe to merge — the LSP color round-trip, regex fallback dedup, retry counter separation, and post-picker position re-validation are all implemented correctly. All previously flagged issues (shared retry counters, stale docLen snapshot, clamp01 duplication, lspChanged reference-equality false positives) are addressed. The two remaining findings are a dead null check in mapLspRange (caught downstream by from < 0) and a no-op debounced fetch on every keystroke when the server has no color provider — neither affects correctness or user-visible behavior. src/cm/lsp/documentColors.ts — the mapLspRange null check and the unconditional docChanged schedule are worth a second look, but neither blocks the feature. Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant ColorViewPlugin as ColorViewPlugin (regex)
participant LSPPlugin as DocumentColors Plugin (LSP)
participant LspField as lspDocumentColorsField
participant LSPServer as LSP Server
User->>ColorViewPlugin: open file / edit
User->>LSPPlugin: open file / edit (docChanged)
LSPPlugin->>LSPPlugin: schedule(debounce 150ms)
LSPPlugin->>LSPServer: textDocument/documentColor
LSPServer-->>LSPPlugin: ColorInformation[]
LSPPlugin->>LSPPlugin: process() map positions
LSPPlugin->>LspField: dispatch setColors effect
LspField-->>ColorViewPlugin: didReplaceLspDocumentColors true
ColorViewPlugin->>ColorViewPlugin: add visibleRanges to pendingDirty, scheduleFlush
ColorViewPlugin->>ColorViewPlugin: colorRanges() skips LSP-covered spans
ColorViewPlugin->>User: render regex chips (non-LSP spans only)
LSPPlugin->>User: render LSP chips (viewport bounds)
User->>LSPPlugin: click LSP color chip
LSPPlugin->>User: openColorPicker(seed)
User-->>LSPPlugin: picked color string
LSPPlugin->>LSPPlugin: findLiveColor() re-validates position
LSPPlugin->>LSPServer: textDocument/colorPresentation
LSPServer-->>LSPPlugin: ColorPresentation[]
LSPPlugin->>LSPPlugin: pickPresentation() scores by format match
LSPPlugin->>LSPPlugin: applyTextEdits() or label fallback
LSPPlugin->>User: dispatch doc change
Reviews (3): Last reviewed commit: "handle edge case" | Re-trigger Greptile |
Adds full LSP document color support (
textDocument/documentColor+textDocument/colorPresentation) and keeps the existing regex color preview as a fallback for colors the language server misses.