-
Notifications
You must be signed in to change notification settings - Fork 56
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
question: support/implement positions for dst nodes and decorations? #38
Comments
Hi @lwsanty, yes - this comment is incorrect. This file was forked from the ast.go in the standard library and it looks like I forgot to update this doc. Since in |
@dave using I was considering running file restorer and mapping the current cursor position to Could you please tell me if it makes sense? The background of my research is to check if it's possible to use If positions were preserved or could be easily restored using |
When the restorer runs, decorations are converted to comments, which do have positions I think, however I don't think there's any mapping from decorations to comments, so locating the comment corresponding to a particular decoration might be problematic. The other problem you might come across is that the dst decorate / restore functions are probably very slow. At no time did I ever think about optimising them for performance and I assume they're very slow compared to the ast parser / printer. |
I'm still a little hazy on what exactly you want to do... Perhaps you can explain some more and maybe there's an easy way that I'm not thinking of right now... |
@dave eventually I wanted to implement a refactoring tool that does the next steps
The So I was considering using |
The problem is that If you need the position of a |
That would be indeed useful knowing the original position when the source file was parsed. I also would like to have it, in my case in order to use line directives. |
If you want the position in the input file of an AST node that corresponds to a DST node, then I believe restorer.Map will help... you can look up the AST node and use the Pos() method? |
Thanks @dave for the clue! The func getPos(restorer *decorator.Restorer, structType *dst.StructType) *token.Pos {
astNode := restorer.Map.Ast.Nodes[structType]
if astNode != nil {
pos := astNode.Pos()
return &pos
}
return nil
} |
could you please help me to figure out one thing?
in the docs here
dst/dst.go
Line 24 in e3c2080
it is said that
but at the same time the interface and it's implementations do not contain this method at all.
I have a doubt if dst nodes contain positions at all
If there're no positions provided, what approach would you suggest in implementing them?
The text was updated successfully, but these errors were encountered: