Debian Codegraph @

internal/imports/source.go

raw symbols SCIP
1 // Copyright 2024 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package importsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/
6
7 import "contextscip-go gomod github.com/golang/go/src go1.25.0 context/"
8
9 // These types document the APIs below.
10 //
11 // TODO(rfindley): consider making these defined types rather than aliases.
12 type (
13 ImportPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportPath# = string
14 PackageNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageName# = string
15 Symbolscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Symbol# = string
16
17 // References is set of References found in a Go file. The first map key is the
18 // left hand side of a selector expression, the second key is the right hand
19 // side, and the value should always be true.
20 Referencesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/References# = map[PackageNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageName#]map[Symbolscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Symbol#]bool
21 )
22
23 // A Result satisfies a missing import.
24 //
25 // The Import field describes the missing import spec, and the Package field
26 // summarizes the package exports.
27 type Resultscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Result# struct {
28 Importscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Result#Import. *ImportInfoscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportInfo#
29 Packagescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Result#Package. *PackageInfoscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageInfo#
30 }
31
32 // An ImportInfo represents a single import statement.
33 type ImportInfoscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportInfo# struct {
34 ImportPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportInfo#ImportPath. string // import path, e.g. "crypto/rand".
35 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportInfo#Name. string // import name, e.g. "crand", or "" if none.
36 }
37
38 // A PackageInfo represents what's known about a package.
39 type PackageInfoscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageInfo# struct {
40 Namescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageInfo#Name. string // package name in the package declaration, if known
41 Exportsscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageInfo#Exports. map[string]bool // set of names of known package level sortSymbols
42 }
43
44 // A Source provides imports to satisfy unresolved references in the file being
45 // fixed.
46 type Sourcescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Source# interface {
47 // LoadPackageNames queries PackageName information for the requested import
48 // paths, when operating from the provided srcDir.
49 //
50 // TODO(rfindley): try to refactor to remove this operation.
51 LoadPackageNamesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Source#LoadPackageNames.(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#, srcDir string, paths []ImportPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportPath#) (map[ImportPathscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/ImportPath#]PackageNamescip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/PackageName#, error)
52
53 // ResolveReferences asks the Source for the best package name to satisfy
54 // each of the missing references, in the context of fixing the given
55 // filename.
56 //
57 // Returns a map from package name to a [Result] for that package name that
58 // provides the required symbols. Keys may be omitted in the map if no
59 // candidates satisfy all missing references for that package name. It is up
60 // to each data source to select the best result for each entry in the
61 // missing map.
62 ResolveReferencesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Source#ResolveReferences.(ctx contextscip-go gomod github.com/golang/go/src go1.25.0 context/.Contextscip-go gomod github.com/golang/go/src go1.25.0 context/Context#, filename string, missing Referencesscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/References#) ([]*Resultscip-go gomod golang.org/x/tools . `golang.org/x/tools/internal/imports`/Result#, error)
63 }