@@ -151,65 +151,80 @@ Custom blink.cmp source for CSS completions in styled-component templates:
151151- Scratch buffer allows cssls to process CSS without file I/O
152152- Position mapping simplified by using insertText only
153153
154- #### 6. ` lua/styled-components/blink.lua ` ** Blink.cmp Integration** ⭐
154+ #### 6. ` lua/styled-components/blink.lua ` ** Blink.cmp Integration Helpers ** ⭐
155155
156- Utilities for integrating with blink.cmp to filter cssls completions outside styled-component context :
156+ Helper functions for integrating with blink.cmp using the ** official Provider Override API ** :
157157
158158** Why this module exists:**
159159- styled-components.nvim configures cssls to attach to TypeScript/JavaScript files (necessary for injection)
160160- blink.cmp's LSP source forwards ALL completions from ALL LSP clients without context filtering
161161- Without filtering, users see CSS completions everywhere in TS/JS files (React components, hooks, etc.)
162- - This module provides filtering to show CSS completions ONLY in styled-component templates
162+ - This module provides helper functions to filter CSS completions ONLY in styled-component templates
163163
164164** Functions:**
165165
166- ` get_lsp_transform_items() ` - Returns a transform_items function for blink.cmp's LSP source:
166+ ` enabled() ` - Smart filetype detection for source activation:
167+ - Returns ` true ` for TypeScript/JavaScript filetypes
168+ - Used by blink.cmp to determine when to activate styled-components source
169+ - Simple, efficient, no overhead
170+
171+ ` get_lsp_transform_items() ` - Returns a transform_items function for blink.cmp's LSP source override:
167172- Checks if cursor is in styled-component CSS injection region
168173- Filters out cssls completions when NOT in CSS context
169174- Allows all completions (including cssls) when IN CSS context
170- - Compatible with blink.cmp's LSP source API
171-
172- ** Usage patterns:**
175+ - Compatible with blink.cmp's Provider Override API
176+ - Robust item detection (checks multiple fields for different blink.cmp versions)
173177
174- 1 . ** Automatic Integration** (via ` init.lua:setup_blink_integration() ` ):
175- - Plugin automatically patches blink.cmp's LSP source on setup
176- - Preserves existing user ` transform_items ` if present
177- - Enabled by default via ` config.blink_integration = true `
178- - Zero user configuration required
178+ ** Usage pattern (user's config):**
179179
180- 2 . ** Manual Integration** (via ` get_lsp_transform_items() ` ):
181- - User explicitly adds to blink.cmp config:
182- ``` lua
183- providers = {
184- lsp = {
185- transform_items = require (" styled-components.blink" ).get_lsp_transform_items (),
186- },
187- }
188- ```
189- - Useful when user wants explicit control or has custom transform logic
180+ Users configure blink.cmp using these helpers:
181+ ``` lua
182+ local styled = require (" styled-components.blink" )
183+ require (" blink.cmp" ).setup ({
184+ sources = {
185+ default = { " lsp" , " path" , " snippets" , " buffer" , " styled-components" },
186+ providers = {
187+ lsp = {
188+ override = {
189+ transform_items = styled .get_lsp_transform_items (),
190+ },
191+ },
192+ [" styled-components" ] = {
193+ name = " styled-components" ,
194+ module = " styled-components.completion" ,
195+ enabled = styled .enabled ,
196+ },
197+ },
198+ },
199+ })
200+ ```
190201
191- ** Integration timing:**
192- - Auto-integration defers patching by 100ms to ensure blink.cmp is fully initialized
193- - Gracefully handles blink.cmp not being installed (silent skip)
194- - Logs debug messages when ` config.debug = true `
202+ ** Benefits of this approach:**
203+ - Uses official blink.cmp API (stable, future-proof)
204+ - No internal patching or timing issues
205+ - Transparent and easy to debug
206+ - User has full control
207+ - Zero magic, explicit configuration
195208
196209### Data Flow
197210
198211** Initialization:**
199212```
200- Plugin loads (lazy=false, priority=1000 )
213+ Plugin loads (ft = ["typescript", "typescriptreact", ...] )
201214 ↓
202215injection.setup_injection_queries()
203216 → Adds queries/*.scm to Neovim's runtimepath
204217 ↓
205218injection.setup_cssls_for_injection()
206219 → Configures cssls filetypes: ['css', 'scss', 'typescript', 'typescriptreact', ...]
207220 ↓
208- setup_blink_integration() (if blink_integration = true, default)
209- → Patches blink.cmp's LSP source to filter cssls completions
210- → Preserves existing transform_items if present
221+ User's blink.cmp config uses helpers from styled-components.blink
222+ → LSP source override: transform_items = styled.get_lsp_transform_items()
223+ → styled-components source: enabled = styled.enabled
211224 ↓
212225blink.cmp registers styled-components completion source
226+ → Uses official Provider Override API
227+ → No patching, no timing issues
213228```
214229
215230** Runtime (Completion Flow):**
0 commit comments