Skip to content

Commit e540e15

Browse files
committed
Small fixes
1 parent 0ee1312 commit e540e15

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

internal/lsp/lsproto/jsonrpc.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ type RequestMessage struct {
7272

7373
func NewRequestMessage(method Method, id *ID, params any) *RequestMessage {
7474
return &RequestMessage{
75-
JSONRPC: JSONRPCVersion{},
76-
ID: id,
77-
Method: method,
78-
Params: params,
75+
ID: id,
76+
Method: method,
77+
Params: params,
7978
}
8079
}
8180

internal/lsp/server.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ func NewServer(opts *ServerOptions) *Server {
4040
newLine: opts.NewLine,
4141
fs: opts.FS,
4242
defaultLibraryPath: opts.DefaultLibraryPath,
43-
watchers: make(map[project.WatcherHandle]struct{}),
4443
}
4544
}
4645

@@ -67,9 +66,9 @@ type Server struct {
6766
initializeParams *lsproto.InitializeParams
6867
positionEncoding lsproto.PositionEncodingKind
6968

70-
watcheEnabled bool
69+
watchEnabled bool
7170
watcherID int
72-
watchers map[project.WatcherHandle]struct{}
71+
watchers core.Set[project.WatcherHandle]
7372
logger *project.Logger
7473
projectService *project.Service
7574
converters *ls.Converters
@@ -102,7 +101,7 @@ func (s *Server) Trace(msg string) {
102101

103102
// Client implements project.ServiceHost.
104103
func (s *Server) Client() project.Client {
105-
if !s.watcheEnabled {
104+
if !s.watchEnabled {
106105
return nil
107106
}
108107
return s
@@ -126,14 +125,14 @@ func (s *Server) WatchFiles(watchers []*lsproto.FileSystemWatcher) (project.Watc
126125
}
127126

128127
handle := project.WatcherHandle(watcherId)
129-
s.watchers[handle] = struct{}{}
128+
s.watchers.Add(handle)
130129
s.watcherID++
131130
return handle, nil
132131
}
133132

134133
// UnwatchFiles implements project.Client.
135134
func (s *Server) UnwatchFiles(handle project.WatcherHandle) error {
136-
if _, ok := s.watchers[handle]; ok {
135+
if s.watchers.Has(handle) {
137136
if err := s.sendRequest(lsproto.MethodClientUnregisterCapability, &lsproto.UnregistrationParams{
138137
Unregisterations: []*lsproto.Unregistration{
139138
{
@@ -144,7 +143,7 @@ func (s *Server) UnwatchFiles(handle project.WatcherHandle) error {
144143
}); err != nil {
145144
return fmt.Errorf("failed to unregister file watcher: %w", err)
146145
}
147-
delete(s.watchers, handle)
146+
s.watchers.Delete(handle)
148147
return nil
149148
}
150149

@@ -364,13 +363,13 @@ func (s *Server) handleInitialize(req *lsproto.RequestMessage) error {
364363

365364
func (s *Server) handleInitialized(req *lsproto.RequestMessage) error {
366365
if s.initializeParams.Capabilities.Workspace.DidChangeWatchedFiles != nil && *s.initializeParams.Capabilities.Workspace.DidChangeWatchedFiles.DynamicRegistration {
367-
s.watcheEnabled = true
366+
s.watchEnabled = true
368367
}
369368

370369
s.logger = project.NewLogger([]io.Writer{s.stderr}, "" /*file*/, project.LogLevelVerbose)
371370
s.projectService = project.NewService(s, project.ServiceOptions{
372371
Logger: s.logger,
373-
WatchEnabled: s.watcheEnabled,
372+
WatchEnabled: s.watchEnabled,
374373
PositionEncoding: s.positionEncoding,
375374
})
376375

0 commit comments

Comments
 (0)