How to change the diff tool used by VSCode for git? - visual-studio-code

I would like to use the difftastic diff tool, which ignores whitespace changes in code (amongst other useful functionalities), and I have set my .gitconfig to use difft (the binary file of difftastic) as my preferred external diff tool using this command:
git config --global diff.external difft
And, my .gitconfig has these lines in it:
[diff]
external = difft
However, the VSCode text editor still shows whitespace diffs. I have searched for a way to change the diff tool in VSCode to no avail, the only results are "How to set VSCode as the default merge/diff tool for git".
To clarify, I would like to change the diff tool used by the vscode text editor section as well as the diff viewer. I do not want to change the tool used by the commandline git command itself. In the image I've linked, it shows changes for whitespace, which should not be happening if difft is set as the diff tool.

You can change the tool Git uses to "diff" two files: https://git-scm.com/docs/git-difftool (this is Git functionality - it has nothing directly to do with VSCode).
You can substitute a custom editor for the built-in the Visual Studio code editor: https://code.visualstudio.com/api/extension-guides/custom-editors.
You can add a custom "diff" plugin to Visual Studio, for example, "Partial Diff": https://marketplace.visualstudio.com/items?itemName=ryu1kn.partial-diff.
What you CANNOT do is swap in a custom app to change the "diff" functionality of the default VSCode editor.

Visual Studio Code does not use an external utility to compute the diff. The necessary algorithms are directly implemented in VS Code and you don't have any control over them.
Using an arbitrary external utility would most likely not result in a good user experience either. If VS Code cannot understand the generated diff, it would not be able to display the output with the diff editor and you would lose features like syntax highlighting.
However, I may have an alternative solution to your original problem (using difftastic in VS Code). I am currently working on my own extension that adds a semantic diff mode to VS Code. It supports fewer languages than difftastic, but has additional features like moved code detection:
If that is what you are looking for, you can find the extension (SemanticDiff) in the Visual Studio Code Marketplace.

Related

Git Extensions GUI: set source code language for "colorization"?

I'm working with a repository of MATLAB code in git (company internal repo) using the "GitExtensions" app. The displayed code in the "FileTree" window is colorized more or less as though it were c-language code. Is there any way to specify other languages, similar to how Notepad++ does?

VCS for Jupyter Notebooks in PyCharm

I'm wondering how to make PyCharm's VCS (i.e. Git) work with Jupyter Notebook files.
Changing even 1 loc results in 3 modifications detected during commit:
Sorry if it's a duplicate, but I haven't found anything similar.
Well, I wouldn't say that the current support of Jupyter Notebook files versioning doesn't work at all. You can see it on your own screenshot that your changes are detected.
We don't parse all of the changes to detect only the source code changes.
And even if we did, many people actually want to track the output because, for example, in data science, the results are not always reproducible and you may want to keep track of the output as well as src.
Although it can be enhanced with the implementation of the following functionality https://youtrack.jetbrains.com/issue/PY-20132 that would allow committing all of the changes, but see only changes of source code, so feel free to upvote and leave comments.
I use Pycharm Community edition. I love the way Pycharm integrates with git and its VCS shows the diffs visually. However, for jupyter notebook files, the diff is difficult to track visually. Running a cell introduces various changes.
Notebook files normally diff like text files. I use a simple method to enhance the visual quality. I created a new file type Settings>Editor>File Types for *.ipynb files. I enable matching for all types of brackets. I add few keywords,
Keyword 1:
"outputs"
"source"
Keyword 2:
"code"
"markdown"
This highlighted format shows up in the Pycharm VCS and enables us to easily locate changes in code and markdown cells and outputs. An example of this effect is shown in this screenshot. Now, we don't need to worry about changes in the execution count or meta data.

Is there any plugin like gitlens for perforce?

GITLENS is pretty cool plugin I found for Visual Studio Code which give all the information about who and when the changes were made in the file. Is there any similar plugin to GITLENS for Perforce ?
The plugin could be for any other IDE as well.
The extension Perforce for VS Code has annotations that can show which changes were made and which user made them.
You can enable annotations for every file by setting the configuration perforce.annotate.enable to true.
perforce.annotate.changelist and perforce.annotate.user can be set to true to output changelist numbers for each line and the user who modified the line respectively.
If you are using a new extension Perforce for VS Code, You can use the command perforce.annotate
By default, it comes with a keybinding alt+p n (it works only when editor text is in focus). You can also search for Perforce: Annotate in Command Palette.

How to merge files(differentiate) in visual studio code

