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
Please sign in to leave a 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 aCSS_RULESET_LIST
as a child, which further contains aCSS_RULESET
. This, in turn, includes aCSS_SELECTOR_LIST
and the selector element itself with the classname “foo”.To get all nested classnames like
foo-bar
andfoo-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