Skip to content

Commit

Permalink
Add initialization trace logging for debugging purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed Dec 25, 2023
1 parent 5cf834c commit d6dbef1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/LanguageServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ void LanguageServer::onInitialized([[maybe_unused]] const lsp::InitializedParams
if (client->capabilities.workspace && client->capabilities.workspace->didChangeConfiguration &&
client->capabilities.workspace->didChangeConfiguration->dynamicRegistration)
{
client->sendTrace("client supports configuration, setting up didChangeConfiguration capability");
requestedConfiguration = true;

client->registerCapability("didChangeConfigurationCapability", "workspace/didChangeConfiguration", nullptr);
Expand All @@ -464,6 +465,7 @@ void LanguageServer::onInitialized([[maybe_unused]] const lsp::InitializedParams
};

// Send off requests to get the configuration for each workspace
client->sendTrace("config: requesting initial configuration for each workspace");
std::vector<lsp::DocumentUri> items{nullWorkspace->rootUri};
for (auto& workspace : workspaceFolders)
items.emplace_back(workspace->rootUri);
Expand Down Expand Up @@ -496,10 +498,12 @@ void LanguageServer::onInitialized([[maybe_unused]] const lsp::InitializedParams
// a race condition where the first LSP events are executed before receiving the user configuration,
// causing us to fall back to the global configuration. Sending the request for configuration
// first means we receive the user config before processing the first LSP events
client->sendTrace("initializing null workspace");
nullWorkspace->initialize();
nullWorkspace->setupWithConfiguration(client->globalConfig);
for (auto& folder : workspaceFolders)
{
client->sendTrace("initializing workspace: " + folder->rootUri.toString());
folder->initialize();
// Client does not support retrieving configuration information, so we just setup the workspaces with the default, global, configuration
if (!requestedConfiguration)
Expand Down
15 changes: 12 additions & 3 deletions src/Workspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ void WorkspaceFolder::indexFiles(const ClientConfiguration& config)
if (isNullWorkspace())
return;

client->sendTrace("workspace: indexing all files");

size_t indexCount = 0;

for (std::filesystem::recursive_directory_iterator next(rootUri.fsPath()), end; next != end; ++next)
Expand Down Expand Up @@ -177,6 +179,8 @@ void WorkspaceFolder::indexFiles(const ClientConfiguration& config)
}
}
}

client->sendTrace("workspace: indexing all files COMPLETED");
}

bool WorkspaceFolder::updateSourceMap()
Expand Down Expand Up @@ -212,15 +216,14 @@ bool WorkspaceFolder::updateSourceMap()

void WorkspaceFolder::initialize()
{
client->sendTrace("workspace initialization: registering Luau globals");
Luau::registerBuiltinGlobals(frontend, frontend.globals, /* typeCheckForAutocomplete = */ false);
Luau::registerBuiltinGlobals(frontend, frontend.globalsForAutocomplete, /* typeCheckForAutocomplete = */ true);

Luau::attachTag(Luau::getGlobalBinding(frontend.globalsForAutocomplete, "require"), "Require");

if (client->definitionsFiles.empty())
{
client->sendLogMessage(lsp::MessageType::Warning, "No definitions file provided by client");
}

for (const auto& definitionsFile : client->definitionsFiles)
{
Expand All @@ -235,13 +238,17 @@ void WorkspaceFolder::initialize()
}

// Parse definitions file metadata
client->sendTrace("workspace initialization: parsing definitions file metadata");
if (auto metadata = types::parseDefinitionsFileMetadata(*definitionsContents))
definitionsFileMetadata = metadata;
client->sendTrace("workspace initialization: parsing definitions file metadata COMPLETED", json(definitionsFileMetadata).dump());

client->sendTrace("workspace initialization: registering types definition");
auto result = types::registerDefinitions(
frontend, frontend.globals, *definitionsContents, /* typeCheckForAutocomplete = */ false, definitionsFileMetadata);
types::registerDefinitions(
frontend, frontend.globalsForAutocomplete, *definitionsContents, /* typeCheckForAutocomplete = */ true, definitionsFileMetadata);
client->sendTrace("workspace initialization: registering types definition COMPLETED");

auto uri = Uri::file(definitionsFile);

Expand Down Expand Up @@ -273,9 +280,11 @@ void WorkspaceFolder::initialize()

void WorkspaceFolder::setupWithConfiguration(const ClientConfiguration& configuration)
{
client->sendTrace("workspace: setting up with configuration");
isConfigured = true;
if (configuration.sourcemap.enabled)
{
client->sendTrace("workspace: sourcemap enabled");
if (!isNullWorkspace() && !updateSourceMap())
{
client->sendWindowMessage(
Expand All @@ -285,4 +294,4 @@ void WorkspaceFolder::setupWithConfiguration(const ClientConfiguration& configur

if (configuration.index.enabled)
indexFiles(configuration);
}
}

0 comments on commit d6dbef1

Please sign in to comment.