mirror of https://github.com/golang/go.git
internal/lsp/source: support completing "range" keyword
We now offer "range" keyword in the for loop init statement: for i := r<> // offer "range" completion candidate Updates golang/go#34009. Change-Id: I2e4c1db11c37127406c78191681c39b9dd3439f7 Reviewed-on: https://go-review.googlesource.com/c/tools/+/220504 Run-TryBot: Muir Manders <muir@mnd.rs> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
2047c2d578
commit
11ec41452d
|
|
@ -86,6 +86,14 @@ func (c *completer) addKeywordCompletions() {
|
|||
return
|
||||
}
|
||||
|
||||
if len(c.path) > 2 {
|
||||
// Offer "range" if we are in ast.ForStmt.Init. This is what the
|
||||
// AST looks like before "range" is typed, e.g. "for i := r<>".
|
||||
if loop, ok := c.path[2].(*ast.ForStmt); ok && nodeContains(loop.Init, c.pos) {
|
||||
addKeywords(stdScore, RANGE)
|
||||
}
|
||||
}
|
||||
|
||||
// Only suggest keywords if we are beginning a statement.
|
||||
switch c.path[1].(type) {
|
||||
case *ast.BlockStmt, *ast.CommClause, *ast.CaseClause, *ast.ExprStmt:
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ func _() {
|
|||
v //@complete(" //", var)
|
||||
c //@complete(" //", const)
|
||||
|
||||
for i := r //@complete(" //", range)
|
||||
}
|
||||
|
||||
/* package */ //@item(package, "package", "", "keyword")
|
||||
|
|
@ -90,3 +91,4 @@ func _() {
|
|||
/* map */ //@item(map, "map", "", "keyword")
|
||||
/* func */ //@item(func, "func", "", "keyword")
|
||||
/* chan */ //@item(chan, "chan", "", "keyword")
|
||||
/* range */ //@item(range, "range", "", "keyword")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
-- summary --
|
||||
CodeLensCount = 0
|
||||
CompletionsCount = 229
|
||||
CompletionsCount = 230
|
||||
CompletionSnippetCount = 68
|
||||
UnimportedCompletionsCount = 11
|
||||
DeepCompletionsCount = 5
|
||||
|
|
|
|||
Loading…
Reference in New Issue