diff --git a/internal/lsp/cache/parse.go b/internal/lsp/cache/parse.go index 6d26674f76..4eb8a05707 100644 --- a/internal/lsp/cache/parse.go +++ b/internal/lsp/cache/parse.go @@ -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