Skip to content

feat: peek into <style> blocks in HTML/Vue files (#151)#163

Merged
pranaygp merged 1 commit into
masterfrom
worktree-agent-aef08144dae59f3d9
May 17, 2026
Merged

feat: peek into <style> blocks in HTML/Vue files (#151)#163
pranaygp merged 1 commit into
masterfrom
worktree-agent-aef08144dae59f3d9

Conversation

@pranaygp
Copy link
Copy Markdown
Owner

Summary

Closes #151

Adds same-file CSS support: when peeking from a class="...", id="...", or HTML tag in an HTML or Vue document, the extension now also resolves selectors defined in any <style> block within the same file.

  • New server/src/core/embeddedStyles.ts uses vscode-html-languageservice's scanner (already a dep) to locate <style> regions and reads any lang="scss|sass|less" attribute to pick the right CSS parser.
  • The embedded virtual TextDocument reuses the host document's URI and masks everything outside the <style> region with whitespace (preserving newlines), so symbol positions line up exactly with the host file — peek/goto jumps to the correct line without any coordinate translation.
  • findSymbols/findDefinition accept an optional in-memory embeddedStylesheetMap that's merged with the persistent StylesheetMap. The persistent cache wins on key collision; embedded entries use fragment-suffixed keys so collisions don't happen in practice.
  • Only runs for html and vue documents — JS/TS/etc. peek paths are unchanged.

Test plan

  • yarn build passes with zero TS errors
  • yarn lint passes
  • yarn test — 27 tests pass, including three new cases:
    • class defined in <style> block is found in the same HTML file
    • id defined in <style> block is found in the same HTML file
    • non-HTML/Vue documents yield no embedded stylesheets
  • Fixture tests/fixture/example.html updated with a <style> block containing .embedded-class and #embedded-id plus matching usages in the body

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings May 16, 2026 20:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for resolving CSS selectors defined in embedded <style> blocks within the same HTML/Vue document, enabling Peek/Go to Definition to jump directly to in-file styles (addressing #151 / “Same File CSS”).

Changes:

  • Added embedded <style> block extraction for html/vue documents using vscode-html-languageservice scanning and creation of masked “virtual” CSS documents aligned to host offsets.
  • Extended findSymbols / findDefinition to accept an optional in-memory embedded stylesheet map merged with the existing persistent stylesheet cache.
  • Added/updated tests and fixtures to validate same-file class/id resolution and to ensure non-HTML/Vue documents don’t produce embedded stylesheets.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/src/core/embeddedStyles.ts New helper to scan HTML/Vue docs for <style> blocks and produce aligned virtual TextDocuments for symbol extraction.
server/src/core/findDefinition.ts Adds optional embedded stylesheet map support and merges it with the persistent stylesheet cache for symbol/definition lookup.
server/src/server.ts Integrates embedded <style> lookup into the LSP onDefinition path for HTML/Vue documents.
tests/src/findDefinition.test.ts Adds coverage for same-file embedded <style> class/id definitions and non-html/vue behavior.
tests/fixture/example.html Extends fixture with an embedded <style> block and matching usages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Adds support for resolving CSS class and ID selectors that are defined in
an embedded `<style>` block within the same HTML or Vue file as the source.

The HTML language service scanner is used to extract `<style>` regions
(respecting `lang="scss|less|sass"` so we pick the right CSS parser), and
the embedded contents are wrapped in a virtual TextDocument whose text
outside the style region is masked with whitespace. That preserves line
and column offsets so peek/goto jumps to the correct line in the host
file without any coordinate translation. Only runs for `html` and `vue`
languageIds, so non-HTML peek paths are unaffected.

Closes #151

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@pranaygp pranaygp force-pushed the worktree-agent-aef08144dae59f3d9 branch from b30df3f to e65c0ab Compare May 17, 2026 00:36
@pranaygp pranaygp merged commit 903e6a8 into master May 17, 2026
2 checks passed
@pranaygp pranaygp deleted the worktree-agent-aef08144dae59f3d9 branch May 17, 2026 00:37
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.

Same File CSS

2 participants