Skip to content

[css] Wrong selector hover when using :has()  #191897

Open

Description

@vincent-octo

Type: Bug

Set language to CSS.

Put this code:

article:has(.alert) {
	color: crimson;
}

Hover over article:has(.alert).

This dialog shows a wrong HTML example:

<article :has>

Instead, it could be:

<article>
  <div class="alert"></div>
</article>

VS Code version: Code 1.80.1 (74f6148, 2023-07-12T17:20:58.115Z)
OS version: Darwin arm64 21.6.0
Modes: Restricted

Activity

  1. vscodenpa commented on Aug 31, 2023

    @vscodenpa

    Thanks for creating this issue! It looks like you may be using an old version of VS Code, the latest stable release is 1.81.1. Please try upgrading to the latest version and checking whether this issue remains.

    Happy Coding!

  2. added
    css-less-scss
    on Aug 31, 2023
  3. added
    bug
    on Aug 31, 2023
  4. changed the title [-]Wrong HTML example when using CSS :has() [/-] [+][css] Wrong selector hover when using :has() [/+] on Aug 31, 2023
  5. added
    help wanted
    on Dec 11, 2024
  6. UsmanQT commented on Nov 14, 2026

    @UsmanQT

    Hi Martin Aeschlimann (@aeschli), I'd like to work on this. Before changing anything, I want to check the intended output, since selectorPrinting.test.ts currently asserts <element id="s12" :has>.

    Proposal for :has(): render the argument as a descendant of the subject element, e.g. article:has(.alert) →

    <article>
      …
        <element class="alert">

    and for :has(> .alert) show it as a direct child (no …). For a selector list like :has(.a, .b) I'd use only the first entry.

    For :not(), :is() and :where() I'd leave the current rendering alone in this change (microsoft/vscode-css-languageservice#169 covers :not() separately).

    Does that match what you'd accept? If so I'll open a PR in vscode-css-languageservice with updated tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcss-less-scsshelp wanted

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions