@@ -300,7 +300,72 @@ void WorkspaceFolder::indexFiles(const ClientConfiguration& config)
300300 client->sendTrace (" workspace: indexing all files COMPLETED" );
301301}
302302
303- void WorkspaceFolder::registerTypes ()
303+ static void clearDisabledGlobals (const ClientPtr client, const Luau::GlobalTypes& globalTypes, const std::vector<std::string>& disabledGlobals)
304+ {
305+ const auto targetScope = globalTypes.globalScope ;
306+ for (const auto & disabledGlobal : disabledGlobals)
307+ {
308+ std::string library = disabledGlobal;
309+ std::optional<std::string> method = std::nullopt ;
310+
311+ if (const auto separator = disabledGlobal.find (' .' ); separator != std::string::npos)
312+ {
313+ library = disabledGlobal.substr (0 , separator);
314+ method = disabledGlobal.substr (separator + 1 );
315+ }
316+
317+ const auto globalName = globalTypes.globalNames .names ->get (library.c_str ());
318+ if (globalName.value == nullptr )
319+ {
320+ client->sendLogMessage (lsp::MessageType::Warning, " disabling globals: skipping unknown global - " + disabledGlobal);
321+ continue ;
322+ }
323+
324+ if (auto binding = targetScope->bindings .find (globalName); binding != targetScope->bindings .end ())
325+ {
326+ if (method)
327+ {
328+ const auto typeId = Luau::follow (binding->second .typeId );
329+ if (const auto ttv = Luau::getMutable<Luau::TableType>(typeId))
330+ {
331+ if (contains (ttv->props , *method))
332+ {
333+ client->sendLogMessage (lsp::MessageType::Info, " disabling globals: erasing global - " + disabledGlobal);
334+ ttv->props .erase (*method);
335+ }
336+ else
337+ client->sendLogMessage (lsp::MessageType::Warning, " disabling globals: could not find method - " + disabledGlobal);
338+ }
339+ else if (const auto ctv = Luau::getMutable<Luau::ClassType>(typeId))
340+ {
341+ if (contains (ctv->props , *method))
342+ {
343+ client->sendLogMessage (lsp::MessageType::Info, " disabling globals: erasing global - " + disabledGlobal);
344+ ttv->props .erase (*method);
345+ }
346+ else
347+ client->sendLogMessage (lsp::MessageType::Warning, " disabling globals: could not find method - " + disabledGlobal);
348+ }
349+ else
350+ {
351+ client->sendLogMessage (lsp::MessageType::Warning,
352+ " disabling globals: cannot clear method from global, only tables or classes are supported - " + disabledGlobal);
353+ }
354+ }
355+ else
356+ {
357+ client->sendLogMessage (lsp::MessageType::Info, " disabling globals: erasing global - " + disabledGlobal);
358+ targetScope->bindings .erase (globalName);
359+ }
360+ }
361+ else
362+ {
363+ client->sendLogMessage (lsp::MessageType::Warning, " disabling globals: skipping unknown global - " + disabledGlobal);
364+ }
365+ }
366+ }
367+
368+ void WorkspaceFolder::registerTypes (const std::vector<std::string>& disabledGlobals)
304369{
305370 LUAU_TIMETRACE_SCOPE (" WorkspaceFolder::initialize" , " LSP" );
306371 client->sendTrace (" workspace initialization: registering Luau globals" );
@@ -368,6 +433,16 @@ void WorkspaceFolder::registerTypes()
368433 client->publishDiagnostics ({uri, std::nullopt , diagnostics});
369434 }
370435 }
436+
437+ if (!disabledGlobals.empty ())
438+ {
439+ client->sendTrace (" workspace initialization: removing disabled globals" );
440+ clearDisabledGlobals (client, frontend.globals , disabledGlobals);
441+ if (!FFlag::LuauSolverV2)
442+ clearDisabledGlobals (client, frontend.globalsForAutocomplete , disabledGlobals);
443+ client->sendTrace (" workspace initialization: removing disabled globals COMPLETED" );
444+ }
445+
371446 Luau::freeze (frontend.globals .globalTypes );
372447 if (!FFlag::LuauSolverV2)
373448 Luau::freeze (frontend.globalsForAutocomplete .globalTypes );
@@ -387,7 +462,7 @@ void WorkspaceFolder::setupWithConfiguration(const ClientConfiguration& configur
387462 platform = LSPPlatform::getPlatform (configuration, &fileResolver, this );
388463 fileResolver.platform = platform.get ();
389464
390- registerTypes ();
465+ registerTypes (configuration. types . disabledGlobals );
391466 }
392467
393468 client->sendTrace (" workspace: apply platform-specific configuration" );
0 commit comments