fix: ensure config.yaml exists and is populated when accessed (#11915)

* fix: ensure config.yaml exists and is populated when accessed

- Opening a config profile (gear icon) now creates config.yaml with
  defaults if the file is missing, matching startup behavior
- Empty config.yaml files are detected and populated with default config
  instead of causing parse errors

* refactor: improve readability of config existence check
This commit is contained in:
Dallin Romney 2026-03-26 18:19:54 -07:00 • committed by GitHub
parent 16a540c337
commit fd7ade8f3f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 9 deletions

View file

@ -10,6 +10,7 @@ import {
ILLMLogger,
} from "../index.js";
import { GlobalContext } from "../util/GlobalContext.js";
import { getConfigYamlPath } from "../util/paths.js";
import EventEmitter from "node:events";
import {
@ -637,6 +638,7 @@ export class ConfigHandler {
}
if (profile.profileDescription.profileType === "local") {
getConfigYamlPath();
const configFile = element?.sourceFile ?? profile.profileDescription.uri;
await this.ide.openFile(configFile);
} else {

View file

@ -118,15 +118,12 @@ export function getConfigJsonPath(): string {
export function getConfigYamlPath(ideType?: IdeType): string {
const p = path.join(getContinueGlobalPath(), "config.yaml");
if (!fs.existsSync(p) && !fs.existsSync(getConfigJsonPath())) {
if (ideType === "jetbrains") {
// https://github.com/continuedev/continue/pull/7224
// This was here because we had different context provider support between jetbrains and vs code
// Leaving so we could differentiate later but for now configs are the same between IDEs
fs.writeFileSync(p, YAML.stringify(defaultConfig));
} else {
fs.writeFileSync(p, YAML.stringify(defaultConfig));
}
const exists = fs.existsSync(p);
const isEmpty = exists && fs.readFileSync(p, "utf8").trim() === "";
const needsCreation = !exists && !fs.existsSync(getConfigJsonPath());
if (needsCreation || isEmpty) {
fs.writeFileSync(p, YAML.stringify(defaultConfig));
setConfigFilePermissions(p);
}
return p;