generated from dogmatiq/template-go
/
workspace.go
65 lines (51 loc) 路 1.29 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
57
58
59
60
61
62
63
64
65
package lsp
import (
"context"
"github.com/dogmatiq/dogmacli/internal/linter/diagnostic"
"github.com/dogmatiq/dogmacli/internal/lsp/proto"
"golang.org/x/exp/slog"
)
type workspaceFolder struct {
Dir string
Diagnostics map[string][]diagnostic.Diagnostic
}
func (h *handler) HandleWorkspaceDidChangeWorkspaceFolders(
ctx context.Context,
p proto.DidChangeWorkspaceFoldersParams,
) error {
for _, f := range p.Event.Removed {
if err := h.removeWorkspaceFolder(ctx, f); err != nil {
return err
}
}
for _, f := range p.Event.Added {
if err := h.addWorkspaceFolder(ctx, f); err != nil {
return err
}
}
return nil
}
func (h *handler) addWorkspaceFolder(ctx context.Context, f proto.WorkspaceFolder) error {
if h.workspaceFolders == nil {
h.workspaceFolders = map[proto.URI]*workspaceFolder{}
}
wf := &workspaceFolder{
Dir: f.URI.Path,
}
h.workspaceFolders[*f.URI] = wf
h.Logger.Debug(
"added workspace folder",
slog.String("name", *f.Name),
slog.String("path", f.URI.Path),
)
return h.lint(ctx, wf)
}
func (h *handler) removeWorkspaceFolder(ctx context.Context, f proto.WorkspaceFolder) error {
delete(h.workspaceFolders, *f.URI)
h.Logger.Debug(
"removed workspace folder",
slog.String("name", *f.Name),
slog.String("path", f.URI.Path),
)
return nil
}