@@ -15,23 +15,23 @@ import (
1515gitignore "github.com/sabhiram/go-gitignore"
1616)
1717
18+ var debug = os .Getenv ("DEBUG" ) != ""
19+
1820// WorkspaceWatcher manages file watching and version tracking
1921type WorkspaceWatcher struct {
2022client * lsp.Client
2123ignore * gitignore.GitIgnore
2224workspacePath string
2325
24- // Debouncing related fields
2526debounceTime time.Duration
2627debounceMap map [string ]* time.Timer
2728debounceMu sync.Mutex
2829}
2930
30- // NewWorkspaceWatcher creates a new instance of WorkspaceWatcher
3131func NewWorkspaceWatcher (client * lsp.Client ) * WorkspaceWatcher {
3232return & WorkspaceWatcher {
3333client : client ,
34- debounceTime : 1000 * time .Millisecond , // Configurable debounce duration
34+ debounceTime : 1000 * time .Millisecond ,
3535debounceMap : make (map [string ]* time.Timer ),
3636}
3737}
@@ -42,7 +42,9 @@ func (w *WorkspaceWatcher) loadGitIgnore(workspacePath string) error {
4242// Read and log the content of .gitignore
4343content , err := os .ReadFile (gitignorePath )
4444if err != nil {
45- log .Printf ("DEBUG: Error reading .gitignore: %v" , err )
45+ if debug {
46+ log .Printf ("DEBUG: Error reading .gitignore: %v" , err )
47+ }
4648return fmt .Errorf ("error reading gitignore: %w" , err )
4749}
4850log .Printf ("DEBUG: .gitignore content:\n %s" , string (content ))
@@ -53,14 +55,15 @@ func (w *WorkspaceWatcher) loadGitIgnore(workspacePath string) error {
5355}
5456w .ignore = ignore
5557
56- log .Printf ("DEBUG: Successfully loaded .gitignore" )
58+ if debug {
59+ log .Printf ("DEBUG: Successfully loaded .gitignore" )
60+ }
5761return nil
5862}
5963
6064func (w * WorkspaceWatcher ) shouldIgnorePath (path string , workspacePath string ) bool {
6165// Always ignore .git directory
6266if filepath .Base (path ) == ".git" {
63- log .Printf ("DEBUG: Ignoring .git directory: %s" , path )
6467return true
6568}
6669
@@ -81,13 +84,15 @@ func (w *WorkspaceWatcher) shouldIgnorePath(path string, workspacePath string) b
8184
8285matches , pattern := w .ignore .MatchesPathHow (relPath )
8386
84- log .Printf ("DEBUG: Path check details:" )
85- log .Printf (" Original path: %s" , path )
86- log .Printf (" Workspace: %s" , workspacePath )
87- log .Printf (" Relative path: %s" , relPath )
88- log .Printf (" Matches? %v" , matches )
89- if pattern != nil {
90- log .Printf (" Matched pattern: %s (line %d)" , pattern .Line , pattern .LineNo )
87+ if debug {
88+ log .Printf ("DEBUG: Path check details:" )
89+ log .Printf (" Original path: %s" , path )
90+ log .Printf (" Workspace: %s" , workspacePath )
91+ log .Printf (" Relative path: %s" , relPath )
92+ log .Printf (" Matches gitignore? %v" , matches )
93+ if pattern != nil {
94+ log .Printf (" Matched pattern: %s (line %d)" , pattern .Line , pattern .LineNo )
95+ }
9196}
9297
9398return matches
@@ -117,7 +122,6 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
117122}
118123
119124if info .IsDir () {
120- // Check if directory should be ignored
121125if w .shouldIgnorePath (path , workspacePath ) {
122126return filepath .SkipDir
123127}
@@ -151,13 +155,17 @@ func (w *WorkspaceWatcher) WatchWorkspace(ctx context.Context, workspacePath str
151155
152156// Skip temporary files and backup files
153157if strings .HasSuffix (event .Name , "~" ) || strings .HasSuffix (event .Name , ".swp" ) {
154- log .Println ("Skipping ~" )
158+ if debug {
159+ log .Println ("Skipping temporary file" )
160+ }
155161continue
156162}
157163
158164// Skip ignored paths
159165if w .shouldIgnorePath (event .Name , workspacePath ) {
160- log .Println ("Skipping" , event .Name )
166+ if debug {
167+ log .Println ("Skipping" , event .Name )
168+ }
161169continue
162170}
163171
0 commit comments