mirror of
https://github.com/luau-lang/luau.git
synced 2025-04-19 11:13:49 +01:00
Pass environment scope to autocomplete typechecker (#610)
Fixes a bug where the environment scope is not passed to the autocomplete typechecker, so environment-related types are not provided. This caused an issue where `getModuleEnvironment` returns `typeChecker.globalScope` when there is no environment. We pass this through to `typeCheckerForAutocomplete.check()` then environmentscope is no longer nullopt and it will use `typeChecker.globalScope` instead of falling back to `typeCheckerForAutocomplete.globalScope`. This is solved by passing `forAutocomplete` to `getModuleEnvironment` so it falls back to the autocomplete global scope if none found.
This commit is contained in:
parent
be2769ad14
commit
a95dff3223
2 changed files with 9 additions and 5 deletions
|
@ -166,7 +166,7 @@ private:
|
||||||
|
|
||||||
static LintResult classifyLints(const std::vector<LintWarning>& warnings, const Config& config);
|
static LintResult classifyLints(const std::vector<LintWarning>& warnings, const Config& config);
|
||||||
|
|
||||||
ScopePtr getModuleEnvironment(const SourceModule& module, const Config& config);
|
ScopePtr getModuleEnvironment(const SourceModule& module, const Config& config, bool forAutocomplete = false);
|
||||||
|
|
||||||
std::unordered_map<std::string, ScopePtr> environments;
|
std::unordered_map<std::string, ScopePtr> environments;
|
||||||
std::unordered_map<std::string, std::function<void(TypeChecker&, ScopePtr)>> builtinDefinitions;
|
std::unordered_map<std::string, std::function<void(TypeChecker&, ScopePtr)>> builtinDefinitions;
|
||||||
|
|
|
@ -455,7 +455,7 @@ CheckResult Frontend::check(const ModuleName& name, std::optional<FrontendOption
|
||||||
|
|
||||||
Mode mode = sourceModule.mode.value_or(config.mode);
|
Mode mode = sourceModule.mode.value_or(config.mode);
|
||||||
|
|
||||||
ScopePtr environmentScope = getModuleEnvironment(sourceModule, config);
|
ScopePtr environmentScope = getModuleEnvironment(sourceModule, config, frontendOptions.forAutocomplete);
|
||||||
|
|
||||||
double timestamp = getTimestamp();
|
double timestamp = getTimestamp();
|
||||||
|
|
||||||
|
@ -500,7 +500,7 @@ CheckResult Frontend::check(const ModuleName& name, std::optional<FrontendOption
|
||||||
typeCheckerForAutocomplete.unifierIterationLimit = std::nullopt;
|
typeCheckerForAutocomplete.unifierIterationLimit = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
ModulePtr moduleForAutocomplete = typeCheckerForAutocomplete.check(sourceModule, Mode::Strict);
|
ModulePtr moduleForAutocomplete = typeCheckerForAutocomplete.check(sourceModule, Mode::Strict, environmentScope);
|
||||||
moduleResolverForAutocomplete.modules[moduleName] = moduleForAutocomplete;
|
moduleResolverForAutocomplete.modules[moduleName] = moduleForAutocomplete;
|
||||||
|
|
||||||
double duration = getTimestamp() - timestamp;
|
double duration = getTimestamp() - timestamp;
|
||||||
|
@ -677,9 +677,13 @@ bool Frontend::parseGraph(std::vector<ModuleName>& buildQueue, CheckResult& chec
|
||||||
return cyclic;
|
return cyclic;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopePtr Frontend::getModuleEnvironment(const SourceModule& module, const Config& config)
|
ScopePtr Frontend::getModuleEnvironment(const SourceModule& module, const Config& config, bool forAutocomplete)
|
||||||
{
|
{
|
||||||
ScopePtr result = typeChecker.globalScope;
|
ScopePtr result;
|
||||||
|
if (forAutocomplete)
|
||||||
|
result = typeCheckerForAutocomplete.globalScope;
|
||||||
|
else
|
||||||
|
result = typeChecker.globalScope;
|
||||||
|
|
||||||
if (module.environmentName)
|
if (module.environmentName)
|
||||||
result = getEnvironmentScope(*module.environmentName);
|
result = getEnvironmentScope(*module.environmentName);
|
||||||
|
|
Loading…
Add table
Reference in a new issue