@@ -40,7 +40,6 @@ func NewServer(opts *ServerOptions) *Server {
40
40
newLine : opts .NewLine ,
41
41
fs : opts .FS ,
42
42
defaultLibraryPath : opts .DefaultLibraryPath ,
43
- watchers : make (map [project.WatcherHandle ]struct {}),
44
43
}
45
44
}
46
45
@@ -67,9 +66,9 @@ type Server struct {
67
66
initializeParams * lsproto.InitializeParams
68
67
positionEncoding lsproto.PositionEncodingKind
69
68
70
- watcheEnabled bool
69
+ watchEnabled bool
71
70
watcherID int
72
- watchers map [project.WatcherHandle ]struct {}
71
+ watchers core. Set [project.WatcherHandle ]
73
72
logger * project.Logger
74
73
projectService * project.Service
75
74
converters * ls.Converters
@@ -102,7 +101,7 @@ func (s *Server) Trace(msg string) {
102
101
103
102
// Client implements project.ServiceHost.
104
103
func (s * Server ) Client () project.Client {
105
- if ! s .watcheEnabled {
104
+ if ! s .watchEnabled {
106
105
return nil
107
106
}
108
107
return s
@@ -126,14 +125,14 @@ func (s *Server) WatchFiles(watchers []*lsproto.FileSystemWatcher) (project.Watc
126
125
}
127
126
128
127
handle := project .WatcherHandle (watcherId )
129
- s .watchers [ handle ] = struct {}{}
128
+ s .watchers . Add ( handle )
130
129
s .watcherID ++
131
130
return handle , nil
132
131
}
133
132
134
133
// UnwatchFiles implements project.Client.
135
134
func (s * Server ) UnwatchFiles (handle project.WatcherHandle ) error {
136
- if _ , ok := s .watchers [ handle ]; ok {
135
+ if s .watchers . Has ( handle ) {
137
136
if err := s .sendRequest (lsproto .MethodClientUnregisterCapability , & lsproto.UnregistrationParams {
138
137
Unregisterations : []* lsproto.Unregistration {
139
138
{
@@ -144,7 +143,7 @@ func (s *Server) UnwatchFiles(handle project.WatcherHandle) error {
144
143
}); err != nil {
145
144
return fmt .Errorf ("failed to unregister file watcher: %w" , err )
146
145
}
147
- delete ( s .watchers , handle )
146
+ s .watchers . Delete ( handle )
148
147
return nil
149
148
}
150
149
@@ -364,13 +363,13 @@ func (s *Server) handleInitialize(req *lsproto.RequestMessage) error {
364
363
365
364
func (s * Server ) handleInitialized (req * lsproto.RequestMessage ) error {
366
365
if s .initializeParams .Capabilities .Workspace .DidChangeWatchedFiles != nil && * s .initializeParams .Capabilities .Workspace .DidChangeWatchedFiles .DynamicRegistration {
367
- s .watcheEnabled = true
366
+ s .watchEnabled = true
368
367
}
369
368
370
369
s .logger = project .NewLogger ([]io.Writer {s .stderr }, "" /*file*/ , project .LogLevelVerbose )
371
370
s .projectService = project .NewService (s , project.ServiceOptions {
372
371
Logger : s .logger ,
373
- WatchEnabled : s .watcheEnabled ,
372
+ WatchEnabled : s .watchEnabled ,
374
373
PositionEncoding : s .positionEncoding ,
375
374
})
376
375
0 commit comments