clerk/internal/lsp/config.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com lsp: dont error if there's no config provided, 2 months ago
olexsmir@gmail.com lsp: dont error if there's no config provided, 2 months ago
| 1 | package lsp |
| 2 | |
| 3 | import ( |
| 4 | "github.com/go-json-experiment/json" |
| 5 | "go.lsp.dev/protocol" |
| 6 | ) |
| 7 | |
| 8 | type Config struct { |
| 9 | SemanticHighlighting bool |
| 10 | |
| 11 | // TODO: Formatter |
| 12 | // TODO: Linter |
| 13 | } |
| 14 | |
| 15 | var DefaultConfig = Config{ |
| 16 | SemanticHighlighting: true, |
| 17 | } |
| 18 | |
| 19 | func (c *Config) merge(v protocol.LSPAny) error { |
| 20 | if len(v) == 0 { // no settings provided |
| 21 | return nil |
| 22 | } |
| 23 | |
| 24 | var patch struct { |
| 25 | SemanticHighlighting *bool `json:"semantic_highlighting,case:ignore"` |
| 26 | } |
| 27 | |
| 28 | if err := json.Unmarshal(v, &patch); err != nil { |
| 29 | return err |
| 30 | } |
| 31 | if patch.SemanticHighlighting != nil { |
| 32 | c.SemanticHighlighting = *patch.SemanticHighlighting |
| 33 | } |
| 34 | return nil |
| 35 | } |
| 36 | |
| 37 | func (s *server) semanticHighlightingEnabled() bool { |
| 38 | s.cfgMu.RLock() |
| 39 | defer s.cfgMu.RUnlock() |
| 40 | return s.config.SemanticHighlighting |
| 41 | } |