Skip to content

[scss] Display a wrong selector preview when using sibling combinators in SCSS, Less #169900

Done
microsoft/vscode-css-languageservice
#546

Description

@otomad

Type: Bug

When using both style nesting and sibling combinators (+ and ~) in SCSS or Less, VSCode will display a wrong selector preview. I've determined that this error also occurs when no extensions are running.

For example, if writing a stylesheet like this:

.foo + .bar {
    .baz & {
        color: red;
    }
}

VSCode will display a wrong selector preview like this:
image

<element class="foo">
<element class="baz">
  …
    <element class="bar">

Expect this:

<element class="baz">
  …
    <element class="foo">
    <element class="bar">

Same when using ~:
image

Expect this:

<element class="baz">
  …
    <element class="foo">
    ⋮
    <element class="bar">

VS Code version: Code 1.74.2 (e8a3071, 2022-12-20T10:29:14.590Z)
OS version: Windows_NT x64 10.0.22621
Modes:
Sandboxed: No

System Info
Item Value
CPUs Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz (8 x 2112)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) undefined
Memory (System) 11.80GB (2.37GB free)
Process Argv --crash-reporter-id 76088c10-0186-42e8-9434-fc9aba83ae2a
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492:30256859
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
vscccc:30610679
pyindex848:30577860
nodejswelcome1:30587005
2e4cg342:30602488
gswce1:30612156
3d0df643:30613357
f6dab269:30613381
fim-prod:30623723
vscsbc:30628655

Activity

  1. added
    css-less-scss
    bug
    on Dec 23, 2022
  2. added
    help wanted
    on Dec 23, 2022
  3. changed the title [-]Display a wrong selector preview when using sibling combinators in SCSS, Less[/-] [+][scss] Display a wrong selector preview when using sibling combinators in SCSS, Less[/+] on Dec 23, 2022
  4. mriiad commented on Jan 1, 2023

    @mriiad

    Martin Aeschlimann (@aeschli) Can I try to fix this please ?

  5. mriiad commented on Jan 12, 2023

    @mriiad

    Martin Aeschlimann (@aeschli) thanks for the reply, should I create a PR ?

  6. UsmanQT commented on Nov 14, 2026

    @UsmanQT

    I'm working on this and have opened microsoft/vscode-css-languageservice#546.

    With .foo + .bar { .baz & {} }, the selector printer moved only .bar under .baz and left .foo at the top level. That's because SelectorElementBuilder.processSelector detached only the last element of the parent context, and Element.cloneWithParent() copied only the ancestor path, dropping the earlier siblings of a +/~ chain. The PR fixes both and adds SCSS and Less tests for the expected output from this issue.

  7. added a commit that references this issue on Nov 26, 2026
    f272767
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