|
16 | 16 | package com.google.devtools.build.lib.bazel.bzlmod;
|
17 | 17 |
|
18 | 18 | import static com.google.common.collect.ImmutableBiMap.toImmutableBiMap;
|
| 19 | +import static com.google.common.collect.ImmutableSet.toImmutableSet; |
19 | 20 |
|
| 21 | +import com.google.common.collect.ImmutableSet; |
20 | 22 | import com.google.devtools.build.lib.analysis.BlazeDirectories;
|
21 | 23 | import com.google.devtools.build.lib.bazel.repository.downloader.DownloadManager;
|
22 | 24 | import com.google.devtools.build.lib.cmdline.BazelModuleContext;
|
|
51 | 53 | import net.starlark.java.eval.StarlarkList;
|
52 | 54 | import net.starlark.java.eval.StarlarkSemantics;
|
53 | 55 | import net.starlark.java.eval.StarlarkThread;
|
| 56 | +import net.starlark.java.spelling.SpellChecker; |
54 | 57 | import net.starlark.java.syntax.Location;
|
55 | 58 |
|
56 | 59 | /**
|
@@ -147,13 +150,19 @@ public SkyValue compute(SkyKey skyKey, Environment env)
|
147 | 150 | // Check that the .bzl file actually exports a module extension by our name.
|
148 | 151 | Object exported = bzlLoadValue.getModule().getGlobal(extensionId.getExtensionName());
|
149 | 152 | if (!(exported instanceof ModuleExtension.InStarlark)) {
|
| 153 | + ImmutableSet<String> exportedExtensions = |
| 154 | + bzlLoadValue.getModule().getGlobals().entrySet().stream() |
| 155 | + .filter(e -> e.getValue() instanceof ModuleExtension.InStarlark) |
| 156 | + .map(Entry::getKey) |
| 157 | + .collect(toImmutableSet()); |
150 | 158 | throw new SingleExtensionEvalFunctionException(
|
151 | 159 | ExternalDepsException.withMessage(
|
152 | 160 | Code.BAD_MODULE,
|
153 |
| - "%s does not export a module extension called %s, yet its use is requested at %s", |
| 161 | + "%s does not export a module extension called %s, yet its use is requested at %s%s", |
154 | 162 | extensionId.getBzlFileLabel(),
|
155 | 163 | extensionId.getExtensionName(),
|
156 |
| - sampleUsageLocation), |
| 164 | + sampleUsageLocation, |
| 165 | + SpellChecker.didYouMean(extensionId.getExtensionName(), exportedExtensions)), |
157 | 166 | Transience.PERSISTENT);
|
158 | 167 | }
|
159 | 168 |
|
@@ -206,12 +215,14 @@ public SkyValue compute(SkyKey skyKey, Environment env)
|
206 | 215 | ExternalDepsException.withMessage(
|
207 | 216 | Code.BAD_MODULE,
|
208 | 217 | "module extension \"%s\" from \"%s\" does not generate repository \"%s\", yet it"
|
209 |
| - + " is imported as \"%s\" in the usage at %s", |
| 218 | + + " is imported as \"%s\" in the usage at %s%s", |
210 | 219 | extensionId.getExtensionName(),
|
211 | 220 | extensionId.getBzlFileLabel(),
|
212 | 221 | repoImport.getValue(),
|
213 | 222 | repoImport.getKey(),
|
214 |
| - usage.getLocation()), |
| 223 | + usage.getLocation(), |
| 224 | + SpellChecker.didYouMean( |
| 225 | + repoImport.getValue(), threadContext.getGeneratedRepos().keySet())), |
215 | 226 | Transience.PERSISTENT);
|
216 | 227 | }
|
217 | 228 | }
|
|
0 commit comments