(serverName, serverConfig, pluginLabel)
| 132 | } |
| 133 | |
| 134 | function normalizeServerConfig(serverName, serverConfig, pluginLabel) { |
| 135 | const context = `${pluginLabel}.${serverName}`; |
| 136 | const errors = []; |
| 137 | |
| 138 | if (!isPlainObject(serverConfig)) { |
| 139 | return { |
| 140 | normalized: null, |
| 141 | errors: [`${context} must be an object`], |
| 142 | }; |
| 143 | } |
| 144 | |
| 145 | for (const field of Object.keys(serverConfig)) { |
| 146 | if (LEGACY_LSP_FIELD_SET.has(field)) { |
| 147 | errors.push(`${context} uses legacy field "${field}"`); |
| 148 | } |
| 149 | |
| 150 | if (!ALLOWED_LSP_FIELD_SET.has(field)) { |
| 151 | errors.push(`${context} uses unsupported field "${field}"`); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | const normalized = {}; |
| 156 | for (const key of ALLOWED_LSP_FIELDS) { |
| 157 | if (!Object.hasOwn(serverConfig, key)) { |
| 158 | continue; |
| 159 | } |
| 160 | |
| 161 | const value = serverConfig[key]; |
| 162 | if (key === "command" || key === "transport" || key === "workspaceFolder") { |
| 163 | if (typeof value !== "string") { |
| 164 | errors.push(`${context}.${key} must be a string`); |
| 165 | continue; |
| 166 | } |
| 167 | normalized[key] = value; |
| 168 | continue; |
| 169 | } |
| 170 | |
| 171 | if (key === "args") { |
| 172 | const normalizedValue = normalizeStringArray(value, `${context}.${key}`, errors); |
| 173 | if (normalizedValue) { |
| 174 | normalized[key] = normalizedValue; |
| 175 | } |
| 176 | continue; |
| 177 | } |
| 178 | |
| 179 | if (key === "extensionToLanguage") { |
| 180 | const normalizedValue = normalizeExtensionToLanguage( |
| 181 | value, |
| 182 | `${context}.${key}`, |
| 183 | errors, |
| 184 | ); |
| 185 | if (normalizedValue) { |
| 186 | normalized[key] = normalizedValue; |
| 187 | } |
| 188 | continue; |
| 189 | } |
| 190 | |
| 191 | if (key === "env") { |
no test coverage detected