Skip to content

chore: extract flag parsing into declarative module#17

Open
lmn451 wants to merge 26 commits into
masterfrom
chore/update-deps
Open

chore: extract flag parsing into declarative module#17
lmn451 wants to merge 26 commits into
masterfrom
chore/update-deps

Conversation

@lmn451
Copy link
Copy Markdown
Owner

@lmn451 lmn451 commented Mar 19, 2026

Summary

  • Extract flag parsing into src/flags.ts with declarative registry
  • Add --no-color-replacement-diagnostics flag for Firefox extension
  • Add env var support for all boolean flags
  • Refactor path-display parsing to be declarative

Changes

  • src/flags.ts - New declarative flag registry
  • src/runtimeConfig.ts - Simplified to re-export from flags.ts
  • README.md - Document new flag
  • package.json - Version bump to 1.0.19

Testing

All 182 tests pass.

lmn451 added 26 commits March 18, 2026 11:13
Updates:
- css-tree: 3.1.0 → 3.2.1 (bug fixes, new parse options)
- node-html-parser: 7.0.1 → 7.1.0 (new parsing options)
- @types/node: 24.10.1 → 24.12.0 (type updates)
- vscode-languageserver-textdocument: 1.0.11 → 1.0.12
- vscode-uri: 3.0.8 → 3.1.0
- Move all flag definitions to a single declarative registry in src/flags.ts
- Supports flag types: bool, optIn, enum, pathDisplay, list, int
- Simplifies adding new flags to 3 steps (add to interface, add to FLAGS, add to return)
- Preserve all existing CLI and env var behavior
- Add --no-color-replacement-diagnostics flag for Firefox extension
- Add CSS_LSP_COLOR_REPLACEMENT_DIAGNOSTICS=0 env var
- Update parseBool to handle "0" for disabling via env
- Document env var in README
- Add try-catch blocks to color replacement functions to prevent LSP crashes
- Implement color index (Map<string, Set<string>>) for O(1) color lookups
- Replace O(n*m) iteration with direct HashMap lookup in getVariablesByColor()
- Mark index dirty when variables change, rebuild lazily on first access

Performance: Color lookup now scales with number of matches (O(k)) instead of
total variables (O(n*m)).
Replace O(n) linear search with O(k) line-bucketed lookup in
findColorLiteralAtPosition, where k = colors on target line.

Changes:
- colorLiterals now uses Map<uri, Map<line, CssColorLiteral[]>>
- Added getDocumentColorLiteralsByLine() method
- getDocumentColorLiterals() flattens for backward compatibility
- findColorLiteralAtPosition uses bucketed lookup
Move Logger interface and createLogger factory from cssVariableManager.ts
to dedicated src/logger.ts module for better separation of concerns.
CssVariableManager now requires a Logger argument.
Update all test files to import Logger and pass SilentLogger instance.
Update server.ts to use the new Logger interface instead of
connection.console. Pass logger to colorVariableFeature functions.
- Extract SilentLogger to shared test helper (tests/helpers/silentLogger.ts)
- Update 16 test files to use shared SilentLogger instead of duplicates
- Add comprehensive tests for logger module (10 tests)
- Add tsconfig.tsbuildinfo to .gitignore
- Remove untracked files (ISSUE_TEMPLATE, run-lsp.sh)
Remove dead guard code since the parameter is always provided by callers
- Fix matchesContext() to properly check selector types instead of using substring matching
- Add timeout cleanup in onDidClose to prevent memory leak
- Update test files to assert correct behavior
…locks

The valueRange property was incorrectly calculated when parsing CSS
variables in HTML <style> blocks. For complex values (rgb(), hsl(),
etc.), the code was adding an offset to css-tree positions, then
using those sums to index into the CSS text - causing out-of-bounds
substring access.

Fix: use css-tree positions directly for substring extraction, but
add offset only for document.positionAt() to get absolute positions.

Added test case for HTML style blocks to prevent regression.
Use --stdio flag to force stdio transport. Without the flag, the
library auto-detects transport from argv (--node-ipc for VS Code
extension, --socket, --pipe for other clients).

This keeps both CLI and VS Code extension working correctly.
- Remove unused htmlText field from DOMTree class
- Rename unused document param to _document in createColorReplacementCompletionItem
- Remove dead parseInt function from flags.ts (never called)
- Add eslint-disable comments for deprecated rootUri/rootPath usage
- Remove deprecated fields from debug logging in onInitialize
- Export isPositionOnDefinition helper and add tests
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