Skip to content

fix(configuration): resolve root paths against the config folder, apply extends transitively, replace on reload - #915

Open
psteinroe wants to merge 4 commits into
fix/watch-configuration-filesfrom
fix/configuration-resolution
Open

psteinroe wants to merge 4 commits into
fix/watch-configuration-filesfrom
fix/configuration-resolution

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #908 → #902 → #895 → #881. Must merge after #881.

Three ways the root configuration didn't behave like the docs or like a nested configuration.

Relative paths resolved against the process's working directory (C7). update_settings got workspace_directory: fs.working_directory() from both the LSP and the CLI, and LoadedConfiguration::directory_path was dropped. With the server started outside the workspace (Neovim from another cwd, the daemon, any workspace folder but the first) or check run from a subfolder, the root migrations.migrationsDir, files.ignore/include and linter globs pointed at the wrong folder, while nested configurations already used their own folder:

// /repo/postgres-language-server.jsonc, server started in /home/alice
{ "migrations": { "migrationsDir": "migrations", "after": 5 } }
// before: /repo/migrations/0009_later.sql is not a migration (looked in /home/alice/migrations)
// after:  it is, and migrations up to 0005 are ignored

Now both pass the folder of the configuration file (the project folder for the user configuration or no configuration). The CLI also uses that folder as the VCS base, like the LSP already did.

extends was one level deep (C10). The pattern #881 documents, a nested file with "extends": ["../../postgres-language-server.jsonc"], lost whatever the root itself extended (a shared file, the user configuration). Extended files' own extends are now applied first, resolved relative to the extended file. A cycle fails with The configuration files extend each other: a -> b -> a, and more than 10 levels fail too.

Reloading merged into the old root settings (C11, self-noted in #881). Removing "linter": { "rules": { "banDropColumn": "error" } } from the file kept the error until a restart. UpdateSettingsParams gets replace (#[serde(default)], so false for existing JSON clients). The LSP and the CLI replace: the settings are rebuilt from the defaults, and only swapped in if the configuration applies, so a broken file keeps the previous settings. The wasm format call keeps merging, since it only sends the formatter section.

Changelog (behaviour changes)

  • Relative paths and globs in the root configuration are resolved against the folder of the configuration file, not the working directory. This affects check/format run from a subfolder of the configuration and editors whose server runs elsewhere. The CLI also looks for .gitignore from the configuration folder.
  • extends applies the extends of extended files; cycles and chains deeper than 10 are errors.
  • A section removed from the configuration file goes back to its default on reload.
  • UpdateSettingsParams.replace is new in the workspace protocol (optional, defaults to merging).

Tests

  • configuration::tests: extends_is_applied_transitively (three levels, own db.database wins, inherited db.host kept, extended files listed), extends_fails_on_a_cycle, extends_fails_when_too_deep.
  • pgls_workspace: updating_the_settings_replaces_or_merges_them.
  • LSP: relative_paths_of_the_root_configuration_are_relative_to_its_folder (server cwd outside the workspace, root and nested migrationsDir), a_section_removed_from_the_configuration_goes_back_to_its_defaults.
  • CLI: relative_paths_are_relative_to_the_configuration_file (check ../migrations/0009_later.sql from sub/).
  • just gen-lint regenerated both backend-jsonrpc workspace.ts files.

Not covered

…ly extends transitively, replace on reload

Relative paths and globs of the root configuration are resolved against
the folder of the configuration file instead of the working directory of
the process. An extended file's own extends are applied too, with cycle
detection and a depth limit. The LSP and the CLI replace the root
settings on reload, so removed sections go back to their defaults; the
wasm format call keeps merging.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant