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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Jul 30, 2018 at 08:42 UTC
54c06c601316bb41b8305c0f3ec755818eb54b7b
4 files changed
+181
.gitignore
+1
@@ -207,6 +207,7 @@
207
/config.mak.autogen
208
/config.mak.append
209
/configure
210
+/.vscode/
211
/tags
212
/TAGS
213
/cscope*
contrib/vscode/.gitattributes
new
+1
@@ -0,0 +1 @@
1
+init.sh whitespace=-indent-with-non-tab
contrib/vscode/README.md
new
+14
@@ -0,0 +1,14 @@
1
+Configuration for VS Code
2
+=========================
3
+
4
+[VS Code](https://code.visualstudio.com/) is a lightweight but powerful source
5
+code editor which runs on your desktop and is available for
6
+[Windows](https://code.visualstudio.com/docs/setup/windows),
7
+[macOS](https://code.visualstudio.com/docs/setup/mac) and
8
+[Linux](https://code.visualstudio.com/docs/setup/linux). Among other languages,
9
+it has [support for C/C++ via an extension](https://github.com/Microsoft/vscode-cpptools).
10
+
11
+To start developing Git with VS Code, simply run the Unix shell script called
12
+`init.sh` in this directory, which creates the configuration files in
13
+`.vscode/` that VS Code consumes. `init.sh` needs access to `make` and `gcc`,
14
+so run the script in a Git SDK shell if you are using Windows.
contrib/vscode/init.sh
new
+165
@@ -0,0 +1,165 @@
1
+#!/bin/sh
2
+
3
+die () {
4
+ echo "$*" >&2
5
+ exit 1
6
+}
7
+
8
+cd "$(dirname "$0")"/../.. ||
9
+die "Could not cd to top-level directory"
10
+
11
+mkdir -p .vscode ||
12
+die "Could not create .vscode/"
13
+
14
+# General settings
15
+
16
+cat >.vscode/settings.json <<\EOF ||
17
+{
18
+ "C_Cpp.intelliSenseEngine": "Default",
19
+ "C_Cpp.intelliSenseEngineFallback": "Disabled",
20
+ "files.associations": {
21
+ "*.h": "c",
22
+ "*.c": "c"
23
+ }
24
+}
25
+EOF
26
+die "Could not write settings.json"
27
+
28
+# Infer some setup-specific locations/names
29
+
30
+GCCPATH="$(which gcc)"
31
+GDBPATH="$(which gdb)"
32
+MAKECOMMAND="make -j5 DEVELOPER=1"
33
+OSNAME=
34
+X=
35
+case "$(uname -s)" in
36
+MINGW*)
37
+ GCCPATH="$(cygpath -am "$GCCPATH")"
38
+ GDBPATH="$(cygpath -am "$GDBPATH")"
39
+ MAKE_BASH="$(cygpath -am /git-cmd.exe) --command=usr\\\\bin\\\\bash.exe"
40
+ MAKECOMMAND="$MAKE_BASH -lc \\\"$MAKECOMMAND\\\""
41
+ OSNAME=Win32
42
+ X=.exe
43
+ ;;
44
+Linux)
45
+ OSNAME=Linux
46
+ ;;
47
+Darwin)
48
+ OSNAME=macOS
49
+ ;;
50
+esac
51
+
52
+# Default build task
53
+
54
+cat >.vscode/tasks.json <<EOF ||
55
+{
56
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
57
+ // for the documentation about the tasks.json format
58
+ "version": "2.0.0",
59
+ "tasks": [
60
+ {
61
+ "label": "make",
62
+ "type": "shell",
63
+ "command": "$MAKECOMMAND",
64
+ "group": {
65
+ "kind": "build",
66
+ "isDefault": true
67
+ }
68
+ }
69
+ ]
70
+}
71
+EOF
72
+die "Could not install default build task"
73
+
74
+# Debugger settings
75
+
76
+cat >.vscode/launch.json <<EOF ||
77
+{
78
+ // Use IntelliSense to learn about possible attributes.
79
+ // Hover to view descriptions of existing attributes.
80
+ // For more information, visit:
81
+ // https://go.microsoft.com/fwlink/?linkid=830387
82
+ "version": "0.2.0",
83
+ "configurations": [
84
+ {
85
+ "name": "(gdb) Launch",
86
+ "type": "cppdbg",
87
+ "request": "launch",
88
+ "program": "\${workspaceFolder}/git$X",
89
+ "args": [],
90
+ "stopAtEntry": false,
91
+ "cwd": "\${workspaceFolder}",
92
+ "environment": [],
93
+ "externalConsole": true,
94
+ "MIMode": "gdb",
95
+ "miDebuggerPath": "$GDBPATH",
96
+ "setupCommands": [
97
+ {
98
+ "description": "Enable pretty-printing for gdb",
99
+ "text": "-enable-pretty-printing",
100
+ "ignoreFailures": true
101
+ }
102
+ ]
103
+ }
104
+ ]
105
+}
106
+EOF
107
+die "Could not write launch configuration"
108
+
109
+# C/C++ extension settings
110
+
111
+make -f - OSNAME=$OSNAME GCCPATH="$GCCPATH" vscode-init \
112
+ >.vscode/c_cpp_properties.json <<\EOF ||
113
+include Makefile
114
+
115
+vscode-init:
116
+ @mkdir -p .vscode && \
117
+ incs= && defs= && \
118
+ for e in $(ALL_CFLAGS); do \
119
+ case "$$e" in \
120
+ -I.) \
121
+ incs="$$(printf '% 16s"$${workspaceRoot}",\n%s' \
122
+ "" "$$incs")" \
123
+ ;; \
124
+ -I/*) \
125
+ incs="$$(printf '% 16s"%s",\n%s' \
126
+ "" "$${e#-I}" "$$incs")" \
127
+ ;; \
128
+ -I*) \
129
+ incs="$$(printf '% 16s"$${workspaceRoot}/%s",\n%s' \
130
+ "" "$${e#-I}" "$$incs")" \
131
+ ;; \
132
+ -D*) \
133
+ defs="$$(printf '% 16s"%s",\n%s' \
134
+ "" "$$(echo "$${e#-D}" | sed 's/"/\\&/g')" \
135
+ "$$defs")" \
136
+ ;; \
137
+ esac; \
138
+ done && \
139
+ echo '{' && \
140
+ echo ' "configurations": [' && \
141
+ echo ' {' && \
142
+ echo ' "name": "$(OSNAME)",' && \
143
+ echo ' "intelliSenseMode": "clang-x64",' && \
144
+ echo ' "includePath": [' && \
145
+ echo "$$incs" | sort | sed '$$s/,$$//' && \
146
+ echo ' ],' && \
147
+ echo ' "defines": [' && \
148
+ echo "$$defs" | sort | sed '$$s/,$$//' && \
149
+ echo ' ],' && \
150
+ echo ' "browse": {' && \
151
+ echo ' "limitSymbolsToIncludedHeaders": true,' && \
152
+ echo ' "databaseFilename": "",' && \
153
+ echo ' "path": [' && \
154
+ echo ' "$${workspaceRoot}"' && \
155
+ echo ' ]' && \
156
+ echo ' },' && \
157
+ echo ' "cStandard": "c11",' && \
158
+ echo ' "cppStandard": "c++17",' && \
159
+ echo ' "compilerPath": "$(GCCPATH)"' && \
160
+ echo ' }' && \
161
+ echo ' ],' && \
162
+ echo ' "version": 4' && \
163
+ echo '}'
164
+EOF
165
+die "Could not write settings for the C/C++ extension"