Module: MilkTea::LSP::Server::ServerConfiguration
- Included in:
- MilkTea::LSP::Server
- Defined in:
- lib/milk_tea/lsp/server/configuration.rb
Instance Method Summary collapse
- #apply_configuration_settings(settings) ⇒ Object
- #apply_dependency_resolution_mode(mode) ⇒ Object
- #apply_platform_override(platform) ⇒ Object
- #apply_strict_current_root_diagnostics(enabled) ⇒ Object
- #dependency_resolution_mode_from_settings(settings) ⇒ Object
- #formatter_mode_from_settings(settings) ⇒ Object
- #platform_override_from_settings(settings) ⇒ Object
- #pull_client_configuration ⇒ Object
- #strict_current_root_diagnostics_from_settings(settings) ⇒ Object
Instance Method Details
#apply_configuration_settings(settings) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 32 def apply_configuration_settings(settings) mode = formatter_mode_from_settings(settings) @format_mode = mode if mode dependency_resolution_mode = dependency_resolution_mode_from_settings(settings) apply_dependency_resolution_mode(dependency_resolution_mode) if dependency_resolution_mode platform_provided, platform_override = platform_override_from_settings(settings) apply_platform_override(platform_override) if platform_provided strict_root_provided, strict_root_enabled = strict_current_root_diagnostics_from_settings(settings) apply_strict_current_root_diagnostics(strict_root_enabled) if strict_root_provided end |
#apply_dependency_resolution_mode(mode) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 119 def apply_dependency_resolution_mode(mode) normalized = DependencyResolution.normalize_mode(mode) return if @dependency_resolution_mode == normalized @dependency_resolution_mode = normalized @workspace.dependency_resolution_mode = normalized @diagnostic_report_cache.clear @workspace_diagnostic_cache.clear open_uris = @workspace.open_document_uris invalidate_document_caches_for(open_uris) open_uris.each do |uri| schedule_diagnostics(uri, force: true, lint_tier: :full) unless @workspace.background_document?(uri) end end |
#apply_platform_override(platform) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 134 def apply_platform_override(platform) normalized = platform.nil? ? nil : ModuleLoader.normalize_platform_name(platform) return if @platform_override == normalized @platform_override = normalized @workspace.platform_override = normalized @diagnostic_report_cache.clear @workspace_diagnostic_cache.clear open_uris = @workspace.open_document_uris invalidate_document_caches_for(open_uris) open_uris.each do |uri| schedule_diagnostics(uri, force: true, lint_tier: :full) unless @workspace.background_document?(uri) end end |
#apply_strict_current_root_diagnostics(enabled) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 149 def apply_strict_current_root_diagnostics(enabled) normalized = !!enabled return if @workspace.strict_current_root_diagnostics_enabled == normalized @workspace.strict_current_root_diagnostics_enabled = normalized @diagnostic_report_cache.clear @workspace_diagnostic_cache.clear open_uris = @workspace.open_document_uris invalidate_document_caches_for(open_uris) open_uris.each do |uri| schedule_diagnostics(uri, force: true, lint_tier: :full) unless @workspace.background_document?(uri) end end |
#dependency_resolution_mode_from_settings(settings) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 61 def dependency_resolution_mode_from_settings(settings) return nil unless settings.is_a?(Hash) mode = settings.dig('milkTea', 'lsp', 'dependencyResolution') || settings.dig('milk_tea', 'lsp', 'dependencyResolution') || settings.dig('lsp', 'dependencyResolution') return nil unless mode normalized = DependencyResolution.normalize_mode(mode) return normalized if DependencyResolution::MODES.include?(normalized) nil end |
#formatter_mode_from_settings(settings) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 46 def formatter_mode_from_settings(settings) return nil unless settings.is_a?(Hash) mode = settings.dig('milkTea', 'format', 'mode') || settings.dig('milk_tea', 'format', 'mode') || settings.dig('format', 'mode') return nil unless mode normalized = mode.to_s.strip.downcase.to_sym return normalized if Formatter::MODES.include?(normalized) nil end |
#platform_override_from_settings(settings) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 76 def platform_override_from_settings(settings) return [false, nil] unless settings.is_a?(Hash) value = settings.dig('milkTea', 'lsp', 'platform') || settings.dig('milk_tea', 'lsp', 'platform') || settings.dig('lsp', 'platform') return [false, nil] if value.nil? normalized = value.to_s.strip.downcase return [true, nil] if normalized.empty? || normalized == 'auto' [true, ModuleLoader.normalize_platform_name(normalized)] rescue ArgumentError [false, nil] end |
#pull_client_configuration ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 7 def pull_client_configuration items = [ { section: 'milkTea.format.mode' }, { section: 'milkTea.lsp.dependencyResolution' }, { section: 'milkTea.lsp.platform' }, { section: 'milkTea.lsp.strictCurrentRootDiagnostics' }, ] Protocol.send_request('workspace/configuration', { items: items }) do |result, error| if error warn "Configuration pull failed: #{error['message']}" elsif result.is_a?(Array) settings = {} items.each_with_index do |item, idx| value = result[idx] next if value.nil? section_parts = item[:section].split('.') current = settings section_parts[0...-1].each { |k| current = (current[k] ||= {}) } current[section_parts.last] = value end apply_configuration_settings(settings) end end end |
#strict_current_root_diagnostics_from_settings(settings) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/milk_tea/lsp/server/configuration.rb', line 93 def strict_current_root_diagnostics_from_settings(settings) return [false, nil] unless settings.is_a?(Hash) value = settings.dig('milkTea', 'lsp', 'strictCurrentRootDiagnostics') || settings.dig('milk_tea', 'lsp', 'strictCurrentRootDiagnostics') || settings.dig('lsp', 'strictCurrentRootDiagnostics') return [false, nil] if value.nil? normalized = case value when true, false value else case value.to_s.strip.downcase when 'true', '1', 'yes', 'on' true when 'false', '0', 'no', 'off', '' false else return [false, nil] end end [true, normalized] end |