@@ -257,7 +257,10 @@ func (w *WorkspaceWatcher) openHighPriorityFiles(ctx context.Context, serverName
260+ // Collect all files to open first
261+ var filesToOpen []string
260− // For each pattern, find and open matching files
263+ // For each pattern, find matching files
261 for _, pattern := range patterns {
264 for _, pattern := range patterns {
262 // Use doublestar.Glob to find files matching the pattern (supports ** patterns)
265 // Use doublestar.Glob to find files matching the pattern (supports ** patterns)
263 matches, err := doublestar.Glob(os.DirFS(w.workspacePath), pattern)
266 matches, err := doublestar.Glob(os.DirFS(w.workspacePath), pattern)
@@ -278,7 +281,23 @@ func (w *WorkspaceWatcher) openHighPriorityFiles(ctx context.Context, serverName
281− // Open the file
284+ filesToOpen = append(filesToOpen, fullPath)
286+ // Limit the number of files per pattern
287+ if len(filesToOpen) >= 5 && (serverName != "java" && serverName != "jdtls") {
293+ // Open files in batches to reduce overhead
295+ for i := 0; i < len(filesToOpen); i += batchSize {
296+ end := min(i+batchSize, len(filesToOpen))
298+ // Open batch of files
299+ for j := i; j < end; j++ {
300+ fullPath := filesToOpen[j]
282 if err := w.client.OpenFile(ctx, fullPath); err != nil {
301 if err := w.client.OpenFile(ctx, fullPath); err != nil {
283 if cnf.DebugLSP {
302 if cnf.DebugLSP {
284 logging.Debug("Error opening high-priority file", "path", fullPath, "error", err)
303 logging.Debug("Error opening high-priority file", "path", fullPath, "error", err)
@@ -289,14 +308,11 @@ func (w *WorkspaceWatcher) openHighPriorityFiles(ctx context.Context, serverName
289 logging.Debug("Opened high-priority file", "path", fullPath)
308 logging.Debug("Opened high-priority file", "path", fullPath)
293− // Add a small delay to prevent overwhelming the server
313+ // Only add delay between batches, not individual files
314+ if end < len(filesToOpen) {
294− time.Sleep(20 * time.Millisecond)
315+ time.Sleep(50 * time.Millisecond)
296− // Limit the number of files opened per pattern
297− if filesOpened >= 5 && (serverName != "java" && serverName != "jdtls") {