-
Notifications
You must be signed in to change notification settings - Fork 124
Fix/40149: add data-* attributes autocomplete #17
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
Conversation
Add two test cases
Extract code to function.
src/services/htmlCompletion.ts
Outdated
const dataAttr = 'data-'; | ||
let dataAttributes: string[] = []; | ||
|
||
function addNodeDataAttributes(node: Node) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could try a non-recursive approach
src/services/htmlCompletion.ts
Outdated
let dataAttributes: string[] = []; | ||
|
||
function addNodeDataAttributes(node: Node) { | ||
node.attributeNames.filter(attr => attr.substr(0, dataAttr.length) === dataAttr).forEach(attr => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest doing a single forEach loop (no filter
)
use startsWith
from ../utils/strings
for the check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the review 👍
src/services/htmlCompletion.ts
Outdated
|
||
function addNodeDataAttributes(node: Node) { | ||
node.attributeNames.filter(attr => attr.substr(0, dataAttr.length) === dataAttr).forEach(attr => { | ||
if (dataAttributes.indexOf(attr) === -1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use a object or Map to check for extistece
if (!dataAttributes['attr']) {
dataAttributes['attr'] = true;
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok I'll make the modification ASAP
@aeschli requested modifications applied. |
@pfongkye Thanks, great PR! |
This issue is referenced here: microsoft/vscode#40149