| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
package golang |
| 6 |
|
| 7 |
import ( |
| 8 |
"context" |
| 9 |
|
| 10 |
"golang.org/x/tools/gopls/internal/cache" |
| 11 |
"golang.org/x/tools/gopls/internal/cache/parsego" |
| 12 |
"golang.org/x/tools/gopls/internal/file" |
| 13 |
"golang.org/x/tools/gopls/internal/protocol" |
| 14 |
"golang.org/x/tools/internal/imports" |
| 15 |
) |
| 16 |
|
| 17 |
|
| 18 |
func AddImport(ctx context.Context, snapshot *cache.Snapshot, fh file.Handle, importPath string) ([]protocol.TextEdit, error) { |
| 19 |
pgf, err := snapshot.ParseGo(ctx, fh, parsego.Full) |
| 20 |
if err != nil { |
| 21 |
return nil, err |
| 22 |
} |
| 23 |
return ComputeImportFixEdits(snapshot.Options().Local, pgf.Src, &imports.ImportFix{ |
| 24 |
StmtInfo: imports.ImportInfo{ |
| 25 |
ImportPath: importPath, |
| 26 |
}, |
| 27 |
FixType: imports.AddImport, |
| 28 |
}) |
| 29 |
} |