Skip to content

Would we add pos to ast source property #251

Description

@HairyRabbit

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?

Activity

  1. alexander-akait commented on Dec 14, 2021

    @alexander-akait
    Collaborator

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

  2. HairyRabbit commented on Dec 14, 2021

    @HairyRabbit
    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 }
      }
    }
  3. alexander-akait commented on Dec 14, 2021

    @alexander-akait
    Collaborator

    But you can calculate them

  4. HairyRabbit commented on Dec 14, 2021

    @HairyRabbit
    Author

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

  5. alexander-akait commented on Dec 14, 2021

    @alexander-akait
    Collaborator
  6. HairyRabbit commented on Dec 14, 2021

    @HairyRabbit
    Author

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

  7. alexander-akait commented on Dec 14, 2021

    @alexander-akait
    Collaborator

    PR welcome

  8. deepanshupal commented on Sep 26, 2026

    @deepanshupal

    I'd like to add absolute offsets to parsed node source positions for #251, using the token positions already produced by the tokenizer. I will cover multiline and nested selectors, plus the public type declaration, before opening a draft PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions