@@ -16,8 +16,6 @@ import (
16 "github.com/kujtimiihoxha/termai/internal/lsp/protocol"
16 "github.com/kujtimiihoxha/termai/internal/lsp/protocol"
19−var logger = logging.Get()
21// WorkspaceWatcher manages LSP file watching
19// WorkspaceWatcher manages LSP file watching
22type WorkspaceWatcher struct {
20type WorkspaceWatcher struct {
23 client *lsp.Client
21 client *lsp.Client
@@ -53,7 +51,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
54 // Print detailed registration information for debugging
52 // Print detailed registration information for debugging
55 if cnf.Debug {
53 if cnf.Debug {
56− logger.Debug("Adding file watcher registrations",
54+ logging.Debug("Adding file watcher registrations",
58 "watchers", len(watchers),
56 "watchers", len(watchers),
59 "total", len(w.registrations),
57 "total", len(w.registrations),
@@ -61,26 +59,26 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
63 for i, watcher := range watchers {
61 for i, watcher := range watchers {
64− logger.Debug("Registration", "index", i+1)
62+ logging.Debug("Registration", "index", i+1)
66 // Log the GlobPattern
64 // Log the GlobPattern
67 switch v := watcher.GlobPattern.Value.(type) {
65 switch v := watcher.GlobPattern.Value.(type) {
68 case string:
66 case string:
69− logger.Debug("GlobPattern", "pattern", v)
67+ logging.Debug("GlobPattern", "pattern", v)
70 case protocol.RelativePattern:
68 case protocol.RelativePattern:
71− logger.Debug("GlobPattern", "pattern", v.Pattern)
69+ logging.Debug("GlobPattern", "pattern", v.Pattern)
73 // Log BaseURI details
71 // Log BaseURI details
74 switch u := v.BaseURI.Value.(type) {
72 switch u := v.BaseURI.Value.(type) {
75 case string:
73 case string:
76− logger.Debug("BaseURI", "baseURI", u)
74+ logging.Debug("BaseURI", "baseURI", u)
77 case protocol.DocumentUri:
75 case protocol.DocumentUri:
78− logger.Debug("BaseURI", "baseURI", u)
76+ logging.Debug("BaseURI", "baseURI", u)
80− logger.Debug("BaseURI", "baseURI", u)
78+ logging.Debug("BaseURI", "baseURI", u)
83− logger.Debug("GlobPattern", "unknown type", fmt.Sprintf("%T", v))
81+ logging.Debug("GlobPattern", "unknown type", fmt.Sprintf("%T", v))
86 // Log WatchKind
84 // Log WatchKind
@@ -89,7 +87,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
89 watchKind = *watcher.Kind
87 watchKind = *watcher.Kind
92− logger.Debug("WatchKind", "kind", watchKind)
90+ logging.Debug("WatchKind", "kind", watchKind)
94 // Test match against some example paths
92 // Test match against some example paths
95 testPaths := []string{
93 testPaths := []string{
@@ -99,7 +97,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
100 for _, testPath := range testPaths {
98 for _, testPath := range testPaths {
101 isMatch := w.matchesPattern(testPath, watcher.GlobPattern)
99 isMatch := w.matchesPattern(testPath, watcher.GlobPattern)
102− logger.Debug("Test path", "path", testPath, "matches", isMatch)
100+ logging.Debug("Test path", "path", testPath, "matches", isMatch)
@@ -119,7 +117,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
119 if d.IsDir() {
117 if d.IsDir() {
120 if path != w.workspacePath && shouldExcludeDir(path) {
118 if path != w.workspacePath && shouldExcludeDir(path) {
121 if cnf.Debug {
119 if cnf.Debug {
122− logger.Debug("Skipping excluded directory", "path", path)
120+ logging.Debug("Skipping excluded directory", "path", path)
124 return filepath.SkipDir
122 return filepath.SkipDir
@@ -139,7 +137,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
140 elapsedTime := time.Since(startTime)
138 elapsedTime := time.Since(startTime)
141 if cnf.Debug {
139 if cnf.Debug {
142− logger.Debug("Workspace scan complete",
140+ logging.Debug("Workspace scan complete",
143 "filesOpened", filesOpened,
141 "filesOpened", filesOpened,
144 "elapsedTime", elapsedTime.Seconds(),
142 "elapsedTime", elapsedTime.Seconds(),
145 "workspacePath", w.workspacePath,
143 "workspacePath", w.workspacePath,
@@ -147,7 +145,7 @@ func (w *WorkspaceWatcher) AddRegistrations(ctx context.Context, id string, watc
149 if err != nil && cnf.Debug {
147 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)
@@ -164,7 +162,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
165 watcher, err := fsnotify.NewWatcher()
163 watcher, err := fsnotify.NewWatcher()
166 if err != nil {
164 if err != nil {
167− logger.Error("Error creating watcher", "error", err)
165+ logging.Error("Error creating watcher", "error", err)
169 defer watcher.Close()
167 defer watcher.Close()
@@ -178,7 +176,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
178 if d.IsDir() && path != workspacePath {
176 if d.IsDir() && path != workspacePath {
179 if shouldExcludeDir(path) {
177 if shouldExcludeDir(path) {
180 if cnf.Debug {
178 if cnf.Debug {
181− logger.Debug("Skipping excluded directory", "path", path)
179+ logging.Debug("Skipping excluded directory", "path", path)
183 return filepath.SkipDir
181 return filepath.SkipDir
@@ -188,14 +186,14 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
188 if d.IsDir() {
186 if d.IsDir() {
189 err = watcher.Add(path)
187 err = watcher.Add(path)
190 if err != nil {
188 if err != nil {
191− logger.Error("Error watching path", "path", path, "error", err)
189+ logging.Error("Error watching path", "path", path, "error", err)
195 return nil
193 return nil
197 if err != nil {
195 if err != nil {
198− logger.Error("Error walking workspace", "error", err)
196+ logging.Error("Error walking workspace", "error", err)
201 // Event loop
199 // Event loop
@@ -217,7 +215,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
217 // Skip excluded directories
215 // Skip excluded directories
218 if !shouldExcludeDir(event.Name) {
216 if !shouldExcludeDir(event.Name) {
219 if err := watcher.Add(event.Name); err != nil {
217 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)
@@ -232,7 +230,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
232 // Debug logging
230 // Debug logging
233 if cnf.Debug {
231 if cnf.Debug {
234 matched, kind := w.isPathWatched(event.Name)
232 matched, kind := w.isPathWatched(event.Name)
235− logger.Debug("File event",
233+ logging.Debug("File event",
236 "path", event.Name,
234 "path", event.Name,
237 "operation", event.Op.String(),
235 "operation", event.Op.String(),
238 "watched", matched,
236 "watched", matched,
@@ -277,7 +275,7 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
280− logger.Error("Error watching file", "error", err)
278+ logging.Error("Error watching file", "error", err)
@@ -402,7 +400,7 @@ func matchesSimpleGlob(pattern, path string) bool {
402 // Fall back to simple matching for simpler patterns
400 // Fall back to simple matching for simpler patterns
403 matched, err := filepath.Match(pattern, path)
401 matched, err := filepath.Match(pattern, path)
404 if err != nil {
402 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)
406 return false
404 return false
@@ -413,7 +411,7 @@ func matchesSimpleGlob(pattern, path string) bool {
413func (w *WorkspaceWatcher) matchesPattern(path string, pattern protocol.GlobPattern) bool {
411func (w *WorkspaceWatcher) matchesPattern(path string, pattern protocol.GlobPattern) bool {
414 patternInfo, err := pattern.AsPattern()
412 patternInfo, err := pattern.AsPattern()
415 if err != nil {
413 if err != nil {
416− logger.Error("Error parsing pattern", "pattern", pattern, "error", err)
414+ logging.Error("Error parsing pattern", "pattern", pattern, "error", err)
417 return false
415 return false
@@ -438,7 +436,7 @@ func (w *WorkspaceWatcher) matchesPattern(path string, pattern protocol.GlobPatt
438 // Make path relative to basePath for matching
436 // Make path relative to basePath for matching
439 relPath, err := filepath.Rel(basePath, path)
437 relPath, err := filepath.Rel(basePath, path)
440 if err != nil {
438 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)
442 return false
440 return false
444 relPath = filepath.ToSlash(relPath)
442 relPath = filepath.ToSlash(relPath)
@@ -479,14 +477,14 @@ func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, chan
479 if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) {
477 if changeType == protocol.FileChangeType(protocol.Changed) && w.client.IsFileOpen(filePath) {
480 err := w.client.NotifyChange(ctx, filePath)
478 err := w.client.NotifyChange(ctx, filePath)
481 if err != nil {
479 if err != nil {
482− logger.Error("Error notifying change", "error", err)
480+ logging.Error("Error notifying change", "error", err)
487 // Notify LSP server about the file event using didChangeWatchedFiles
485 // Notify LSP server about the file event using didChangeWatchedFiles
488 if err := w.notifyFileEvent(ctx, uri, changeType); err != nil {
486 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)
@@ -494,7 +492,7 @@ func (w *WorkspaceWatcher) handleFileEvent(ctx context.Context, uri string, chan
494func (w *WorkspaceWatcher) notifyFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) error {
492func (w *WorkspaceWatcher) notifyFileEvent(ctx context.Context, uri string, changeType protocol.FileChangeType) error {
495 cnf := config.Get()
493 cnf := config.Get()
496 if cnf.Debug {
494 if cnf.Debug {
497− logger.Debug("Notifying file event",
495+ logging.Debug("Notifying file event",
498 "uri", uri,
496 "uri", uri,
499 "changeType", changeType,
497 "changeType", changeType,
@@ -618,7 +616,7 @@ func shouldExcludeFile(filePath string) bool {
618 // Skip large files
616 // Skip large files
619 if info.Size() > maxFileSize {
617 if info.Size() > maxFileSize {
620 if cnf.Debug {
618 if cnf.Debug {
621− logger.Debug("Skipping large file",
619+ logging.Debug("Skipping large file",
622 "path", filePath,
620 "path", filePath,
623 "size", info.Size(),
621 "size", info.Size(),
624 "maxSize", maxFileSize,
622 "maxSize", maxFileSize,
@@ -651,7 +649,7 @@ func (w *WorkspaceWatcher) openMatchingFile(ctx context.Context, path string) {
651 if watched, _ := w.isPathWatched(path); watched {
649 if watched, _ := w.isPathWatched(path); watched {
652 // Don't need to check if it's already open - the client.OpenFile handles that
650 // Don't need to check if it's already open - the client.OpenFile handles that
653 if err := w.client.OpenFile(ctx, path); err != nil && cnf.Debug {
651 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)