postcss-selector-parser
postcss-selector-parser copied to clipboard
Would we add `pos` to ast source property
Hi, I write a vsc extension want to implement go to definition, it require position info. I see that token already has pos property, would we also add to node.source filed?
Why you need this on mode.source property? Can you show AST which you expected?
I write css code in js via template string, like
const style = css`
.foo { color: red; }
`
style.foo
// ^---- click foo will jump to `.foo` selector
the tss.getDefinitionAndBoundSpan require position info,
interface LanguageService {
getDefinitionAtPosition(fileName: string, position: number): readonly DefinitionInfo[] | undefined;
getDefinitionAndBoundSpan(fileName: string, position: number): DefinitionInfoAndBoundSpan | undefined;
}
I need comput position base on template string node, css rule and selector. So I hope selector parser can provide offset just like postcss:
{
source: {
start: { offset: 0, line: 1, column: 1 }
}
}
But you can calculate them
sure, but I think it can implement when parse, or any api provide like ts.getPositionFromLineAndColumn
hm, do you need offset, because we have https://github.com/postcss/postcss-selector-parser/blob/master/src/parser.js#L49
yes, I fork the code then add TOKEN.START_POS to getSource function and do some update with getTokenSource, looks fine for me.
PR welcome