Add support to develop Git in Visual Studio Code
cover Add support to develop Git in Visual Studio Code
[Visual Studio Code](https://code.visualstudio.com/) (nickname "VS Code") is a light-weight, cross-platform, Open Source development environment, with an increasingly powerful extension to support C/C++ development. In particular the intellisense support as well as all the other niceties developers might have come to expect from Integrated Development Environments will help accelerate development.
This topic branch makes it easy to get started using VS Code to develop Git itself.
To get started, run the script ./contrib/vscode/init.sh. This will initialize the .vscode/ directory and some files in that directory. After that, simply open Git's top-level directory as "folder" in VS Code.
The files have to be generated because of the curious way Git determines what flags to pass to the C compiler, in particular which constants are defined, because they change the compile flow in rather dramatic ways (determining, e.g. which SHA-1 backend to use).
Johannes Schindelin (9):
contrib: add a script to initialize VS Code configuration
vscode: hard-code a couple defines
cache.h: extract enum declaration from inside a struct declaration
mingw: define WIN32 explicitly
vscode: only overwrite C/C++ settings
vscode: wrap commit messages at column 72 by default
vscode: use 8-space tabs, no trailing ws, etc for Git's source code
vscode: add a dictionary for cSpell
vscode: let cSpell work on commit messages, too
.gitignore | 1 + cache.h | 24 ++- config.mak.uname | 2 +- contrib/vscode/.gitattributes | 1 + contrib/vscode/README.md | 14 ++ contrib/vscode/init.sh | 375 ++++++++++++++++++++++++++++++++++ 6 files changed, 405 insertions(+), 12 deletions(-) create mode 100644 contrib/vscode/.gitattributes create mode 100644 contrib/vscode/README.md create mode 100755 contrib/vscode/init.sh
base-commit: 53f9a3e157dbbc901a02ac2c73346d375e24978c
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-2%2Fdscho%2Fvscode-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2/dscho/vscode-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/2
Signature · 1 line
gitgitgadget
PATCH 1/9 contrib: add a script to initialize VS Code configuration
From: Johannes Schindelin <[email protected]>
VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. Among other languages, it has support for C/C++ via an extension.
To start developing Git with VS Code, simply run the Unix shell script contrib/vscode/init.sh, which creates the configuration files in .vscode/ that VS Code consumes.
--- .gitignore | 1 + contrib/vscode/.gitattributes | 1 + contrib/vscode/README.md | 14 +++ contrib/vscode/init.sh | 165 ++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 contrib/vscode/.gitattributes create mode 100644 contrib/vscode/README.md create mode 100755 contrib/vscode/init.sh
.gitignore +1 -0
@@ -206,6 +206,7 @@ /config.mak.autogen /config.mak.append /configure +/.vscode/ /tags /TAGS /cscope*
contrib/vscode/.gitattributes new file +1 -0
@@ -0,0 +1 @@ +init.sh whitespace=-indent-with-non-tab
contrib/vscode/README.md new file +14 -0
@@ -0,0 +1,14 @@ +Configuration for VS Code +========================= + +[VS Code](https://code.visualstudio.com/) is a lightweight but powerful source +code editor which runs on your desktop and is available for +[Windows](https://code.visualstudio.com/docs/setup/windows), +[macOS](https://code.visualstudio.com/docs/setup/mac) and +[Linux](https://code.visualstudio.com/docs/setup/linux). Among other languages, +it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools). + +To start developing Git with VS Code, simply run the Unix shell script called +`init.sh` in this directory, which creates the configuration files in +`.vscode/` that VS Code consumes. `init.sh` needs access to `make` and `gcc`, +so run the script in a Git SDK shell if you are using Windows.
contrib/vscode/init.sh new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
gitgitgadget
Re: [PATCH 1/9] contrib: add a script to initialize VS Code configuration
Hi,
Thanks for working on this.
Quoted 5 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. Among other languages, it has support for C/C++ via an extension.
This doesn't really seem relevant to the change. The relevant bits are that (1) VS Code is a popular source code editor, and that (2) it's one worth recommending to newcomers.
Quoted 5 lines
To start developing Git with VS Code, simply run the Unix shell script
contrib/vscode/init.sh, which creates the configuration files in .vscode/ that VS Code consumes.Signed-off-by Johannes Schindelin <[email protected]>
This doesn't tell me what the patch will actually do.
VSCode is an editor. Is the idea that this will help configure the editor to do the right thing with whitespace or something? Or does it configure IDE features to build git?
Thanks,
Jonathan
Re: [PATCH 1/9] contrib: add a script to initialize VS Code configuration
Hi Jonathan,
Quoted 11 lines · Jonathan Nieder
Quoted 5 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. Among other languages, it has support for C/C++ via an extension.
This doesn't really seem relevant to the change. The relevant bits are that (1) VS Code is a popular source code editor, and that (2) it's one worth recommending to newcomers.
To the contrary. This paragraph describes the motivation of the patch.
It is, if you want, the most important part of the entire patch series.
Quoted 7 lines
Quoted 5 lines
To start developing Git with VS Code, simply run the Unix shell script
contrib/vscode/init.sh, which creates the configuration files in .vscode/ that VS Code consumes.Signed-off-by Johannes Schindelin <[email protected]>This doesn't tell me what the patch will actually do.
True. Will add a paragraph.
Quoted 3 lines
VSCode is an editor. Is the idea that this will help configure the editor to do the right thing with whitespace or something? Or does it configure IDE features to build git?
It is a start of all of the above. Ideally, I will be eventually be able to consistently use VS Code for Git development, whether I have to work on a Linux, a macOS or a Windows machine.
And I am not happy until the same ease is also available to others. Hence my contribution.
Ciao,
Dscho
Re: [PATCH 1/9] contrib: add a script to initialize VS Code configuration
In reply to Johannes Schindelin via GitGitGadget"Johannes Schindelin via GitGitGadget" <[email protected]>
contrib/vscode/init.sh line 1
Quoted 7 lines · writes:
contrib/vscode/init.sh new file +1
-0@@ -0,0 +1,165 @@ +#!/bin/sh
This is caued by our usual "git apply --whitespace=warn" as it contains lines indented by spaces not tabs (perhaps the json literals?) Can we have contrib/vscode/.gitattributes to tweak the whitespace breakage checking rules so that this file is excempt?
I'll just shut my eyes while applying this series for today, though ;-)
Re: [PATCH 1/9] contrib: add a script to initialize VS Code configuration
Quoted 12 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
contrib/vscode/init.sh line 1
Quoted 7 lines · writes:
contrib/vscode/init.sh new file +1
-0@@ -0,0 +1,165 @@ +#!/bin/shThis is caued by our usual "git apply --whitespace=warn" as it
"caught"; sorry for a typo.
Re: [PATCH 1/9] contrib: add a script to initialize VS Code configuration
In reply to Junio C HamanoHi Junio,
Quoted 14 lines · Junio C Hamano
"Johannes Schindelin via GitGitGadget" <[email protected]>
contrib/vscode/init.sh line 1
Quoted 7 lines · writes:
contrib/vscode/init.sh new file +1
-0@@ -0,0 +1,165 @@ +#!/bin/shThis is caued by our usual "git apply --whitespace=warn" as it contains lines indented by spaces not tabs (perhaps the json literals?)
A git diff --check does not show any red flag.
Quoted 2 lines
Can we have contrib/vscode/.gitattributes to tweak the whitespace breakage checking rules so that this file is excempt?
I would have appreciated quite a bit more clear a message, including how I can trigger this, and what is the appropriate setting.
As it is, I cannot reproduce your problem with a git show, so I assume that the main problem is that this commit *does* add that .gitattributes, but of course your git apply ran before that file existed.
For your own pleasure, here is the link to the .gitattributes file in the commit that you applied yourself:
I assume that this is good enough for you, and your comment is moot?
Ciao,
Dscho
PATCH 2/9 vscode: hard-code a couple defines
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
Sadly, we do not get all of the definitions via ALL_CFLAGS. Some defines are passed to GCC *only* when compiling specific files, such as git.o.
Let's just hard-code them into the script for the time being.
--- contrib/vscode/init.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
contrib/vscode/init.sh +13 -1
@@ -115,7 +115,19 @@ include Makefile vscode-init: @mkdir -p .vscode && \ incs= && defs= && \ - for e in $(ALL_CFLAGS); do \ + for e in $(ALL_CFLAGS) \ + '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ + '-DBINDIR="$(bindir_relative_SQ)"' \ + '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' \ + '-DDEFAULT_GIT_TEMPLATE_DIR="$(template_dir_SQ)"' \ + '-DETC_GITCONFIG="$(ETC_GITCONFIG_SQ)"' \ + '-DETC_GITATTRIBUTES="$(ETC_GITATTRIBUTES_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ + '-DCURL_DISABLE_TYPECHECK', \ + '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ + '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ + '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'; do \ case "$$e" in \ -I.) \ incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
Signature · 1 line
gitgitgadget
Re: [PATCH 2/9] vscode: hard-code a couple defines
Hi,
Quoted 6 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Sadly, we do not get all of the definitions via
ALL_CFLAGS. Some defines are passed to GCC *only* when compiling specific files, such as git.o.Let's just hard-code them into the script for the time being.
Could we move these to ALL_CFLAGS? Is there any downside other than increased rebuilds when options change?
Thanks,
Jonathan
Re: [PATCH 2/9] vscode: hard-code a couple defines
Hi Jonathan,
Quoted 11 lines · Jonathan Nieder
Quoted 6 lines · Johannes Schindelin via GitGitGadget
From: Johannes Schindelin <[email protected]>
Sadly, we do not get all of the definitions via
ALL_CFLAGS. Some defines are passed to GCC *only* when compiling specific files, such as git.o.Let's just hard-code them into the script for the time being.
Could we move these to
ALL_CFLAGS? Is there any downside other than increased rebuilds when options change?
I assumed that it gives us a bit more liberty at using names for constants that might otherwise be too general.
I did not even consider the rebuild time, but that's a good point.
The idea to move those definitions to ALL_CFLAGS sounds good to me, yet I am loathe to introduce this into a patch series that is not about far-reaching design decisions at all, but merely about making a decent tool available to the finger tips of all Git contributors.
Read: I think this would make for a pretty good micro-project, maybe in next year's GSoC (assuming that it happens and that we're accepted again).
Ciao,
Dscho
PATCH 3/9 cache.h: extract enum declaration from inside a struct declaration
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
While it is technically possible, it is confusing. Not only the user, but also VS Code's intellisense.
--- cache.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
cache.h +13 -11
@@ -1425,18 +1425,20 @@ extern void *read_object_with_reference(const struct object_id *oid,extern struct object *peel_to_type (const char *name,int namelen,struct object *o,enum object_type ); +enum date_mode_type { +DATE_NORMAL =0 , +DATE_RELATIVE , +DATE_SHORT , +DATE_ISO8601 , +DATE_ISO8601_STRICT , +DATE_RFC2822 , +DATE_STRFTIME , +DATE_RAW , +DATE_UNIX +}; +struct date_mode { -enum date_mode_type { -DATE_NORMAL =0 , -DATE_RELATIVE , -DATE_SHORT , -DATE_ISO8601 , -DATE_ISO8601_STRICT , -DATE_RFC2822 , -DATE_STRFTIME , -DATE_RAW , -DATE_UNIX - } type; +enum date_mode_type type;const char *strftime_fmt;int local; };
Signature · 1 line
gitgitgadget
PATCH 4/9 mingw: define WIN32 explicitly
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
This helps VS Code's intellisense to figure out that we want to include windows.h, and that we want to define the minimum target Windows version as Windows Vista/2008R2.
--- config.mak.uname | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
config.mak.uname +1 -1
@@ -528,7 +528,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) COMPAT_OBJS += compat/mingw.o compat/winansi.o \ compat/win32/pthread.o compat/win32/syslog.o \ compat/win32/dirent.o - BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1 + BASIC_CFLAGS += -DWIN32 -DPROTECT_NTFS_DEFAULT=1 EXTLIBS += -lws2_32 GITLIBS += git.res PTHREAD_LIBS =
Signature · 1 line
gitgitgadget
PATCH 5/9 vscode: only overwrite C/C++ settings
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
The C/C++ settings are special, as they are the only generated VS Code configurations that *will* change over the course of Git's development, e.g. when a new constant is defined.
Therefore, let's only update the C/C++ settings, also to prevent user modifications from being overwritten.
Ideally, we would keep user modifications in the C/C++ settings, but that would require parsing JSON, a task for which a Unix shell script is distinctly unsuited. So we write out .new files instead, and warn the user if they may want to reconcile their changes.
--- contrib/vscode/init.sh | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
contrib/vscode/init.sh +20 -3
@@ -13,7 +13,7 @@ die "Could not create .vscode/" # General settings -cat >.vscode/settings.json <<\EOF || +cat >.vscode/settings.json.new <<\EOF || { "C_Cpp.intelliSenseEngine": "Default", "C_Cpp.intelliSenseEngineFallback": "Disabled",
@@ -51,7 +51,7 @@ esac # Default build task -cat >.vscode/tasks.json <<EOF || +cat >.vscode/tasks.json.new <<EOF || { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format
@@ -73,7 +73,7 @@ die "Could not install default build task" # Debugger settings -cat >.vscode/launch.json <<EOF || +cat >.vscode/launch.json.new <<EOF || { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes.
@@ -175,3 +175,20 @@ vscode-init: echo '}' EOF die "Could not write settings for the C/C++ extension" + +for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json +do + if test -f $file + then + if git diff --no-index --quiet --exit-code $file $file.new + then + rm $file.new + else + printf "The file $file.new has these changes:\n\n" + git --no-pager diff --no-index $file $file.new + printf "\n\nMaybe \`mv $file.new $file\`?\n\n" + fi + else + mv $file.new $file + fi +done
Signature · 1 line
gitgitgadget
PATCH 6/9 vscode: wrap commit messages at column 72 by default
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
When configuring VS Code as core.editor (via code --wait), we really want to adhere to the Git conventions of wrapping commit messages.
--- contrib/vscode/init.sh | 4 ++++ 1 file changed, 4 insertions(+)
contrib/vscode/init.sh +4 -0
@@ -17,6 +17,10 @@ cat >.vscode/settings.json.new <<\EOF || { "C_Cpp.intelliSenseEngine": "Default", "C_Cpp.intelliSenseEngineFallback": "Disabled", + "[git-commit]": { + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 72 + }, "files.associations": { "*.h": "c", "*.c": "c"
Signature · 1 line
gitgitgadget
PATCH 7/9 vscode: use 8-space tabs, no trailing ws, etc for Git's source code
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
This adds a couple settings for the .c/.h files so that it is easier to conform to Git's conventions while editing the source code.
--- contrib/vscode/init.sh | 8 ++++++++ 1 file changed, 8 insertions(+)
contrib/vscode/init.sh +8 -0
@@ -21,6 +21,14 @@ cat >.vscode/settings.json.new <<\EOF || "editor.wordWrap": "wordWrapColumn", "editor.wordWrapColumn": 72 }, + "[c]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.tabSize": 8, + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 80, + "files.trimTrailingWhitespace": true + }, "files.associations": { "*.h": "c", "*.c": "c"
Signature · 1 line
gitgitgadget
Re: [PATCH 7/9] vscode: use 8-space tabs, no trailing ws, etc for Git's source code
Am 23.07.2018 um 15:52 schrieb Johannes Schindelin via GitGitGadget:
Quoted 16 lines
From: Johannes Schindelin <[email protected]>
This adds a couple settings for the .c/.h files so that it is easier to conform to Git's conventions while editing the source code.
Signed-off-by Johannes Schindelin <[email protected]>--- contrib/vscode/init.sh | 8 ++++++++ 1 file changed, 8 insertions(+)contrib/vscode/init.sh +0
-0@@ -21,6 +21,14 @@ cat >.vscode/settings.json.new <<\EOF || "editor.wordWrap": "wordWrapColumn",
contrib/vscode/init.sh cat >.vscode/settings.json.new <<\EOF || · line 31
Quoted 10 lines
contrib/vscode/init.sh +8
-0"editor.wordWrapColumn": 72 }, + "[c]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.tabSize": 8, + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 80, + "files.trimTrailingWhitespace": true + },
I am a VS Code user, but I haven't used these settings before.
With these settings, does the editor break lines while I am typing? Or does it just insert a visual cue that tells where I should insert a line break? If the former, it would basically make the editor unusable for my taste. I want to have total control over the code I write. The 80 column limit is just a recommendation, not a hard requirement.
contrib/vscode/init.sh cat >.vscode/settings.json.new <<\EOF || · line 34
Quoted 4 lines
contrib/vscode/init.sh +0
-0"files.associations": { "*.h": "c", "*.c": "c"
-- Hannes
Re: [PATCH 7/9] vscode: use 8-space tabs, no trailing ws, etc for Git's source code
Hi Hannes,
Quoted 30 lines · Johannes Sixt
Am 23.07.2018 um 15:52 schrieb Johannes Schindelin via GitGitGadget:
Quoted 16 lines
From: Johannes Schindelin <[email protected]>
This adds a couple settings for the .c/.h files so that it is easier to conform to Git's conventions while editing the source code.
Signed-off-by Johannes Schindelin <[email protected]>--- contrib/vscode/init.sh | 8 ++++++++ 1 file changed, 8 insertions(+)contrib/vscode/init.sh +0
-0@@ -21,6 +21,14 @@ cat >.vscode/settings.json.new <<\EOF || "editor.wordWrap": "wordWrapColumn",contrib/vscode/init.sh cat >.vscode/settings.json.new <<\EOF || · line 31
Quoted 10 lines
contrib/vscode/init.sh +8
-0"editor.wordWrapColumn": 72 }, + "[c]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.tabSize": 8, + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 80, + "files.trimTrailingWhitespace": true + },I am a VS Code user, but I haven't used these settings before.
Quoted 5 lines
With these settings, does the editor break lines while I am typing? Or does it just insert a visual cue that tells where I should insert a line break? If the former, it would basically make the editor unusable for my taste. I want to have total control over the code I write. The 80 column limit is just a recommendation, not a hard requirement.
Fear not. It is giving you a very clear visual cue, but that's all. It does show the line wrapped, but the line number column quite clearly shows that it did not insert a new-line.
Ciao,
Dscho
Quoted 9 lines
contrib/vscode/init.sh cat >.vscode/settings.json.new <<\EOF || · line 34
Quoted 5 lines
contrib/vscode/init.sh +0
-0"files.associations": { "*.h": "c", "*.c": "c"-- Hannes
PATCH 8/9 vscode: add a dictionary for cSpell
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
The quite useful cSpell extension allows VS Code to have "squiggly" lines under spelling mistakes. By default, this would add too much clutter, though, because so much of Git's source code uses words that would trigger cSpell.
Let's add a few words to make the spell checking more useful by reducing the number of false positives.
--- contrib/vscode/init.sh | 169 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-)
contrib/vscode/init.sh +168 -1
@@ -32,7 +32,174 @@ cat >.vscode/settings.json.new <<\EOF || "files.associations": { "*.h": "c", "*.c": "c" - } + }, + "cSpell.words": [ + "DATAW", + "DBCACHED", + "DFCHECK", + "DTYPE", + "Hamano", + "HCAST", + "HEXSZ", + "HKEY", + "HKLM", + "IFGITLINK", + "IFINVALID", + "ISBROKEN", + "ISGITLINK", + "ISSYMREF", + "Junio", + "LPDWORD", + "LPPROC", + "LPWSTR", + "MSVCRT", + "NOARG", + "NOCOMPLETE", + "NOINHERIT", + "RENORMALIZE", + "STARTF", + "STARTUPINFOEXW", + "Schindelin", + "UCRT", + "YESNO", + "argcp", + "beginthreadex", + "committish", + "contentp", + "cpath", + "cpidx", + "ctim", + "dequote", + "envw", + "ewah", + "fdata", + "fherr", + "fhin", + "fhout", + "fragp", + "fsmonitor", + "hnsec", + "idents", + "includeif", + "interpr", + "iprog", + "isexe", + "iskeychar", + "kompare", + "mksnpath", + "mktag", + "mktree", + "mmblob", + "mmbuffer", + "mmfile", + "noenv", + "nparents", + "ntpath", + "ondisk", + "ooid", + "oplen", + "osdl", + "pnew", + "pold", + "ppinfo", + "pushf", + "pushv", + "rawsz", + "rebasing", + "reencode", + "repo", + "rerere", + "scld", + "sharedrepo", + "spawnv", + "spawnve", + "spawnvpe", + "strdup'ing", + "submodule", + "submodules", + "topath", + "topo", + "tpatch", + "unexecutable", + "unhide", + "unkc", + "unkv", + "unmark", + "unmatch", + "unsets", + "unshown", + "untracked", + "untrackedcache", + "unuse", + "upos", + "uval", + "vreportf", + "wargs", + "wargv", + "wbuffer", + "wcmd", + "wcsnicmp", + "wcstoutfdup", + "wdeltaenv", + "wdir", + "wenv", + "wenvblk", + "wenvcmp", + "wenviron", + "wenvpos", + "wenvsz", + "wfile", + "wfilename", + "wfopen", + "wfreopen", + "wfullpath", + "which'll", + "wlink", + "wmain", + "wmkdir", + "wmktemp", + "wnewpath", + "wotype", + "wpath", + "wpathname", + "wpgmptr", + "wpnew", + "wpointer", + "wpold", + "wpos", + "wputenv", + "wrmdir", + "wship", + "wtarget", + "wtemplate", + "wunlink", + "xcalloc", + "xgetcwd", + "xmallocz", + "xmemdupz", + "xmmap", + "xopts", + "xrealloc", + "xsnprintf", + "xutftowcs", + "xutftowcsn", + "xwcstoutf" + ], + "cSpell.ignoreRegExpList": [ + "\\\"(DIRC|FSMN|REUC|UNTR)\\\"", + "\\\\u[0-9a-fA-Fx]{4}\\b", + "\\b(filfre|frotz|xyzzy)\\b", + "\\bCMIT_FMT_DEFAULT\\b", + "\\bde-munge\\b", + "\\bGET_OID_DISAMBIGUATORS\\b", + "\\bHASH_RENORMALIZE\\b", + "\\bTREESAMEness\\b", + "\\bUSE_STDEV\\b", + "\\Wchar *\\*\\W*utfs\\W", + "cURL's", + "nedmalloc'ed", + "ntifs\\.h", + ], } EOF die "Could not write settings.json"
Signature · 1 line
gitgitgadget
PATCH 9/9 vscode: let cSpell work on commit messages, too
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
By default, the cSpell extension ignores all files under .git/. That includes, unfortunately, COMMIT_EDITMSG, i.e. commit messages. However, spell checking is *quite* useful when writing commit messages... And since the user hardly ever opens any file inside .git (apart from commit messages, the config, and sometimes interactive rebase's todo lists), there is really not much harm in *not* ignoring .git/.
The default also ignores node_modules/, but that does not apply to Git, so let's skip ignoring that, too.
--- contrib/vscode/init.sh | 2 ++ 1 file changed, 2 insertions(+)
contrib/vscode/init.sh +2 -0
@@ -33,6 +33,8 @@ cat >.vscode/settings.json.new <<\EOF || "*.h": "c", "*.c": "c" }, + "cSpell.ignorePaths": [ + ], "cSpell.words": [ "DATAW", "DBCACHED",
Signature · 1 line
gitgitgadget
v2 cover Add support to develop Git in Visual Studio Code
In reply to Johannes Schindelin via GitGitGadget[Visual Studio Code](https://code.visualstudio.com/) (nickname "VS Code") is a light-weight, cross-platform, Open Source development environment, with an increasingly powerful extension to support C/C++ development. In particular the intellisense support as well as all the other niceties developers might have come to expect from Integrated Development Environments will help accelerate development.
Due to the way Git's source code and build process is structured, it can be quite challenging to use VS Code effectively for developing Git. Which is a shame, as developing with vim and the command-line causes unnecessary churn, and it is quite understandable that most Git developers simply do not want to fight with a modern development environment just to try whether they like developing Git with it.
This topic branch makes it easy to get started using VS Code to develop Git.
Simply run the script ./contrib/vscode/init.sh. This will initialize the .vscode/ directory and some files in that directory. After that, just open Git's top-level directory as "folder" in VS Code.
The files have to be generated because of the curious way Git determines what flags to pass to the C compiler, in particular which constants are defined, because they change the compile flow in rather dramatic ways (determining, e.g. which SHA-1 backend to use).
Changes since v1:
- Clarified commit message of the first commit.
Johannes Schindelin (9):
contrib: add a script to initialize VS Code configuration
vscode: hard-code a couple defines
cache.h: extract enum declaration from inside a struct declaration
mingw: define WIN32 explicitly
vscode: only overwrite C/C++ settings
vscode: wrap commit messages at column 72 by default
vscode: use 8-space tabs, no trailing ws, etc for Git's source code
vscode: add a dictionary for cSpell
vscode: let cSpell work on commit messages, too
.gitignore | 1 + cache.h | 24 ++- config.mak.uname | 2 +- contrib/vscode/.gitattributes | 1 + contrib/vscode/README.md | 14 ++ contrib/vscode/init.sh | 375 ++++++++++++++++++++++++++++++++++ 6 files changed, 405 insertions(+), 12 deletions(-) create mode 100644 contrib/vscode/.gitattributes create mode 100644 contrib/vscode/README.md create mode 100755 contrib/vscode/init.sh
base-commit: 53f9a3e157dbbc901a02ac2c73346d375e24978c
Published-As: https://github.com/gitgitgadget/git/releases/tags/pr-2%2Fdscho%2Fvscode-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2/dscho/vscode-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2
Range-diff vs v1:
1: e2e449a00 ! 1: bbf13e40a contrib: add a script to initialize VS Code configuration
@@ -4,11 +4,14 @@
VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. Among other
- languages, it has support for C/C++ via an extension.
+ languages, it has support for C/C++ via an extension, which offers to
+ not only build and debug the code, but also Intellisense, i.e.
+ code-aware completion and similar niceties.
- To start developing Git with VS Code, simply run the Unix shell script
- contrib/vscode/init.sh, which creates the configuration files in
- .vscode/ that VS Code consumes.
+ This patch adds a script that helps set up the environment to work
+ effectively with VS Code: simply run the Unix shell script
+ contrib/vscode/init.sh, which creates the relevant files, and open the
+ top level folder of Git's source code in VS Code.
2: 3770bd855 = 2: 6c8b5a4f2 vscode: hard-code a couple defines 3: de49c4bf2 = 3: 105b50c62 cache.h: extract enum declaration from inside a struct declaration 4: b3ce2ccf4 = 4: 4b95b1e2a mingw: define WIN32 explicitly 5: 06dcf6d97 = 5: 3dd53c04c vscode: only overwrite C/C++ settings 6: 08212c57e = 6: 384b08836 vscode: wrap commit messages at column 72 by default 7: 2e880b6f1 = 7: ba78af756 vscode: use 8-space tabs, no trailing ws, etc for Git's source code 8: ce216cf43 = 8: 358f38d3a vscode: add a dictionary for cSpell 9: 4c2aa015a = 9: b9c628b88 vscode: let cSpell work on commit messages, too
Signature · 1 line
gitgitgadget
PATCH v2 1/9 contrib: add a script to initialize VS Code configuration
From: Johannes Schindelin <[email protected]>
VS Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. Among other languages, it has support for C/C++ via an extension, which offers to not only build and debug the code, but also Intellisense, i.e. code-aware completion and similar niceties.
This patch adds a script that helps set up the environment to work effectively with VS Code: simply run the Unix shell script contrib/vscode/init.sh, which creates the relevant files, and open the top level folder of Git's source code in VS Code.
--- .gitignore | 1 + contrib/vscode/.gitattributes | 1 + contrib/vscode/README.md | 14 +++ contrib/vscode/init.sh | 165 ++++++++++++++++++++++++++++++++++ 4 files changed, 181 insertions(+) create mode 100644 contrib/vscode/.gitattributes create mode 100644 contrib/vscode/README.md create mode 100755 contrib/vscode/init.sh
.gitignore +1 -0
@@ -206,6 +206,7 @@ /config.mak.autogen /config.mak.append /configure +/.vscode/ /tags /TAGS /cscope*
contrib/vscode/.gitattributes new file +1 -0
@@ -0,0 +1 @@ +init.sh whitespace=-indent-with-non-tab
contrib/vscode/README.md new file +14 -0
@@ -0,0 +1,14 @@ +Configuration for VS Code +========================= + +[VS Code](https://code.visualstudio.com/) is a lightweight but powerful source +code editor which runs on your desktop and is available for +[Windows](https://code.visualstudio.com/docs/setup/windows), +[macOS](https://code.visualstudio.com/docs/setup/mac) and +[Linux](https://code.visualstudio.com/docs/setup/linux). Among other languages, +it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools). + +To start developing Git with VS Code, simply run the Unix shell script called +`init.sh` in this directory, which creates the configuration files in +`.vscode/` that VS Code consumes. `init.sh` needs access to `make` and `gcc`, +so run the script in a Git SDK shell if you are using Windows.
contrib/vscode/init.sh new file +165 -0
165 lines not on this page · raw message
Signature · 1 line
gitgitgadget
PATCH v2 2/9 vscode: hard-code a couple defines
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
Sadly, we do not get all of the definitions via ALL_CFLAGS. Some defines are passed to GCC *only* when compiling specific files, such as git.o.
Let's just hard-code them into the script for the time being.
--- contrib/vscode/init.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
contrib/vscode/init.sh +13 -1
@@ -115,7 +115,19 @@ include Makefile vscode-init: @mkdir -p .vscode && \ incs= && defs= && \ - for e in $(ALL_CFLAGS); do \ + for e in $(ALL_CFLAGS) \ + '-DGIT_EXEC_PATH="$(gitexecdir_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ + '-DBINDIR="$(bindir_relative_SQ)"' \ + '-DFALLBACK_RUNTIME_PREFIX="$(prefix_SQ)"' \ + '-DDEFAULT_GIT_TEMPLATE_DIR="$(template_dir_SQ)"' \ + '-DETC_GITCONFIG="$(ETC_GITCONFIG_SQ)"' \ + '-DETC_GITATTRIBUTES="$(ETC_GITATTRIBUTES_SQ)"' \ + '-DGIT_LOCALE_PATH="$(localedir_relative_SQ)"' \ + '-DCURL_DISABLE_TYPECHECK', \ + '-DGIT_HTML_PATH="$(htmldir_relative_SQ)"' \ + '-DGIT_MAN_PATH="$(mandir_relative_SQ)"' \ + '-DGIT_INFO_PATH="$(infodir_relative_SQ)"'; do \ case "$$e" in \ -I.) \ incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
Signature · 1 line
gitgitgadget
PATCH v2 3/9 cache.h: extract enum declaration from inside a struct declaration
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
While it is technically possible, it is confusing. Not only the user, but also VS Code's intellisense.
--- cache.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-)
cache.h +13 -11
@@ -1425,18 +1425,20 @@ extern void *read_object_with_reference(const struct object_id *oid,extern struct object *peel_to_type (const char *name,int namelen,struct object *o,enum object_type ); +enum date_mode_type { +DATE_NORMAL =0 , +DATE_RELATIVE , +DATE_SHORT , +DATE_ISO8601 , +DATE_ISO8601_STRICT , +DATE_RFC2822 , +DATE_STRFTIME , +DATE_RAW , +DATE_UNIX +}; +struct date_mode { -enum date_mode_type { -DATE_NORMAL =0 , -DATE_RELATIVE , -DATE_SHORT , -DATE_ISO8601 , -DATE_ISO8601_STRICT , -DATE_RFC2822 , -DATE_STRFTIME , -DATE_RAW , -DATE_UNIX - } type; +enum date_mode_type type;const char *strftime_fmt;int local; };
Signature · 1 line
gitgitgadget
PATCH v2 4/9 mingw: define WIN32 explicitly
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
This helps VS Code's intellisense to figure out that we want to include windows.h, and that we want to define the minimum target Windows version as Windows Vista/2008R2.
--- config.mak.uname | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
config.mak.uname +1 -1
@@ -528,7 +528,7 @@ ifneq (,$(findstring MINGW,$(uname_S))) COMPAT_OBJS += compat/mingw.o compat/winansi.o \ compat/win32/pthread.o compat/win32/syslog.o \ compat/win32/dirent.o - BASIC_CFLAGS += -DPROTECT_NTFS_DEFAULT=1 + BASIC_CFLAGS += -DWIN32 -DPROTECT_NTFS_DEFAULT=1 EXTLIBS += -lws2_32 GITLIBS += git.res PTHREAD_LIBS =
Signature · 1 line
gitgitgadget
PATCH v2 5/9 vscode: only overwrite C/C++ settings
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
The C/C++ settings are special, as they are the only generated VS Code configurations that *will* change over the course of Git's development, e.g. when a new constant is defined.
Therefore, let's only update the C/C++ settings, also to prevent user modifications from being overwritten.
Ideally, we would keep user modifications in the C/C++ settings, but that would require parsing JSON, a task for which a Unix shell script is distinctly unsuited. So we write out .new files instead, and warn the user if they may want to reconcile their changes.
--- contrib/vscode/init.sh | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-)
contrib/vscode/init.sh +20 -3
@@ -13,7 +13,7 @@ die "Could not create .vscode/" # General settings -cat >.vscode/settings.json <<\EOF || +cat >.vscode/settings.json.new <<\EOF || { "C_Cpp.intelliSenseEngine": "Default", "C_Cpp.intelliSenseEngineFallback": "Disabled",
@@ -51,7 +51,7 @@ esac # Default build task -cat >.vscode/tasks.json <<EOF || +cat >.vscode/tasks.json.new <<EOF || { // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format
@@ -73,7 +73,7 @@ die "Could not install default build task" # Debugger settings -cat >.vscode/launch.json <<EOF || +cat >.vscode/launch.json.new <<EOF || { // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes.
@@ -175,3 +175,20 @@ vscode-init: echo '}' EOF die "Could not write settings for the C/C++ extension" + +for file in .vscode/settings.json .vscode/tasks.json .vscode/launch.json +do + if test -f $file + then + if git diff --no-index --quiet --exit-code $file $file.new + then + rm $file.new + else + printf "The file $file.new has these changes:\n\n" + git --no-pager diff --no-index $file $file.new + printf "\n\nMaybe \`mv $file.new $file\`?\n\n" + fi + else + mv $file.new $file + fi +done
Signature · 1 line
gitgitgadget
PATCH v2 6/9 vscode: wrap commit messages at column 72 by default
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
When configuring VS Code as core.editor (via code --wait), we really want to adhere to the Git conventions of wrapping commit messages.
--- contrib/vscode/init.sh | 4 ++++ 1 file changed, 4 insertions(+)
contrib/vscode/init.sh +4 -0
@@ -17,6 +17,10 @@ cat >.vscode/settings.json.new <<\EOF || { "C_Cpp.intelliSenseEngine": "Default", "C_Cpp.intelliSenseEngineFallback": "Disabled", + "[git-commit]": { + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 72 + }, "files.associations": { "*.h": "c", "*.c": "c"
Signature · 1 line
gitgitgadget
PATCH v2 7/9 vscode: use 8-space tabs, no trailing ws, etc for Git's source code
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
This adds a couple settings for the .c/.h files so that it is easier to conform to Git's conventions while editing the source code.
--- contrib/vscode/init.sh | 8 ++++++++ 1 file changed, 8 insertions(+)
contrib/vscode/init.sh +8 -0
@@ -21,6 +21,14 @@ cat >.vscode/settings.json.new <<\EOF || "editor.wordWrap": "wordWrapColumn", "editor.wordWrapColumn": 72 }, + "[c]": { + "editor.detectIndentation": false, + "editor.insertSpaces": false, + "editor.tabSize": 8, + "editor.wordWrap": "wordWrapColumn", + "editor.wordWrapColumn": 80, + "files.trimTrailingWhitespace": true + }, "files.associations": { "*.h": "c", "*.c": "c"
Signature · 1 line
gitgitgadget
PATCH v2 8/9 vscode: add a dictionary for cSpell
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
The quite useful cSpell extension allows VS Code to have "squiggly" lines under spelling mistakes. By default, this would add too much clutter, though, because so much of Git's source code uses words that would trigger cSpell.
Let's add a few words to make the spell checking more useful by reducing the number of false positives.
--- contrib/vscode/init.sh | 169 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-)
contrib/vscode/init.sh +168 -1
@@ -32,7 +32,174 @@ cat >.vscode/settings.json.new <<\EOF || "files.associations": { "*.h": "c", "*.c": "c" - } + }, + "cSpell.words": [ + "DATAW", + "DBCACHED", + "DFCHECK", + "DTYPE", + "Hamano", + "HCAST", + "HEXSZ", + "HKEY", + "HKLM", + "IFGITLINK", + "IFINVALID", + "ISBROKEN", + "ISGITLINK", + "ISSYMREF", + "Junio", + "LPDWORD", + "LPPROC", + "LPWSTR", + "MSVCRT", + "NOARG", + "NOCOMPLETE", + "NOINHERIT", + "RENORMALIZE", + "STARTF", + "STARTUPINFOEXW", + "Schindelin", + "UCRT", + "YESNO", + "argcp", + "beginthreadex", + "committish", + "contentp", + "cpath", + "cpidx", + "ctim", + "dequote", + "envw", + "ewah", + "fdata", + "fherr", + "fhin", + "fhout", + "fragp", + "fsmonitor", + "hnsec", + "idents", + "includeif", + "interpr", + "iprog", + "isexe", + "iskeychar", + "kompare", + "mksnpath", + "mktag", + "mktree", + "mmblob", + "mmbuffer", + "mmfile", + "noenv", + "nparents", + "ntpath", + "ondisk", + "ooid", + "oplen", + "osdl", + "pnew", + "pold", + "ppinfo", + "pushf", + "pushv", + "rawsz", + "rebasing", + "reencode", + "repo", + "rerere", + "scld", + "sharedrepo", + "spawnv", + "spawnve", + "spawnvpe", + "strdup'ing", + "submodule", + "submodules", + "topath", + "topo", + "tpatch", + "unexecutable", + "unhide", + "unkc", + "unkv", + "unmark", + "unmatch", + "unsets", + "unshown", + "untracked", + "untrackedcache", + "unuse", + "upos", + "uval", + "vreportf", + "wargs", + "wargv", + "wbuffer", + "wcmd", + "wcsnicmp", + "wcstoutfdup", + "wdeltaenv", + "wdir", + "wenv", + "wenvblk", + "wenvcmp", + "wenviron", + "wenvpos", + "wenvsz", + "wfile", + "wfilename", + "wfopen", + "wfreopen", + "wfullpath", + "which'll", + "wlink", + "wmain", + "wmkdir", + "wmktemp", + "wnewpath", + "wotype", + "wpath", + "wpathname", + "wpgmptr", + "wpnew", + "wpointer", + "wpold", + "wpos", + "wputenv", + "wrmdir", + "wship", + "wtarget", + "wtemplate", + "wunlink", + "xcalloc", + "xgetcwd", + "xmallocz", + "xmemdupz", + "xmmap", + "xopts", + "xrealloc", + "xsnprintf", + "xutftowcs", + "xutftowcsn", + "xwcstoutf" + ], + "cSpell.ignoreRegExpList": [ + "\\\"(DIRC|FSMN|REUC|UNTR)\\\"", + "\\\\u[0-9a-fA-Fx]{4}\\b", + "\\b(filfre|frotz|xyzzy)\\b", + "\\bCMIT_FMT_DEFAULT\\b", + "\\bde-munge\\b", + "\\bGET_OID_DISAMBIGUATORS\\b", + "\\bHASH_RENORMALIZE\\b", + "\\bTREESAMEness\\b", + "\\bUSE_STDEV\\b", + "\\Wchar *\\*\\W*utfs\\W", + "cURL's", + "nedmalloc'ed", + "ntifs\\.h", + ], } EOF die "Could not write settings.json"
Signature · 1 line
gitgitgadget
PATCH v2 9/9 vscode: let cSpell work on commit messages, too
In reply to Johannes Schindelin via GitGitGadgetFrom: Johannes Schindelin <[email protected]>
By default, the cSpell extension ignores all files under .git/. That includes, unfortunately, COMMIT_EDITMSG, i.e. commit messages. However, spell checking is *quite* useful when writing commit messages... And since the user hardly ever opens any file inside .git (apart from commit messages, the config, and sometimes interactive rebase's todo lists), there is really not much harm in *not* ignoring .git/.
The default also ignores node_modules/, but that does not apply to Git, so let's skip ignoring that, too.
--- contrib/vscode/init.sh | 2 ++ 1 file changed, 2 insertions(+)
contrib/vscode/init.sh +2 -0
@@ -33,6 +33,8 @@ cat >.vscode/settings.json.new <<\EOF || "*.h": "c", "*.c": "c" }, + "cSpell.ignorePaths": [ + ], "cSpell.words": [ "DATAW", "DBCACHED",
Signature · 1 line
gitgitgadget