Unreviewed changes
5 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: gopls/internal/golang/type_definition.go
Insertions: 1, Deletions: 1.
@@ -31,7 +31,7 @@
if err != nil {
return nil, err
}
- cur, _, _, _ := astutil.Select(pgf.Cursor, start, end) // can't happen
+ cur, _, _, _ := astutil.Select(pgf.Cursor(), start, end) // can't fail (start, end are within File)
// Find innermost enclosing expression that has a type.
// It needn't be an identifier.
@@ -66,8 +66,6 @@
if t == nil {
return nil, fmt.Errorf("no enclosing expression has a type")
}
- // TODO(hxjiang, adnonvan): check the ergonomics in language clients (VSCode,
- // vim, emacs) and support basic types.
tnames := typeToObjects(t)
if len(tnames) == 0 {
return nil, fmt.Errorf("cannot find type name(s) from type %s", t)
```
```
The name of the file: internal/astutil/util.go
Insertions: 3, Deletions: 2.
@@ -179,7 +179,7 @@
// Select returns the enclosing BlockStmt, the f() CallExpr, and the g() CallExpr.
//
// If the selection does not wholly enclose any nodes, Select returns an error
-// and invalid stsrt/end nodes, but it may return a valid enclosing node.
+// and invalid start/end nodes, but it may return a valid enclosing node.
//
// Callers that require exactly one syntax tree (e.g. just f() or just
// g()) should check that the returned start and end nodes are
@@ -219,7 +219,8 @@
if !CursorValid(curStart) {
// The selection is valid (inside curEnclosing) but contains no
// complete nodes. This happens for point selections (start == end),
- // or selections covering only tokens/whitespace.
+ // or selections covering only only spaces, comments, and punctuation
+ // tokens.
// Return the enclosing node so the caller can still use the context.
return curEnclosing, noCursor, noCursor, fmt.Errorf("invalid selection")
}
```
Change information
Commit message:
internal/astutil: return enclosing node when selection contains no nodes
Previously, if a selection range did not wholly enclose any syntax nodes
(e.g., point selections or ranges covering only whitespace), Select
returned an error with all noCursor return values.
Select now returns the valid enclosing cursor alongside the error in
these cases, while keeping start and end as noCursor.
This allows callers to inspect the surrounding syntax tree even when the
selection does not map to specific sub-nodes.
Change-Id: I623cd5bc1b4173970ad1dc3e7baae79aa74cc5de
Files:
- M gopls/internal/golang/type_definition.go
- M internal/astutil/util.go
Change size: S
Delta: 2 files changed, 10 insertions(+), 5 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Code-Review: +2 by Alan Donovan
TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI