From bbf13e40a501b6d46766cbf69fd6022b9c0b47b3 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 17 May 2018 15:32:40 +0200 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 --- .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 388cc4beee54fa..592e8f879f5493 100644 --- a/.gitignore +++ b/.gitignore @@ -206,6 +206,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 00000000000000..e89f2236efeac4 --- /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 00000000000000..8202d62035f98e --- /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 00000000000000..3cc93243f59cf2 --- /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 6c8b5a4f2234e1340859cafe29bb49b846ca140d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 17 May 2018 17:29:41 +0200 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 --- 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 3cc93243f59cf2..494a51ac55320a 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 105b50c62667640d0ed45cba1cf730bc3f2237da Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 17 May 2018 21:39:19 +0200 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 --- cache.h | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cache.h b/cache.h index 89a107a7f79175..2380136f67884d 100644 --- a/cache.h +++ b/cache.h @@ -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; }; From 4b95b1e2a3eb3d3c26dc3fdc5cd880792a5f048e Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Thu, 17 May 2018 21:51:37 +0200 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 --- config.mak.uname | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.mak.uname b/config.mak.uname index 684fc5bf02677b..2be2f198113943 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 3dd53c04c4e10d0ec8ce2e6b04558824ab61eb67 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 18 May 2018 10:20:10 +0200 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 --- 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 494a51ac55320a..ba946922681e62 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: Fri, 18 May 2018 10:30:06 +0200 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 --- contrib/vscode/init.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index ba946922681e62..face115e89022c 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 ba78af756bac56d2c4436a1de924fc72e6887a47 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Fri, 18 May 2018 13:46:02 +0200 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 --- contrib/vscode/init.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index face115e89022c..29f2a729d1c0ee 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 358f38d3aa058bb9399f4a8fab71027e2e7a6289 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 17 Jun 2018 21:47:28 +0200 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 --- 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 29f2a729d1c0ee..a134cb4c5fc703 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 b9c628b8812abb265c4f48f846dc3d3e170649e6 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 17 Jun 2018 21:52:37 +0200 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 --- contrib/vscode/init.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/contrib/vscode/init.sh b/contrib/vscode/init.sh index a134cb4c5fc703..27de94994b5dc5 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",