clerk/internal/lsp/config.go (view raw)
Oleksandr Smirnov
Oleksandr Smirnov
olexsmir@gmail.com lsp: latin to cyrillic transliteration, 1 month ago
olexsmir@gmail.com lsp: latin to cyrillic transliteration, 1 month 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 | // LatinToCyrillicCompletion matches Latin input against Cyrillic labels. |
| 12 | LatinToCyrillicCompletion bool |
| 13 | |
| 14 | // TODO: Formatter |
| 15 | // TODO: Linter |
| 16 | } |
| 17 | |
| 18 | var DefaultConfig = Config{ |
| 19 | SemanticHighlighting: true, |
| 20 | LatinToCyrillicCompletion: false, |
| 21 | } |
| 22 | |
| 23 | func (c *Config) merge(v protocol.LSPAny) error { |
| 24 | if len(v) == 0 { // no settings provided |
| 25 | return nil |
| 26 | } |
| 27 | |
| 28 | var patch struct { |
| 29 | SemanticHighlighting *bool `json:"semantic_highlighting,case:ignore"` |
| 30 | LatinToCyrillicCompletion *bool `json:"latin_to_cyrillic_completion,case:ignore"` |
| 31 | } |
| 32 | |
| 33 | if err := json.Unmarshal(v, &patch); err != nil { |
| 34 | return err |
| 35 | } |
| 36 | if patch.SemanticHighlighting != nil { |
| 37 | c.SemanticHighlighting = *patch.SemanticHighlighting |
| 38 | } |
| 39 | if patch.LatinToCyrillicCompletion != nil { |
| 40 | c.LatinToCyrillicCompletion = *patch.LatinToCyrillicCompletion |
| 41 | } |
| 42 | return nil |
| 43 | } |
| 44 | |
| 45 | func (s *server) semanticHighlightingEnabled() bool { |
| 46 | s.mu.RLock() |
| 47 | defer s.mu.RUnlock() |
| 48 | return s.config.SemanticHighlighting |
| 49 | } |
| 50 | |
| 51 | func (s *server) latinToCyrillicCompletionEnabled() bool { |
| 52 | s.mu.RLock() |
| 53 | defer s.mu.RUnlock() |
| 54 | return s.config.LatinToCyrillicCompletion |
| 55 | } |