-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide option to opt out of line ending normalisation for files #127
Comments
The current file model normalizes the line endings as soon as the file is read (i.e. each line does not keep track of its EOL), the model only keeps track of one EOL for the entire file (which is computed on file open as the predominantely used EOL character). @miqid Before we invest a lot into supporting this, when is it desirable to have a file with code that uses mixed EOL sequences? (i.e. why would you want to have a mixed EOL file at all) |
Thanks for the insight @alexandrudima - a bit gutted to hear it won't be a trivial change. Personally, I don't believe having mixed line endings around is a sane thing at all. Where the normalisation becomes a problem for me is when I need to make small edits in source files part of huge code repositories owned by people (usually in the commercial industry) who are extremely stringent on changes they allow through. I've instead been using the Atom editor to commit changes to files where line endings aren't normalised as it preserves the original line endings of a while on save. If it is going to be too much effort, I'm happy for the feature request to be closed off as there are alternatives beyond VS Code. |
+1 to that! |
This would be important when editing files with a binary payload. Think shellscripts with a built-in binary blob, or data files with a plaintext header part. |
Clearly, having mixed line endings in source code files is not sane at all. But this is something you often have to deal with in cross-platform development environments (Windows developers not aware at all of the EOL they are inserting in source code files, since the very beginning of the project). Thanks |
In my case, I would like to edit a |
EOL normalization should be optional feature and off by default. Thanks |
@gwax |
@shreyasminocha Yes, That person comes along, adds an entry to the The crux of the issue is that the editor is making changes to the rest of the file without warning or explicit configuration request. Compare to the behavior of the (similar) "Trim Trailing Whitespace". The feature also potentially edits untouched lines of a file but must be enabled by configuration before it will modify anything. |
Is there a way to turn off this line ending normalization? |
I've come across another scenario where the automatic normalisation of line endings is not desirable: an SQL export, which contains LF as the main line ending at the end of each row, but in my case also CRLF line endings within fields that contain multi-line text. |
I have the exact issue when making a pull request. I get surprised that the whole file is changed when I just changed one line! I work on both Mac and Windows, and I believe switching between them is what makes this problem. |
Please fix this issue since this is not just to be more comfortable, this is a mandatory feature of any modern editor: how do you work with XML having CDATA entries with different lineendings than the surrounding XML document?? I just can't edit such a file in VSCode, since it will thrash the CDATA parts, or the XML part..... Please, there should be a mode like in Notepad++:
|
Completely agree with the above. This should be a core feature. I shouldn't have to install an extension to see the line endings either. I expected the show control characters feature to show line endings but it did not and I had to hunt for an extension. |
I also would like to agree with the above statements. We for one develop on windows but then use linux docker containers. If we have to write shell scripts for docker using vscode, it usually causes issues. This is especially true if a developer tries to just modify one line, they have to be aware and make sure they set the line ending back to LF. |
Can't believe this still isn't fixed! I decided to move on to Spacemacs and haven't looked back.. |
@gwax @finn-matti I'm using EditorConfig already. The It'd be nice to selectively (per-file or file-pattern, or directory), be able to simply disable all end-of-line mangling, and trust that the developer knows what they are doing and have a valid reason, in both VSCode and extensions like EditorConfig or Prettier. Unfortunately, the only option is to not edit those files with VSCode, either using Vim or NotePad++ or some other basic editor, or specify escape sequences in a programming language, treat those special files as templates, and 'build' the text file. Having a text editor that hinders editing a text file and forces you to write code to build it, is pretty absurd. Luckily for me, it's an edge case for now, encountered once or more per project, only if I use source control and allow Apple/macOS contributors but prevent Icon cruft in repo. ( |
+1 |
I sometimes run into this issue at my day job. We have at least one MS Windows project in which developers contribute via heterogeneous tools. They don't always set up these tools and/or the Git client to consistently handle line endings. For whatever reason, line endings, spaces and tabs often wind up getting "jacked up" or even mixed in the same file thereby creating merge conflicts and visual noise. Sometimes I wind up using Notepad++ just to correctly see the line endings and whitespace; unfortunately, Notepad++ is an MS Windows only program even if there is apparently a Snap package out that makes it easy to run Notepad++ via Wine. I think EMACS and vi make it possible to see the line endings and whitespace also to some extent; however, I would rather Visual Studio Code behave more like Notepad++ and do the following:
Attached is a picture of what I'm talking about... BTW: I think Visual Studio (proper) - Not Visual Studio Code actually had a history in the past of jacking up line endings. Between that and the MS Windows client of Git, it seems we have managed to get some seriously jacked up line endings in one of our repos. That causes massive headaches when trying to merge changes among various branches. DISCLAIMER: My comments in this "bug entry" do not represent any current or former supervisors I have. Terms like "jacked up" are not officially endorsed language of my current employer; however, in this particular case, I'm calling it like it is... Furthermore, I reserve the right to solicit job opportunities with employers that feel "jacked up" is an acceptable technical phrase. |
Unless I'm missing something, shouldn't this be as easy as checking if mixed line endings are detected in the file, prompt the user to either ignore or fix them? The only real case that I can think of is is when this is exactly the intention (fix those wrong line endings and enforce my own) so the prompt would work for people who want to opt out of this behavior and for those who intend to fix the incorrect line endings. |
@gpnerds this issue also tracks this for Monaco (microsoft/monaco-editor#1813, microsoft/monaco-editor#1225, microsoft/monaco-editor#1427). So what you're suggesting does not apply. When working with Monaco I want full control over line endings. Each time a new line is added, e.g. by pressing |
FWIW, I just ran into this editing a pull request in a file that has intentionally mixed line endings in both github.dev and Codespaces--it's unfortunate that there's no way to disable this behavior, and unexpectedly, the builtin diff editor does not tell me about the line ending changes, so I only realized that I'd messed with the line endings when viewing the PR diff on github.com. If not for this behavior I'd have been able to complete this otherwise very straightforward PR entirely from the github.dev web editor, but as it stands I had to switch to a different editor to undo the line ending changes I'd made (making this the first time in 4 years that I've used an editor other than VS Code). |
LF is the defacto standard since it's used by Mac and Linux and Windows are mostly fine with it (batch files may be the only exception). Until this commit most of the files in this repo used a LF line endings anyway, the only exception were *.ino files which mostly used CRLF with couple of lines with LF. These mixed line endings cause troubles to those using VSCode since it doesn't support it (microsoft/vscode#127) so it's impossible to save a changed file without normalizing its line endings. This commit also introduces .gitattribute and .editorconfig files which will ensure correct formating in the future (strangely Arduino IDE doesn't support the latter one arduino/Arduino#8804).
This is super annoying. To keep git history clean and free from cross-branch conflicts, I want to leave the line endings out of a commit. Just change the lines I want to change and that's it. If the current file model normalizes the line endings as soon as the file is read, then clearly this is a wrong model for this use case as VS Code is a development tool. |
I have a project where I need to test the behavior of different escape characters and since I was using a static file to organize my tests (with different \r\n characters) I need to edit it with Notepad++ to avoid breaking my tests. |
Here's a use case for mixed line endings: We verify our HTTP responses by diffing against "golden" files.
Please could VS Code be able to edit our "golden" HTTP response files. 🙏 |
When is this closing? It's been opened since Nov 18, 2015 |
I need this feature too, and I agree with this reply from mathias-a-la-basse commented on Jun 25, 2019.
|
@alexdima > when is it desirable to have a file with code that uses mixed EOL sequences? (i.e. why would you want to have a mixed EOL file at all) There is a well-known issue with
Forking the project is not always an easy option in a corporate environment (licensing etc.), and forking only to normalize the line endings is less likely to be seen as a worthy reason to bother the legal department. |
I've been working with .sql files that contain encrypted data and unknowingly causing issues due to this "feature". At the very least, a notification that line endings were normalized upon opening the file would seem warranted. It's been 9 years since this issue was opened. As a dev who has been using VS Code for years, it took this biting me to look it up. No third party extensions appear to support this either. Overall I love this editor, and would like to use it for nearly everything, but now I'm forced to install something like Notepad++ just to work around this one issue. |
I'm working on project containing files with XML having CDATA entries with different lineendings and i have to use Notepad++ for editing and merging changes. |
It seems to me that this issue is even worse then what described so far, because it looks like there is an bad coupling of VSC's inability to properly use CR as EOL and its search. |
Upon saving a file edited with VS Code, it appears to perform line ending normalisation automatically and without user notification of any sort. Because of this, I've found myself bitten by large diffs in Git (I'm aware you can circumvent this using the
-w
flag) where a trivial fix to a single line of source code appears to affect a significant proportion of the file, which makes pull requests and reviews for such changes on GitHub a pain to sift through. Then again, I guess one could argue why a source file with mixed line endings should stay in version control like that anyway!Visual Studio Community displays a prompt upon opening a file if it has mixed line endings and lets a user decide whether or not to have it fixed.
Version: 0.10.1
(By the way, great work on open sourcing VS Code too, thanks!)
The text was updated successfully, but these errors were encountered: