ParseFromPlugins parses the @effect/language-service plugin config from the plugins array. The plugins parameter is the value of compilerOptions.plugins from tsconfig.json. Returns nil if the plugin is not configured or if diagnosticSeverity is explicitly set to null.
(value any)
| 10 | // The plugins parameter is the value of compilerOptions.plugins from tsconfig.json. |
| 11 | // Returns nil if the plugin is not configured or if diagnosticSeverity is explicitly set to null. |
| 12 | func ParseFromPlugins(value any) *EffectPluginOptions { |
| 13 | plugins, ok := value.([]any) |
| 14 | if !ok { |
| 15 | return nil |
| 16 | } |
| 17 | |
| 18 | for _, p := range plugins { |
| 19 | var getPluginValue func(string) (any, bool) |
| 20 | switch pluginMap := p.(type) { |
| 21 | case *collections.OrderedMap[string, any]: |
| 22 | getPluginValue = pluginMap.Get |
| 23 | case map[string]any: |
| 24 | getPluginValue = func(key string) (any, bool) { |
| 25 | val, exists := pluginMap[key] |
| 26 | return val, exists |
| 27 | } |
| 28 | default: |
| 29 | continue |
| 30 | } |
| 31 | |
| 32 | name, found := getPluginValue("name") |
| 33 | if !found || name != EffectPluginName { |
| 34 | continue |
| 35 | } |
| 36 | |
| 37 | // Found our plugin, parse the config |
| 38 | result := &EffectPluginOptions{ |
| 39 | Refactors: true, // default: true |
| 40 | Diagnostics: true, // default: true |
| 41 | IncludeSuggestionsInTsc: true, // default: true |
| 42 | Quickinfo: true, // default: true |
| 43 | Completions: true, // default: true |
| 44 | Goto: true, // default: true |
| 45 | Renames: true, // default: true |
| 46 | IgnoreEffectSuggestionsInTscExitCode: true, // default: true |
| 47 | IgnoreEffectWarningsInTscExitCode: false, // default: false |
| 48 | DiagnosticSeverity: make(map[string]Severity), |
| 49 | } |
| 50 | |
| 51 | // Parse refactors (default: true) |
| 52 | if val, exists := getPluginValue("refactors"); exists { |
| 53 | if b, ok := val.(bool); ok { |
| 54 | result.Refactors = b |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | // Parse diagnostics (default: true) |
| 59 | if val, exists := getPluginValue("diagnostics"); exists { |
| 60 | if b, ok := val.(bool); ok { |
| 61 | result.Diagnostics = b |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // Parse diagnosticSeverity |
| 66 | if diag, exists := getPluginValue("diagnosticSeverity"); exists { |
| 67 | if diag == nil { |
| 68 | // diagnosticSeverity: null means explicitly disabled |
| 69 | return nil |