Repository navigation
fix: provide plugins the file path with the shebang's extension for files matched by a shebang - #1349
Merged
Merged
Conversation
…iles matched by a shebang
…tal cache, decide the path once per file
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.
The CLI sends an extensionless file to a plugin based on the
"shebangs"config, but the plugin received the file's real path. Plugins decide how to format a file based on its extension, so a plugin could end up doing nothing with a file it was sent. For example, the exec plugin matches its commands'extsagainst the path, so no command ran (dprint/dprint-plugin-exec#69).Now a file that's formatted because of its shebang is given to the plugins with a marker and the mapped extension added to its path (ex.
build.dprint-ext-added.shfor a file namedbuildwith"#!/bin/sh": "sh"). This works for every plugin without needing changes to them. The marker is there so a plugin can tell the path isn't the real one and get the real one by taking what's before.dprint-ext-added.Only the path given to the plugins changes. Everything the CLI does with the path still uses the real one: includes and excludes, plugin
"associations", plugin"overrides", the incremental cache and the output. A file that a plugin claims by its path (ex."associations") keeps its real path.Some details:
"shebangs"by adding a version number to its hash, since a file a plugin previously did nothing with was recorded as formatted.dprint fmt/check, the path is decided once per file from its original text, the same as the plugins formatting it, so it stays the same when ensuring a stable format."associations"and"overrides"against the real path, and the plugins' extensions against the added one.The path a plugin sees for these files doesn't exist on disk. It matters for something like an exec plugin command that reads the file at
{{file_path}}instead of from stdin, which previously didn't run for these files. dprint/dprint-plugin-exec#70 makes the exec plugin use the real path for that.This applies the same way to
dprint fmt/check,--stdin, the editor service and the LSP. The tests coverdprint fmtand--stdinby having the test process plugin output the path it received, plus unit tests for building and reversing the path; the editor service and the LSP go through the same code as--stdinand don't have their own test.