Skip to content

fix: keep each folder on its own settings - #902

Open
psteinroe wants to merge 4 commits into
fix/nested-config-discoveryfrom
fix/nested-config-isolation
Open

psteinroe wants to merge 4 commits into
fix/nested-config-discoveryfrom
fix/nested-config-isolation

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #895 (which is stacked on #881). Must merge after #881.

Three ways a file could end up with another folder's settings, and with them another folder's database.

Environment variables collapsed nested databases (C4). DATABASE_URL and PG* were laid over every nested configuration. With PGDATABASE=postgres (or a DATABASE_URL from Rails/Prisma/sqlx) in the shell, db1/ and db2/ both connected to that database, which defeats the main use case of #881:

// db1/postgres-language-server.jsonc
{ "db": { "host": "127.0.0.1", "database": "db1" } }
// before, with PGDATABASE=postgres: connects to 127.0.0.1/postgres
// after: connects to 127.0.0.1/db1

Precedence now (documented in docs/configuration.md):

  • The root configuration: unchanged, the environment overrides the file.
  • A nested configuration file: an environment variable only fills in an option (host, port, username, password, database) the file doesn't set itself. Options it only gets through extends are overridden like in the root, so extends: ["../../root"] + "database": "db1" connects to $PGHOST/db1 in CI. DATABASE_URL is only used when the file sets no connection option, because a connection string wins over the other options.
  • CLI arguments (--connection-string, …) and the editor's client overrides still apply to every file: they are explicit for this run.

I picked this over "environment for the root only" because a nested file without a db section (only linter settings, say) should still connect like the root in CI.

A broken workspace-folder config used another folder's settings (C6). In the LSP, a workspace folder whose configuration failed to load at startup was unregistered, and project_key fell back to the shallowest other folder. Now the folder keeps its project (its previous settings, or the defaults if it's new) and the error is logged. Files outside every workspace folder get a folder-less project with the defaults instead of some folder's. Without workspace folders or root, or with an explicit configurationPath, the only project still applies to every file.

A broken nested config aborted the CLI (C9). check failed with configuration × key must be a string at line 1 column 3 without naming the file, and checked nothing. Now each broken nested file is reported with its path, its folder uses the defaults (like the LSP), and the run continues; the run still fails because of the reported error:

/repo/tests/fixtures/broken/postgres-language-server.jsonc configuration ━━━━━━━
  × key must be a string at line 1 column 3
/repo/a.sql:1:1 lint/banDropColumn ━━━━━━━
  ...

With --stdin-file-path, the errors go to stderr.

Tests

  • pgls_configuration: the_environment_only_fills_in_what_a_nested_configuration_does_not_set.
  • CLI: the_environment_does_not_replace_the_database_of_a_nested_configuration (no env, PGDATABASE, DATABASE_URL; Linux, uses the test DB server), check_reports_a_broken_nested_configuration_and_continues.
  • LSP: files_never_get_the_settings_of_another_workspace_folder: a folder with a broken config and a file outside every folder get the defaults, not the other folder's banDropColumn: error.

Not covered

  • While a workspace folder's root configuration is broken, its nested configuration files aren't loaded either. They come back once it's fixed.
  • The GitHub reporter still drops diagnostics without a line, like the database connection error, so the broken-config error only shows in the other reporters.

The database environment variables only fill in the connection options
a nested configuration file doesn't set itself. A workspace folder whose
configuration fails to load keeps its own project instead of borrowing
another folder's, files outside every folder use a folder-less project
with the defaults, and the CLI reports a broken nested configuration
with its path and keeps checking with the defaults for that folder.
…lation

# Conflicts:
#	crates/pgls_lsp/src/session.rs

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