@@ -16,8 +16,6 @@ import (
1616 "github.com/kujtimiihoxha/termai/internal/lsp/protocol"
1717)
1818
19−var logger = logging.Get()
20−
2119// WorkspaceWatcher manages LSP file watching
2220type WorkspaceWatcher struct {
2321 client *lsp.Client
@@ -53,7 +51,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
5351
5452 // Print detailed registration information for debugging
5553 if cnf.Debug {
56− logger.Debug("Adding file watcher registrations",
54+ logging.Debug("Adding file watcher registrations",
5755 "id", id,
5856 "watchers", len(watchers),
5957 "total", len(w.registrations),
@@ -61,26 +59,26 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
6159 )
6260
6361 for i, watcher := range watchers {
64− logger.Debug("Registration", "index", i+1)
62+ logging.Debug("Registration", "index", i+1)
6563
6664 // Log the GlobPattern
6765 switch v := watcher.GlobPattern.Value.(type) {
6866 case string:
69− logger.Debug("GlobPattern", "pattern", v)
67+ logging.Debug("GlobPattern", "pattern", v)
7068 case protocol.RelativePattern:
71− logger.Debug("GlobPattern", "pattern", v.Pattern)
69+ logging.Debug("GlobPattern", "pattern", v.Pattern)
7270
7371 // Log BaseURI details
7472 switch u := v.BaseURI.Value.(type) {
7573 case string:
76− logger.Debug("BaseURI", "baseURI", u)
74+ logging.Debug("BaseURI", "baseURI", u)
7775 case protocol.DocumentUri:
78− logger.Debug("BaseURI", "baseURI", u)
76+ logging.Debug("BaseURI", "baseURI", u)
7977 default:
80− logger.Debug("BaseURI", "baseURI", u)
78+ logging.Debug("BaseURI", "baseURI", u)
8179 }
8280 default:
83− logger.Debug("GlobPattern", "unknown type", fmt.Sprintf("%T", v))
81+ logging.Debug("GlobPattern", "unknown type", fmt.Sprintf("%T", v))
8482 }
8583
8684 // Log WatchKind
@@ -89,7 +87,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
8987 watchKind = *watcher.Kind
9088 }
9189
92− logger.Debug("WatchKind", "kind", watchKind)
90+ logging.Debug("WatchKind", "kind", watchKind)
9391
9492 // Test match against some example paths
9593 testPaths := []string{
@@ -99,7 +97,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
9997
10098 for _, testPath := range testPaths {
10199 isMatch := w.matchesPattern(testPath, watcher.GlobPattern)
102− logger.Debug("Test path", "path", testPath, "matches", isMatch)
100+ logging.Debug("Test path", "path", testPath, "matches", isMatch)
103101 }
104102 }
105103 }
@@ -119,7 +117,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
119117 if d.IsDir() {
120118 if path != w.workspacePath && shouldExcludeDir(path) {
121119 if cnf.Debug {
122− logger.Debug("Skipping excluded directory", "path", path)
120+ logging.Debug("Skipping excluded directory", "path", path)
123121 }
124122 return filepath.SkipDir
125123 }
@@ -139,7 +137,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
139137
140138 elapsedTime := time.Since(startTime)
141139 if cnf.Debug {
142− logger.Debug("Workspace scan complete",
140+ logging.Debug("Workspace scan complete",
143141 "filesOpened", filesOpened,
144142 "elapsedTime", elapsedTime.Seconds(),
145143 "workspacePath", w.workspacePath,
@@ -147,7 +145,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
147145 }
148146
149147 if err != nil && cnf.Debug {
150− logger.Debug("Error scanning workspace for files to open", "error", err)
148+ logging.Debug("Error scanning workspace for files to open", "error", err)
151149 }
152150 }()
153151}
@@ -164,7 +162,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
164162
165163 watcher, err := fsnotify.NewWatcher()
166164 if err != nil {
167− logger.Error("Error creating watcher", "error", err)
165+ logging.Error("Error creating watcher", "error", err)
168166 }
169167 defer watcher.Close()
170168
@@ -178,7 +176,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
178176 if d.IsDir() && path != workspacePath {
179177 if shouldExcludeDir(path) {
180178 if cnf.Debug {
181− logger.Debug("Skipping excluded directory", "path", path)
179+ logging.Debug("Skipping excluded directory", "path", path)
182180 }
183181 return filepath.SkipDir
184182 }
@@ -188,14 +186,14 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
188186 if d.IsDir() {
189187 err = watcher.Add(path)
190188 if err != nil {
191− logger.Error("Error watching path", "path", path, "error", err)
189+ logging.Error("Error watching path", "path", path, "error", err)
192190 }
193191 }
194192
195193 return nil
196194 })
197195 if err != nil {
198− logger.Error("Error walking workspace", "error", err)
196+ logging.Error("Error walking workspace", "error", err)
199197 }
200198
201199 // Event loop
@@ -217,7 +215,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
217215 // Skip excluded directories
218216 if !shouldExcludeDir(event.Name) {
219217 if err := watcher.Add(event.Name); err != nil {
220− logger.Error("Error adding directory to watcher", "path", event.Name, "error", err)
218+ logging.Error("Error adding directory to watcher", "path", event.Name, "error", err)
221219 }
222220 }
223221 } else {
@@ -232,7 +230,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
232230 // Debug logging
233231 if cnf.Debug {
234232 matched, kind := w.isPathWatched(event.Name)
235− logger.Debug("File event",
233+ logging.Debug("File event",
236234 "path", event.Name,
237235 "operation", event.Op.String(),
238236 "watched", matched,
@@ -277,7 +275,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
277275 if !ok {
278276 return
279277 }
280− logger.Error("Error watching file", "error", err)
278+ logging.Error("Error watching file", "error", err)
281279 }
282280 }
283281}
@@ -402,7 +400,7 @@ func matchesSimpleGlob(pattern, path string) bool {
402400 // Fall back to simple matching for simpler patterns
403401 matched, err := filepath.Match(pattern, path)
404402 if err != nil {
405− logger.Error("Error matching pattern", "pattern", pattern, "path", path, "error", err)
403+ logging.Error("Error matching pattern", "pattern", pattern, "path", path, "error", err)
406404 return false
407405 }
408406
@@ -413,7 +411,7 @@ func matchesSimpleGlob(pattern, path string) bool {
413411func (w *WorkspaceWatcher) matchesPattern(path string, pattern protocol.GlobPattern) bool {
414412 patternInfo, err := pattern.AsPattern()
415413 if err != nil {
416− logger.Error("Error parsing pattern", "pattern", pattern, "error", err)
414+ logging.Error("Error parsing pattern", "pattern", pattern, "error", err)
417415 return false
418416 }
419417
@@ -438,7 +436,7 @@ func (w *WorkspaceWatcher) matchesPattern(path string, pattern protocol.GlobPatt
438436 // Make path relative to basePath for matching
439437 relPath, err := filepath.Rel(basePath, path)
440438 if err != nil {
441− logger.Error("Error getting relative path", "path", path, "basePath", basePath, "error", err)
439+ logging.Error("Error getting relative path", "path", path, "basePath", basePath, "error", err)
442440 return false
443441 }
444442 relPath = filepath.ToSlash(relPath)
@@ -479,14 +477,14 @@ func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, chan
479477 if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) {
480478 err := w.client.NotifyChange(ctx, filePath)
481479 if err != nil {
482− logger.Error("Error notifying change", "error", err)
480+ logging.Error("Error notifying change", "error", err)
483481 }
484482 return
485483 }
486484
487485 // Notify LSP server about the file event using didChangeWatchedFiles
488486 if err := w.notifyFileEvent(ctx, uri, changeType); err != nil {
489− logger.Error("Error notifying LSP server about file event", "error", err)
487+ logging.Error("Error notifying LSP server about file event", "error", err)
490488 }
491489}
492490
@@ -494,7 +492,7 @@ func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, chan
494492func (w *WorkspaceWatcher) notifyFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) error {
495493 cnf := config.Get()
496494 if cnf.Debug {
497− logger.Debug("Notifying file event",
495+ logging.Debug("Notifying file event",
498496 "uri", uri,
499497 "changeType", changeType,
500498 )
@@ -618,7 +616,7 @@ func shouldExcludeFile(filePath string) bool {
618616 // Skip large files
619617 if info.Size() > maxFileSize {
620618 if cnf.Debug {
621− logger.Debug("Skipping large file",
619+ logging.Debug("Skipping large file",
622620 "path", filePath,
623621 "size", info.Size(),
624622 "maxSize", maxFileSize,
@@ -651,7 +649,7 @@ func (w *WorkspaceWatcher) openMatchingFile(ctx context.Context, path string) {
651649 if watched, _ := w.isPathWatched(path); watched {
652650 // Don't need to check if it's already open - the client.OpenFile handles that
653651 if err := w.client.OpenFile(ctx, path); err != nil && cnf.Debug {
654− logger.Error("Error opening file", "path", path, "error", err)
652+ logging.Error("Error opening file", "path", path, "error", err)
655653 }
656654 }
657655}