I am using Visual studio code for angular2 application. The requirement is to merge files, so, I want to differentiate changes in two files as it happens in Netbeans IDE. Is there, any extensions available to achieve the task in visual studio code.
For e.g - Merging Two files by differentiating changes like below:-
Please suggest some solution.
abc.component.ts (located in project1)
abc <-- text for understanding purpose
def
abc.component.ts ( located in project2)
abc
I want to differentiate two component files and push changes in another like it happens in Netbeans IDE? Is there, any solution available for Visual studio code?
First using vscode natively with the git toolset
(Make sure to look on the second title as it's a better native way!)
This way may be available on older version of vscode too! Still a good thing to know! (even we should always run on the latest version! And vscode is always keeping getting better and better).
A native powerful and cool way is to use the git toolset within vscode! It still not the most fluid way! But if you are in a setup where you don't have anything else or time or resources to use anything else! Also as a requirement you need to have a git repo initiated! Here we go:
First we will use the change and diffing capability of the git tool set. And the steps go as bellow:
Commit all the current changes
once done: copy past the other file to diff on the place of the current one. And save.
Cool now in the git pallet you can see the file in changes list! Click on it and the diffing editor will show!
Bingo this is it! You can compare and make direct changment! The diffing will keep happening in real time. Note the current state is in the right. And you make changement there.
Here an illustration of direct modification for instance the part in the left is missing from the current file
And here another illustration (current have in plus)
Well to sum up! Git tool and diffing in vscode is so powerful! And all that one need! The only problem is the extra step of committing and cleaning after if desired!
Here some tips! If you want to have the commit history cleaner! Or not have a merge separate! You can remove the last commits from history as much as you need: Without hard reset and commit again a cleaner one!
git reset --soft HEAD~1
You can check
How to cancel a local git commit
Otherwise it can be ok with atomic commit and merge mention!
Also if what you need is to be able to keep a lot from the current file! You can copy the current elsewhere! past the other file to compare! commit ! and then past again the old one! You'll have the old in the right and as current (Not as described on the above) In such a scenario this work well! (Hacky a bit but you may need it).
Native way (direct open of the compare editor)
(May require the newer version of vscode)
open a file that you gonna compare
open the command pallet
CTRL + SHIFT + P
type file: compare
You can see the different possible ways! For a file we can choose compare active file with.
Then you choose the file! The file need to be within the project directory.
And then you choose a file and the compare editor will open
The above was tested on my brother computer on a new vscode installation. I wasn't sure at first if it was part of the core! And i just confirmed that it is. That too remove the need to the method above involving git! And it's the best native way to go with.
Vscode extensions
Here two extensions i suggest the first:
https://marketplace.visualstudio.com/items?itemName=jinsihou.diff-tool
Easy and simple! It add two elements to the right click menu:
In current file right click -> Select as first file for diff, select one again to view the diff results
select to compare and compare with select no more simple then that !
Another extension to check:
https://marketplace.visualstudio.com/items?itemName=fabiospampinato.vscode-diff
I prefer the first! As this one compare a lot to the native way. And having the control in the contextual menu is just great.
Out of vscode! Using other tools
A quick google search and you'll find a lot of tools!
https://meldmerge.org/
meld merge is cross platform and open source and nice!
in linux and debian:
sudo apt install meld
Otherwise you can check the long list here:
https://www.jotform.com/blog/25-useful-document-and-file-comparison-tools/
https://stackify.com/code-merge-tools/
There is too winMerge to mention (an open source project for windows)
https://winmerge.org/

How do I auto-indent Python code in Visual Studio Code?

I'm using Visual Studio Code (not Visual Studio) on Linux and I can't seem to find out how to turn on auto-indentation for Python. I've looked all over preferences, spent some time on Google, and can't find anything.
Does anyone know how to do this?
In VS Code you can set the indentation in several places :
General/Workspace settings (bottom bar),
User settings,
language formatter settings.
When using Python, no matter what settings you set, all of them are overridden by the autopep8Args value of the autopep8 language formatter setting, which has an indent size of 4.
By default, autopep8 is used as VS Code Python formatter, but there are others, like yapf.
To update the indent size of this formatter, search in your user settings the "python.formatting.autopep8Args" and set it to : ["--indent-size=2"],
"python.formatting.autopep8Args": ["--indent-size=2"],
Visual Studio Code doesn't have much support for Python (yet), aside from syntax-highlighting, and per-file intellisense (meaning it'll provide suggestions for symbols that have been found within the current file).
I'm willing to bet that the Visual Studio Code team will, eventually, increase their support for Python within Visual Studio Code, and with this, they'll likely add support for auto-indentation.
In the meantime, it might be worth trying this Visual Studio Code extension, which aims to add better support for Python, into Visual Studio Code.
The extension does add auto-indentation for Python, to Visual Studio Code, along with many other features.
Happy scripting!
I auto-format python with autopep8, vscode can use it. It can be easily configured for tab-size and other stuff creating the config file: $HOME/.config/pep8
Here an example of that file:
[pep8]
indent-size = 2
max-line-length = 100