@@ -67,18 +67,25 @@ void WorkspaceFolder::closeTextDocument(const lsp::DocumentUri& uri)
6767 clearDiagnosticsForFile (uri);
6868}
6969
70- void WorkspaceFolder::clearDiagnosticsForFile (const lsp::DocumentUri& uri)
70+ void WorkspaceFolder::clearDiagnosticsForFiles (const std::vector< lsp::DocumentUri>& uris) const
7171{
7272 if (!client->capabilities .textDocument || !client->capabilities .textDocument ->diagnostic )
7373 {
74- client->publishDiagnostics (lsp::PublishDiagnosticsParams{uri, std::nullopt , {}});
74+ for (const auto & uri : uris)
75+ client->publishDiagnostics (lsp::PublishDiagnosticsParams{uri, std::nullopt , {}});
7576 }
7677 else if (client->workspaceDiagnosticsToken )
7778 {
78- lsp::WorkspaceDocumentDiagnosticReport documentReport;
79- documentReport.uri = uri;
80- documentReport.kind = lsp::DocumentDiagnosticReportKind::Full;
81- lsp::WorkspaceDiagnosticReportPartialResult report{{documentReport}};
79+ std::vector<lsp::WorkspaceDocumentDiagnosticReport> reports;
80+ reports.reserve (uris.size ());
81+ for (const auto & uri : uris)
82+ {
83+ lsp::WorkspaceDocumentDiagnosticReport report;
84+ report.uri = uri;
85+ report.kind = lsp::DocumentDiagnosticReportKind::Full;
86+ reports.push_back (report);
87+ }
88+ lsp::WorkspaceDiagnosticReportPartialResult report{reports};
8289 client->sendProgress ({client->workspaceDiagnosticsToken .value (), report});
8390 }
8491 else
@@ -87,52 +94,66 @@ void WorkspaceFolder::clearDiagnosticsForFile(const lsp::DocumentUri& uri)
8794 }
8895}
8996
90- void WorkspaceFolder::onDidChangeWatchedFiles (const lsp::FileEvent& change)
97+ void WorkspaceFolder::clearDiagnosticsForFile (const lsp::DocumentUri& uri)
98+ {
99+ clearDiagnosticsForFiles ({uri});
100+ }
101+
102+ void WorkspaceFolder::onDidChangeWatchedFiles (const std::vector<lsp::FileEvent>& changes)
91103{
92- auto filePath = change.uri .fsPath ();
104+ client->sendTrace (" workspace: processing " + std::to_string (changes.size ()) + " watched files changes" );
105+
93106 auto config = client->getConfiguration (rootUri);
94107
95- platform->onDidChangeWatchedFiles (change);
108+ std::vector<Luau::ModuleName> dirtyFiles;
109+ std::vector<Uri> deletedFiles;
96110
97- if (filePath. filename () == " .luaurc " )
111+ for ( const auto & change : changes )
98112 {
99- client->sendLogMessage (lsp::MessageType::Info, " Acknowledge config changed for workspace " + name + " , clearing configuration cache" );
100- fileResolver.clearConfigCache ();
113+ auto filePath = change.uri .fsPath ();
101114
102- // Recompute diagnostics
103- recomputeDiagnostics (config);
104- }
105- else if (filePath.extension () == " .lua" || filePath.extension () == " .luau" )
106- {
107- // Notify if it was a definitions file
108- if (isDefinitionFile (filePath, config))
109- {
110- client->sendWindowMessage (
111- lsp::MessageType::Info, " Detected changes to global definitions files. Please reload your workspace for this to take effect" );
112- return ;
113- }
115+ platform->onDidChangeWatchedFiles (change);
114116
115- // Index the workspace on changes
116- // We only update the require graph. We do not perform type checking
117- if (config.index .enabled && isConfigured)
117+ if (filePath.filename () == " .luaurc" )
118118 {
119- auto moduleName = fileResolver.getModuleName (change.uri );
119+ client->sendLogMessage (lsp::MessageType::Info, " Acknowledge config changed for workspace " + name + " , clearing configuration cache" );
120+ fileResolver.clearConfigCache ();
120121
121- std::vector<Luau::ModuleName> markedDirty{};
122- frontend.markDirty (moduleName, &markedDirty);
122+ // Recompute diagnostics
123+ recomputeDiagnostics (config);
124+ }
125+ else if (filePath.extension () == " .lua" || filePath.extension () == " .luau" )
126+ {
127+ // Notify if it was a definitions file
128+ if (isDefinitionFile (filePath, config))
129+ {
130+ client->sendWindowMessage (
131+ lsp::MessageType::Info, " Detected changes to global definitions files. Please reload your workspace for this to take effect" );
132+ continue ;
133+ }
134+ else if (isIgnoredFile (filePath, config))
135+ {
136+ continue ;
137+ }
123138
124- if (change.type == lsp::FileChangeType::Created)
125- frontend.parse (moduleName);
139+ // Index the workspace on changes
140+ if (config.index .enabled && isConfigured)
141+ {
142+ auto moduleName = fileResolver.getModuleName (change.uri );
143+ frontend.markDirty (moduleName, &dirtyFiles);
144+ }
126145
127- // Re-check the reverse dependencies
128- for (const auto & reverseDep : markedDirty)
129- frontend.parse (reverseDep);
146+ if (change.type == lsp::FileChangeType::Deleted)
147+ deletedFiles.push_back (change.uri );
130148 }
131-
132- // Clear the diagnostics for the file in case it was not managed
133- if (change.type == lsp::FileChangeType::Deleted)
134- clearDiagnosticsForFile (change.uri );
135149 }
150+
151+ // Parse require graph for files if indexing enabled
152+ for (const auto & dirtyModule : dirtyFiles)
153+ frontend.parse (dirtyModule);
154+
155+ // Clear the diagnostics for files in case it was not managed
156+ clearDiagnosticsForFiles (deletedFiles);
136157}
137158
138159// / When using lexically_relative, if the root-dir does not match, it will return a default-constructed path.
0 commit comments