aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/cache/parse.go
diff options
context:
space:
mode:
authorRobert Findley <rfindley@google.com>2022-05-12 15:59:22 -0400
committerRobert Findley <rfindley@google.com>2022-06-01 19:19:15 +0000
commit9e1d19b13e1ca9d45d9378b34f139f32c2f1c994 (patch)
treebf52902807ba42ba515d7f0c3c73becd1566c384 /internal/lsp/cache/parse.go
parentdae3f4bf3c337d6972fe56c81a811a5ab7f81d41 (diff)
downloadgolang-x-tools-9e1d19b13e1ca9d45d9378b34f139f32c2f1c994.tar.gz
internal/span: eliminate TokenConverter
The TokenConverter has been trimmed down to a thin wrapper around token.File, and can now be removed. Change-Id: I9985492274c88e6a13e6d62dadab5595c75c7840 Reviewed-on: https://go-review.googlesource.com/c/tools/+/406134 TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'internal/lsp/cache/parse.go')
-rw-r--r--internal/lsp/cache/parse.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go
index 1ab1fa9e5..668c437f5 100644
--- a/internal/lsp/cache/parse.go
+++ b/internal/lsp/cache/parse.go
@@ -331,9 +331,9 @@ func parseGo(ctx context.Context, fset *token.FileSet, fh source.FileHandle, mod
File: file,
Tok: tok,
Mapper: &protocol.ColumnMapper{
- URI: fh.URI(),
- Converter: span.NewTokenConverter(tok),
- Content: src,
+ URI: fh.URI(),
+ TokFile: tok,
+ Content: src,
},
ParseErr: parseErr,
},
@@ -764,7 +764,7 @@ func walkASTWithParent(n ast.Node, f func(n ast.Node, parent ast.Node) bool) {
// fixSrc attempts to modify the file's source code to fix certain
// syntax errors that leave the rest of the file unparsed.
-func fixSrc(f *ast.File, tok *token.File, src []byte) (newSrc []byte) {
+func fixSrc(f *ast.File, tf *token.File, src []byte) (newSrc []byte) {
walkASTWithParent(f, func(n, parent ast.Node) bool {
if newSrc != nil {
return false
@@ -772,9 +772,9 @@ func fixSrc(f *ast.File, tok *token.File, src []byte) (newSrc []byte) {
switch n := n.(type) {
case *ast.BlockStmt:
- newSrc = fixMissingCurlies(f, n, parent, tok, src)
+ newSrc = fixMissingCurlies(f, n, parent, tf, src)
case *ast.SelectorExpr:
- newSrc = fixDanglingSelector(n, tok, src)
+ newSrc = fixDanglingSelector(n, tf, src)
}
return newSrc == nil
@@ -937,8 +937,8 @@ func fixEmptySwitch(body *ast.BlockStmt, tok *token.File, src []byte) {
// To fix completion at "<>", we insert a real "_" after the "." so the
// following declaration of "x" can be parsed and type checked
// normally.
-func fixDanglingSelector(s *ast.SelectorExpr, tok *token.File, src []byte) []byte {
- if !isPhantomUnderscore(s.Sel, tok, src) {
+func fixDanglingSelector(s *ast.SelectorExpr, tf *token.File, src []byte) []byte {
+ if !isPhantomUnderscore(s.Sel, tf, src) {
return nil
}
@@ -946,7 +946,7 @@ func fixDanglingSelector(s *ast.SelectorExpr, tok *token.File, src []byte) []byt
return nil
}
- insertOffset, err := safetoken.Offset(tok, s.X.End())
+ insertOffset, err := safetoken.Offset(tf, s.X.End())
if err != nil {
return nil
}
@@ -973,8 +973,8 @@ func fixDanglingSelector(s *ast.SelectorExpr, tok *token.File, src []byte) []byt
// yields a "_" selector instead of "var" since "var" is a keyword.
//
// TODO(rfindley): should this constitute an ast 'fix'?
-func fixPhantomSelector(sel *ast.SelectorExpr, tok *token.File, src []byte) {
- if !isPhantomUnderscore(sel.Sel, tok, src) {
+func fixPhantomSelector(sel *ast.SelectorExpr, tf *token.File, src []byte) {
+ if !isPhantomUnderscore(sel.Sel, tf, src) {
return
}
@@ -988,7 +988,7 @@ func fixPhantomSelector(sel *ast.SelectorExpr, tok *token.File, src []byte) {
return
}
- maybeKeyword := readKeyword(sel.Sel.Pos(), tok, src)
+ maybeKeyword := readKeyword(sel.Sel.Pos(), tf, src)
if maybeKeyword == "" {
return
}