Skip to content
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

Would we add pos to ast source property #251

Open
HairyRabbit opened this issue Dec 14, 2021 · 7 comments
Open

Would we add pos to ast source property #251

HairyRabbit opened this issue Dec 14, 2021 · 7 comments

Comments

@HairyRabbit
Copy link

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?

@alexander-akait
Copy link
Collaborator

Why you need this on mode.source property? Can you show AST which you expected?

@HairyRabbit
Copy link
Author

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 }
  }
}

@alexander-akait
Copy link
Collaborator

But you can calculate them

@HairyRabbit
Copy link
Author

sure, but I think it can implement when parse, or any api provide like ts.getPositionFromLineAndColumn

@alexander-akait
Copy link
Collaborator

hm, do you need offset, because we have https://github.com/postcss/postcss-selector-parser/blob/master/src/parser.js#L49

@HairyRabbit
Copy link
Author

yes, I fork the code then add TOKEN.START_POS to getSource function and do some update with getTokenSource, looks fine for me.

@alexander-akait
Copy link
Collaborator

PR welcome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants