Comments (10)
Hi! This is really important for projects that are using .editorconfig
, otherwise if you've Format on save
enabled, you have to disable this plugin entirely because they might conflict with each other, or manually configure shfmt flags from settings.
from vs-shell-format.
Sorry for not reading! Would a possible workaround be to create a temporary file in the same directory as a buffer? Keep up the good work 👏🏼
from vs-shell-format.
The thing is we're already inconsistent with the command line. The changes in this PR bring the behaviour of the extension in-line with the results from running shfmt
from the command line by ensuring we respect the settings in any present .editorconfig
.
Regarding usage of stdin
, it is a firm requirement as far as I'm aware. The communication mechanism between VS Code and the extension is via the DocumentFormattingEditProvider interface. Usage of stdin
is absolutely the correct approach in my view, as it provides many benefits which are much harder or impossible to implement if operating directly on the underlying file (assuming there is one). Conversely, operating directly on a file means an external utility is making modifications to the user's files concurrent with the editor, sidestepping potentially all manner of user and editor expectations.
from vs-shell-format.
Note that you can use shfmt --filename=path/to/original/file.sh
and pass the script contents over stdin. EditorConfig will apply as if you were formatting the file in its original location, and you won't need to re-implement shfmt's own EditorConfig loading logic.
from vs-shell-format.
I think it's a bug not a feature request. The behavior is different from calling shfmt
directly. Could it be because the working directory isn't being passed? Here's an example from the ShellCheck extension:
from vs-shell-format.
I've submitted a PR which adds this functionality. See PR #102 for more details.
from vs-shell-format.
@ralish I think there was a misunderstanding. You should let shfmt use editorconfig. Instead you're duplicating the functionality just like your format on save feature. The only thing missing was passing the working directory when spawning the command.
from vs-shell-format.
@texastoland Spawning shfmt
with the current working directory set to that of the file being saved was the approach I originally took, but it's unfortunately not sufficient. As noted in the updated PR, the content of the file being saved is passed to shfmt
over stdin
(i.e. shfmt
only sees the file content, it is not aware of the path of the file nor its name).
Spawning shfmt
with the current working directory of the file will thus only apply EditorConfig settings which are applied globally. Options which are specific to certain paths are not applied as shfmt
doesn't know the file path required to determine if the options apply. The approach I've taken is admittedly not ideal, but it's working around inherent limitations.
There's work being done in shfmt
itself to make dealing with this issue easier as well by providing the file path as a parameter when formatting shell scripts over stdin
. When that support lands, the approach I've taken can likely be simplified, provided a shfmt
version is being used which has the required support.
from vs-shell-format.
@texastoland I don't think I understand the approach you're suggesting?
from vs-shell-format.
I mean is reading from stdin a firm requirement? Could you just update the file in-place with shfmt -w
? If you really need a file buffer, you could replace stdin with a generated unique filename in the same directory, copy its formatted contents, then delete the copy. I'm worried trying to duplicate the behavior of shfmt will resolve the immediate problem but yield inconspicuous inconsistencies with the command line.
from vs-shell-format.
Related Issues (20)
- quoting issues using the formatter
- Possible Issue - shfmt on Windows does not Format CRLF Files HOT 1
- Scripts and startup files (no `.sh` suffix) are not supported. HOT 3
- Windows Batch HOT 1
- Bundle full changelog with your extension HOT 2
- Antivirus issue
- .env file lost syntax highlighting HOT 1
- all_proxy is a invalid var name
- parameter expansion requires a literal
- IntelliSense Optimization
- Bug: case HOT 1
- Command arguments are being indented at the same level as the parent HOT 1
- VSCodium Marketplace
- Trailing slashes removed in Dockerfile RUN command HOT 2
- pls update bundled `shfmt` from 3.6 to 3.8
- [BUG]: unclosed here-document error on windows but not darwin HOT 1
- The syntax checking for .gitignore is incorrectly reporting errors.
- Error "Effective shfmt flags: "
- Do not steal focus when installing shell format binary
- Formatter adds spaces to option blocks in gitignore
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vs-shell-format.