how to get all class name in scss file

Answered

There is a scss file like this 

.foo{
 &-bar{
 	&-baz {}
 }
}

I try to use 

PsiTreeUtil.findChildrenOfType(stylesheetFile , CssClass.class);

Through PsiTreeUtil  i get classname is ["foo"] , but i hope get “foo” and “foo-bar” and “foo-bar-baz”,  what should i do ?  pls 

0
1 comment

Hello!

The function PsiTreeUtil.findChildrenOfType() returns depth first elements of provided type. If you'll open PSI Viewer(how to open PSI viewer ), you'll see that element for stylesheetFile contains a CSS_RULESET_LIST as a child, which further contains a CSS_RULESET. This, in turn, includes a CSS_SELECTOR_LIST and the selector element itself with the classname “foo”.

To get all nested classnames like foo-bar and foo-bar-baz, you need to traverse the elements tree and collect the IDs at each level. So, classnames concatenation must be done “manually”.

If you have any questions, please ask

1

Please sign in to leave a comment.