You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently astutil.PathEnclosingInterval doesn't handle enclosing node for comments correctly. Examples:
Pos on <> returns whole *ast.File as enclosing node, but should return *ast.CommentGroup.
// main is main <>funcmain() {
}
Pos on <> returns main function's *ast.BlockStmt with all statements (*ast.CommentGroup is not included in this node), but should return *ast.CommentGroup.
funcmain() {
fmt.Print("hi") // Print prints hi <>fmt.Print("bye")
}
@alandonovan What do you think we can do here? Is it fixable? Was it some requirements for other tools to work this way? Thanks a lot.
Background:
x/tools/internal/lsp uses PathEnclosingInterval for autocompletion and I was working on preventing autocompletion inside comment blocks. I made a fix for 1 case which is still kind of hacky because it traverse *ast.File and checks if node on given pos is actually *ast.Comment , but for 2 case there is no easy way to fix it and the best way would be to fix PathEnclosingInterval.
Comment handling in go/ast has been the bane of tool writers for years because they are stored off to the side. The correct solution to this problem (and a raft of others) is to make go/ast (optionally) save all comments in the tree. I don't think it should be too hard, but it will require a Go release.
As a workaround, you could seek through the File.Comments list to see whether the cursor position falls within a comment, and if so, prepend the Comment node to the path returned by PathEnclosingPosition.
Currently astutil.PathEnclosingInterval doesn't handle enclosing node for comments correctly. Examples:
By looking at unit tests I can see that this was intentional behaviour https://github.com/golang/tools/blob/master/go/ast/astutil/enclosing_test.go#L156.
@alandonovan What do you think we can do here? Is it fixable? Was it some requirements for other tools to work this way? Thanks a lot.
Background:
x/tools/internal/lsp uses PathEnclosingInterval for autocompletion and I was working on preventing autocompletion inside comment blocks. I made a fix for 1 case which is still kind of hacky because it traverse *ast.File and checks if node on given pos is actually *ast.Comment , but for 2 case there is no easy way to fix it and the best way would be to fix PathEnclosingInterval.
/cc @stamblerre
The text was updated successfully, but these errors were encountered: