load static method

Loads the configuration for env: the built-in defaults merged with .fah/lsp.json from env's cwd when present. A malformed config file is reported in warnings and otherwise ignored (never fatal).

Implementation

static Future<LspConfig> load(ExecutionEnv env) async {
  final base = LspConfig.defaults();
  final read = await env.readTextFile(lspConfigFileName);
  if (read.isErr) return base;
  final Object? parsed;
  try {
    parsed = jsonDecode(read.valueOrNull!);
  } on Object catch (error) {
    return LspConfig(
      servers: base.servers,
      warnings: ['ignoring malformed $lspConfigFileName: $error'],
    );
  }
  if (parsed is! Map<String, dynamic>) {
    return LspConfig(
      servers: base.servers,
      warnings: ['ignoring $lspConfigFileName: top level must be an object'],
    );
  }

  final warnings = <String>[];
  final servers = Map<String, LspServerConfig>.of(base.servers);
  _mergeServers(parsed, servers, warnings);
  final idleTimeout = _idleTimeoutFor(parsed, base.idleTimeout);
  return LspConfig(
    servers: servers,
    idleTimeout: idleTimeout,
    warnings: warnings,
  );
}