-
Notifications
You must be signed in to change notification settings - Fork 108
/
workspace.go
56 lines (44 loc) · 1.45 KB
/
workspace.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
package lsp
import (
"github.com/issue9/sliceutil"
"github.com/caixw/apidoc/v7/internal/locale"
"github.com/caixw/apidoc/v7/internal/lsp/protocol"
)
// workspace/workspaceFolders
//
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_workspaceFolders
func (s *server) workspaceWorkspaceFolders() error {
return s.Send("workspace/workspaceFolders", nil, func(folders *[]protocol.WorkspaceFolder) error {
s.workspaceMux.Lock()
defer s.workspaceMux.Unlock()
for _, f := range s.folders {
f.close()
}
s.folders = s.folders[:0]
s.appendFolders(*folders...)
return nil
})
}
// workspace/didChangeWorkspaceFolders
//
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_didChangeWorkspaceFolders
func (s *server) workspaceDidChangeWorkspaceFolders(notify bool, in *protocol.DidChangeWorkspaceFoldersParams, out *interface{}) error {
if s.getState() != serverInitialized {
return newError(ErrInvalidRequest, locale.ErrInvalidLSPState)
}
s.workspaceMux.Lock()
defer s.workspaceMux.Unlock()
old := s.folders
s.folders = sliceutil.Delete(s.folders, func(i *folder) bool {
return sliceutil.Count(in.Event.Removed, func(j protocol.WorkspaceFolder) bool {
return j.URI == i.URI
}) > 0
})
deleted := old[len(s.folders):]
for _, f := range deleted {
f.close()
}
s.appendFolders(in.Event.Added...)
return nil
}