Skip to content

🔨 Include both <sth> and <element name="sth"> in hover #299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 16 additions & 19 deletions src/services/selectorPrinting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,32 +168,29 @@ class MarkedStringPrinter {
}

// the real deal
const content = ['<'];

// element name
const content = [];
if (name) {
content.push(name);
} else {
content.push('element');
content.push(this.prepareElement(name, element.attributes?.filter(x => x.name !== 'name')));
}
content.push(this.prepareElement('element', element.attributes));
this.writeLine(indent, content.join('|'));
}

// attributes
if (element.attributes) {
for (const attr of element.attributes) {
if (attr.name !== 'name') {
content.push(' ');
content.push(attr.name);
const value = attr.value;
if (value) {
content.push('=');
content.push(quotes.ensure(value, this.quote));
}
private prepareElement(name: string, attributes?: Element['attributes']): string {
const content = [`<${name}`];
if (attributes) {
for (const attr of attributes) {
content.push(' ');
content.push(attr.name);
const value = attr.value;
if (value) {
content.push('=');
content.push(quotes.ensure(value, this.quote));
}
}
}
content.push('>');

this.writeLine(indent, content.join(''));
return content.join('');
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/test/css/hover.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ suite('CSS Hover', () => {
'[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)'
]
});
assertHover('[name="something"] { color: blue; }', {
contents: [
{ language: 'html', value: '<something>|<element name="something">' },
'[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)'
]
});
assertHover('[attr="something"] { color: blue; }', {
contents: [
{ language: 'html', value: '<element attr="something">' },
'[Selector Specificity](https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity): (0, 1, 0)'
]
});
});
});

Expand Down