Repository navigation
feat(configuration): expand ~ in extends and fall back to a user configuration - #878
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #640. Related to #13.
What changed
~inextends. Entries that start with~/, or are exactly~, now resolve against the home directory.~\is also accepted on Windows. Before this change,.jsoncentries were always joined onto the config's directory, so~/...became<project>/~/...and failed to load:A path with
~is always treated as a file path, whatever its extension, so~/shared.jsondoesn't go through the package resolver. If the home directory is unknown, the entry falls back to the old behaviour and fails with the usual "can't load" error.User configuration fallback. If the search finds no project config, the user config is loaded. The search walks up from the CLI working directory or the editor's workspace folder. It looks for
postgres-language-server.jsoncin the first of these directories that has one:$XDG_CONFIG_HOME/postgres-language-server/, else~/.config/postgres-language-server/$XDG_CONFIG_HOMEor~/.config(as on Linux), then~/Library/Application Support/postgres-language-server/%APPDATA%\postgres-language-server\The semantics are kept simple on purpose:
extends, which now works thanks to~.--config-path,PGLS_CONFIG_PATHor editorconfigurationPathnever falls back. A missing file there is still an error.LoadedConfiguration::directory_pathis the project directory, so the LSP resolvesvcs.rootand.gitignoreagainst the project, not~/.config/.... Globs already resolve against the working directory. Relativeextendsinside the user config still resolve against the user config's own directory.postgrestools.jsoncis not.Why macOS also checks
~/.config. Thedirectoriescrate only knows~/Library/Application Support, but most CLI tools on macOS read~/.config/<tool>(gh, helix, bat, starship, …), and that's where users look first. Checking both keeps the native location working and puts~/.configfirst. No new environment variable is added:XDG_CONFIG_HOMEcovers relocating it on Unix.Implementation.
FileSystemgetshome_directory()anduser_config_directories().OsFileSystemreads them from the OS (pgls_fs::dir).MemoryFileSystemreturns nothing unless the test sets them, so tests never touch the real home directory. Unit tests inpgls_workspace::configurationcover:~expansion (including non-.jsoncentries)extendsinside the user configpgls_fs::dirtests cover the XDG resolution.docs/configuration.mddocuments both features and the precedence.Risks
postgres-language-server.jsoncin their config directory will now have it applied to projects without a config. That's the intended effect, but it is a behaviour change.