mirror of https://github.com/golang/go.git
internal/lsp/cache: kill unused func fixAccidentalDecl
I think I resurrected this accidentally when resolving a merge conflict. Change-Id: Ib871068902eeaaca9b95878f3e40ed5e53d6814f Reviewed-on: https://go-review.googlesource.com/c/tools/+/220018 Run-TryBot: Muir Manders <muir@mnd.rs> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
parent
f8e42dc477
commit
753a1d49df
|
|
@ -432,42 +432,6 @@ func fixDanglingSelector(f *ast.File, s *ast.SelectorExpr, parent ast.Node, tok
|
|||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// fixAccidentalDecl tries to fix "accidental" declarations. For example:
|
||||
//
|
||||
// func typeOf() {}
|
||||
// type<> // want to call typeOf(), not declare a type
|
||||
//
|
||||
// If we find an *ast.DeclStmt with only a single phantom "_" spec, we
|
||||
// replace the decl statement with an expression statement containing
|
||||
// only the keyword. This allows completion to work to some degree.
|
||||
func fixAccidentalDecl(decl *ast.DeclStmt, parent ast.Node, tok *token.File, src []byte) {
|
||||
genDecl, _ := decl.Decl.(*ast.GenDecl)
|
||||
if genDecl == nil || len(genDecl.Specs) != 1 {
|
||||
return
|
||||
}
|
||||
|
||||
switch spec := genDecl.Specs[0].(type) {
|
||||
case *ast.TypeSpec:
|
||||
// If the name isn't a phantom "_" identifier inserted by the
|
||||
// parser then the decl is likely legitimate and we shouldn't mess
|
||||
// with it.
|
||||
if !isPhantomUnderscore(spec.Name, tok, src) {
|
||||
return
|
||||
}
|
||||
case *ast.ValueSpec:
|
||||
if len(spec.Names) != 1 || !isPhantomUnderscore(spec.Names[0], tok, src) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
replaceNode(parent, decl, &ast.ExprStmt{
|
||||
X: &ast.Ident{
|
||||
Name: genDecl.Tok.String(),
|
||||
NamePos: decl.Pos(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// fixPhantomSelector tries to fix selector expressions with phantom
|
||||
// "_" selectors. In particular, we check if the selector is a
|
||||
// keyword, and if so we swap in an *ast.Ident with the keyword text. For example:
|
||||
|
|
@ -886,7 +850,7 @@ func offsetPositions(n ast.Node, offset token.Pos) {
|
|||
}
|
||||
|
||||
// replaceNode updates parent's child oldChild to be newChild. It
|
||||
// retuns whether it replaced successfully.
|
||||
// returns whether it replaced successfully.
|
||||
func replaceNode(parent, oldChild, newChild ast.Node) bool {
|
||||
if parent == nil || oldChild == nil || newChild == nil {
|
||||
return false
|
||||
|
|
|
|||
Loading…
Reference in New Issue