Documentation ¶
Index ¶
- type Resolver
- func (rslv *Resolver) Embeds(*rule.Rule, label.Label) []label.Label
- func (rslv *Resolver) Imports(c *config.Config, r *rule.Rule, f *rule.File) []resolve.ImportSpec
- func (rslv *Resolver) Name() string
- func (rslv *Resolver) Resolve(c *config.Config, _ *resolve.RuleIndex, _ *repo.RemoteCache, r *rule.Rule, ...)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver implements the resolve.Resolver interface.
Interface documentation:
Resolver is an interface that language extensions can implement to resolve dependencies in rules they generate.
func (*Resolver) Imports ¶
Imports implements the resolve.Resolver interface.
Imports extracts and indexes the imports provided by the given rule. Gazelle calls this method once for each rule in the repository that this Gazelle extension understands (i.e. all front-end rules).
For example, if Imports is passed a ts_library rule with label "//path/to:my_lib" and sources "foo.ts" and "bar.ts", then presumably said rule could satisfy TypeScript imports such as "import * from 'path/to/foo'" or "import 'path/to/bar'". In this example, Imports should return a slice with two resolve.ImportSpec structs, one for each of "path/to/foo" and "path/to/bar".
Gazelle uses the returned resolve.ImportSpec structs to build a resolve.RuleIndex struct, which maps imports (e.g. "path/to/foo") to the labels of the rules that provide them (e.g. "//path/to:my_lib"). This index is passed to the Resolve method (implemented below), in which we resolve the dependencies of all the rules generated by this Gazelle extension (i.e. we populate their deps attributes).
However, the resolve.RuleIndex struct is insufficient to resolve the dependencies of rules such as sk_element, which has multiple types of dependencies (ts_deps, sass_deps, sk_element_deps). We need to know the kind of a dependency (e.g. "ts_library", "sass_library", "sk_element"), in addition to its label, before we can add it to one of the *_deps arguments, but the resolve.RuleIndex struct only provides the latter.
For this reason, this Gazelle extension ignores the resolve.RuleIndex struct. Instead, we build our own index with all the information we need (see fields sassImportsToDeps and tsImportsToDeps).
Therefore, this method always returns an empty slice, which results in an empty resolve.RuleIndex, but that is OK because we do not use it.
func (*Resolver) Name ¶
Name implements the resolve.Resolver interface.
Interface documentation:
Name returns the name of the language. This should be a prefix of the kinds of rules generated by the language, e.g., "go" for the Go extension since it generates "go_library" rules.
func (*Resolver) Resolve ¶
func (rslv *Resolver) Resolve(c *config.Config, _ *resolve.RuleIndex, _ *repo.RemoteCache, r *rule.Rule, imports interface{}, from label.Label)
Resolve implements the resolve.Resolver interface.
Resolve takes a (rule, ImportsParsedFromRuleSources) pair generated by Language.GenerateRules() and resolves the rule's dependencies based on its imports. It populates the rule's deps argument (or ts_deps, sass_deps and sk_element_deps arguments in the case of sk_element and sk_page rules) with the result of mapping each import to the label of a rule that provides the import. It does so by leveraging the index built in the Imports method.
Gazelle calls this method once for each (rule, ImportsParsedFromRuleSources) pair generated by successive calls to Language.GenerateRules(). Gazelle calls this method after all imports in the repository have been indexed via successive calls to the Imports method.