From 54c06c601316bb41b8305c0f3ec755818eb54b7b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:46 -0700 Subject: [PATCH 1/9] contrib: add a script to initialize VS Code configuration 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. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- .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 diff --git a/.gitignore b/.gitignore index 3284a1e9b1..3524803da5 100644 --- a/.gitignore +++ b/.gitignore @@ -207,6 +207,7 @@ /config.mak.autogen /config.mak.append /configure +/.vscode/ /tags /TAGS /cscope* diff --git a/contrib/vscode/.gitattributes b/contrib/vscode/.gitattributes new file mode 100644 index 0000000000..e89f2236ef --- /dev/null +++ b/contrib/vscode/.gitattributes @@ -0,0 +1 @@ +init.sh whitespace=-indent-with-non-tab diff --git a/contrib/vscode/README.md b/contrib/vscode/README.md new file mode 100644 index 0000000000..8202d62035 --- /dev/null +++ b/contrib/vscode/README.md @@ -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. diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh new file mode 100755 index 0000000000..3cc93243f5 --- /dev/null +++ b/contrib/vscode/init.sh @@ -0,0 +1,165 @@ +#!/bin/sh + +die () { + echo "$*" >&2 + exit 1 +} + +cd "$(dirname "$0")"/../.. || +die "Could not cd to top-level directory" + +mkdir -p .vscode || +die "Could not create .vscode/" + +# General settings + +cat >.vscode/settings.json <<\EOF || +{ + "C_Cpp.intelliSenseEngine": "Default", + "C_Cpp.intelliSenseEngineFallback": "Disabled", + "files.associations": { + "*.h": "c", + "*.c": "c" + } +} +EOF +die "Could not write settings.json" + +# Infer some setup-specific locations/names + +GCCPATH="$(which gcc)" +GDBPATH="$(which gdb)" +MAKECOMMAND="make -j5 DEVELOPER=1" +OSNAME= +X= +case "$(uname -s)" in +MINGW*) + GCCPATH="$(cygpath -am "$GCCPATH")" + GDBPATH="$(cygpath -am "$GDBPATH")" + MAKE_BASH="$(cygpath -am /git-cmd.exe) --command=usr\\\\bin\\\\bash.exe" + MAKECOMMAND="$MAKE_BASH -lc \\\"$MAKECOMMAND\\\"" + OSNAME=Win32 + X=.exe + ;; +Linux) + OSNAME=Linux + ;; +Darwin) + OSNAME=macOS + ;; +esac + +# Default build task + +cat >.vscode/tasks.json <.vscode/launch.json <.vscode/c_cpp_properties.json <<\EOF || +include Makefile + +vscode-init: + @mkdir -p .vscode && \ + incs= && defs= && \ + for e in $(ALL_CFLAGS); do \ + case "$$e" in \ + -I.) \ + incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \ + "" "$$incs")" \ + ;; \ + -I/*) \ + incs="$$(printf '% 16s"%s",\n%s' \ + "" "$${e#-I}" "$$incs")" \ + ;; \ + -I*) \ + incs="$$(printf '% 16s"$${workspaceRoot}/%s",\n%s' \ + "" "$${e#-I}" "$$incs")" \ + ;; \ + -D*) \ + defs="$$(printf '% 16s"%s",\n%s' \ + "" "$$(echo "$${e#-D}" | sed 's/"/\\&/g')" \ + "$$defs")" \ + ;; \ + esac; \ + done && \ + echo '{' && \ + echo ' "configurations": [' && \ + echo ' {' && \ + echo ' "name": "$(OSNAME)",' && \ + echo ' "intelliSenseMode": "clang-x64",' && \ + echo ' "includePath": [' && \ + echo "$$incs" | sort | sed '$$s/,$$//' && \ + echo ' ],' && \ + echo ' "defines": [' && \ + echo "$$defs" | sort | sed '$$s/,$$//' && \ + echo ' ],' && \ + echo ' "browse": {' && \ + echo ' "limitSymbolsToIncludedHeaders": true,' && \ + echo ' "databaseFilename": "",' && \ + echo ' "path": [' && \ + echo ' "$${workspaceRoot}"' && \ + echo ' ]' && \ + echo ' },' && \ + echo ' "cStandard": "c11",' && \ + echo ' "cppStandard": "c++17",' && \ + echo ' "compilerPath": "$(GCCPATH)"' && \ + echo ' }' && \ + echo ' ],' && \ + echo ' "version": 4' && \ + echo '}' +EOF +die "Could not write settings for the C/C++ extension" From dee338236bbef71639149ba90ec60cb732b73cd0 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:48 -0700 Subject: [PATCH 2/9] vscode: hard-code a couple defines 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. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/vscode/init.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index 3cc93243f5..494a51ac55 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -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' \ From 58930fdb195d55d25d84c7d6ba2e2976d78a423d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:49 -0700 Subject: [PATCH 3/9] cache.h: extract enum declaration from inside a struct declaration While it is technically possible, it is confusing. Not only the user, but also VS Code's intellisense. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cache.h b/cache.h index 8b447652a7..cdb489fca3 100644 --- a/cache.h +++ b/cache.h @@ -1362,18 +1362,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; }; From b4d991d1a2e2f5da6d3f08d82d1fa9ef45605e07 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:51 -0700 Subject: [PATCH 4/9] mingw: define WIN32 explicitly 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. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- config.mak.uname | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mak.uname b/config.mak.uname index 684fc5bf02..2be2f19811 100644 --- a/config.mak.uname +++ b/config.mak.uname @@ -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 = From 0f47f78e02d16e6edd0448285815ccc1744294e8 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:52 -0700 Subject: [PATCH 5/9] vscode: only overwrite C/C++ settings 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. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/vscode/init.sh | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index 494a51ac55..ba94692268 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -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 <.vscode/tasks.json.new <.vscode/launch.json <.vscode/launch.json.new < Date: Mon, 30 Jul 2018 08:42:54 -0700 Subject: [PATCH 6/9] vscode: wrap commit messages at column 72 by default When configuring VS Code as core.editor (via `code --wait`), we really want to adhere to the Git conventions of wrapping commit messages. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/vscode/init.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index ba94692268..face115e89 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -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" From 5482f418f5185cd2c2c94c1aec58c7c035780b8a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:55 -0700 Subject: [PATCH 7/9] vscode: use 8-space tabs, no trailing ws, etc for Git's source code 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 Signed-off-by: Junio C Hamano --- contrib/vscode/init.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index face115e89..29f2a729d1 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -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" From 2a2cdd069a071277923b4fcb51d93c38f0616956 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:57 -0700 Subject: [PATCH 8/9] vscode: add a dictionary for cSpell 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. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/vscode/init.sh | 169 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 168 insertions(+), 1 deletion(-) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index 29f2a729d1..a134cb4c5f 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -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" From 12861e200a0e530f5293374a9507c6aea0359e25 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 30 Jul 2018 08:42:58 -0700 Subject: [PATCH 9/9] vscode: let cSpell work on commit messages, too 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. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- contrib/vscode/init.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index a134cb4c5f..27de94994b 100755 --- a/contrib/vscode/init.sh +++ b/contrib/vscode/init.sh @@ -33,6 +33,8 @@ cat >.vscode/settings.json.new <<\EOF || "*.h": "c", "*.c": "c" }, + "cSpell.ignorePaths": [ + ], "cSpell.words": [ "DATAW", "DBCACHED",