| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package golang |
| 6 |
|
| 7 |
import ( |
| 8 |
"context" |
| 9 |
"fmt" |
| 10 |
"go/ast" |
| 11 |
"go/token" |
| 12 |
|
| 13 |
"golang.org/x/tools/go/ast/inspector" |
| 14 |
"golang.org/x/tools/gopls/internal/cache" |
| 15 |
"golang.org/x/tools/gopls/internal/file" |
| 16 |
"golang.org/x/tools/gopls/internal/protocol" |
| 17 |
"golang.org/x/tools/internal/moreiters" |
| 18 |
) |
| 19 |
|
| 20 |
|
| 21 |
func MoveType(ctx context.Context, fh file.Handle, snapshot *cache.Snapshot, loc protocol.Location, newPkgDir string) ([]protocol.DocumentChange, error) { |
| 22 |
return nil, fmt.Errorf("MoveType: not yet supported") |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
func selectionContainsType(cursor inspector.Cursor) (inspector.Cursor, *ast.GenDecl, *ast.TypeSpec, string, bool) { |
| 28 |
declCur, ok := moreiters.First(cursor.Enclosing((*ast.GenDecl)(nil))) |
| 29 |
if !ok { |
| 30 |
return inspector.Cursor{}, &ast.GenDecl{}, &ast.TypeSpec{}, "", false |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
declNode := declCur.Node().(*ast.GenDecl) |
| 35 |
if declNode.Tok != token.TYPE { |
| 36 |
return inspector.Cursor{}, &ast.GenDecl{}, &ast.TypeSpec{}, "", false |
| 37 |
} |
| 38 |
|
| 39 |
typSpec, ok := declNode.Specs[0].(*ast.TypeSpec) |
| 40 |
if !ok { |
| 41 |
return inspector.Cursor{}, &ast.GenDecl{}, &ast.TypeSpec{}, "", false |
| 42 |
} |
| 43 |
|
| 44 |
return declCur, declNode, declNode.Specs[0].(*ast.TypeSpec), typSpec.Name.Name, true |
| 45 |
} |