Browse Source

Basic VSCode configuration for building and debugging (#2483)

* Basic VSCode configuration for building and debugging

* Fix building and debugging in Windows

* Move to contrib folder and add instructions
Lauris BH 2 years ago
parent
commit
4c2b1be3a4
6 changed files with 105 additions and 1 deletions
  1. 4 0
      .gitignore
  2. 2 0
      CONTRIBUTING.md
  3. 12 0
      contrib/ide/README.md
  4. 31 0
      contrib/ide/vscode/launch.json
  5. 51 0
      contrib/ide/vscode/tasks.json
  6. 5 1
      modules/setting/setting.go

+ 4 - 0
.gitignore

@@ -10,6 +10,9 @@ _test
10 10
 # IntelliJ
11 11
 .idea
12 12
 
13
+# MS VSCode
14
+.vscode
15
+
13 16
 # Architecture specific extensions/prefixes
14 17
 *.[568vq]
15 18
 [568vq].out
@@ -36,6 +39,7 @@ _testmain.go
36 39
 *.log
37 40
 
38 41
 /gitea
42
+/debug
39 43
 /integrations.test
40 44
 
41 45
 /bin

+ 2 - 0
CONTRIBUTING.md

@@ -26,6 +26,8 @@ It assumes you have followed the
26 26
 Sensitive security-related issues should be reported to
27 27
 [security@gitea.io](mailto:security@gitea.io).
28 28
 
29
+For configuring IDE or code editor to develop Gitea see [IDE and code editor configuration](contrib/ide/)
30
+
29 31
 ## Bug reports
30 32
 
31 33
 Please search the issues on the issue tracker with a variety of keywords

+ 12 - 0
contrib/ide/README.md

@@ -0,0 +1,12 @@
1
+# IDE and code editor configuration
2
+
3
+## Table of Contents
4
+- [IDE and code editor configuration](#ide-and-code-editor-configuration)
5
+  - [Microsoft Visual Studio Code](#microsoft-visual-studio-code)
6
+
7
+## Microsoft Visual Studio Code
8
+Download Microsoft Visual Studio Code at https://code.visualstudio.com/ and follow instructions at https://code.visualstudio.com/docs/languages/go to setup Go extension for it.
9
+
10
+Create new direcotry `.vscode` in Gitea root folder and copy contents of folder [contrib/ide/vscode](vscode/) to it. You can now use `Ctrl`+`Shift`+`B` to build gitea executable and `F5` to run it in debug mode.
11
+
12
+Supported on Debian, Ubuntu, Red Hat, Fedora, SUSE Linux, MacOS and Microsoft Windows.

+ 31 - 0
contrib/ide/vscode/launch.json

@@ -0,0 +1,31 @@
1
+{
2
+  "version": "0.2.0",
3
+  "configurations": [
4
+    {
5
+      "name": "Launch",
6
+      "type": "go",
7
+      "request": "launch",
8
+      "mode": "debug",
9
+      "buildFlags": "",
10
+      "port": 2345,
11
+      "host": "127.0.0.1",
12
+      "program": "${workspaceRoot}/main.go",
13
+      "env": {},
14
+      "args": ["web"],
15
+      "showLog": true
16
+    },
17
+    {
18
+      "name": "Launch (with SQLite3)",
19
+      "type": "go",
20
+      "request": "launch",
21
+      "mode": "debug",
22
+      "buildFlags": "-tags=\"sqlite\"",
23
+      "port": 2345,
24
+      "host": "127.0.0.1",
25
+      "program": "${workspaceRoot}/main.go",
26
+      "env": {},
27
+      "args": ["web"],
28
+      "showLog": true
29
+    }
30
+  ]
31
+}

+ 51 - 0
contrib/ide/vscode/tasks.json

@@ -0,0 +1,51 @@
1
+{
2
+  "version": "2.0.0",
3
+  "tasks": [
4
+    {
5
+      "taskName": "Build",
6
+      "type": "shell",
7
+      "command": "go",
8
+      "group": "build",
9
+      "presentation": {
10
+        "echo": true,
11
+        "reveal": "always",
12
+        "focus": false,
13
+        "panel": "shared"
14
+      },
15
+      "args": ["build"],
16
+      "linux": {
17
+        "args": [ "-o", "gitea", "${workspaceRoot}/main.go" ]
18
+      },
19
+      "osx": {
20
+        "args": [ "-o", "gitea", "${workspaceRoot}/main.go" ]
21
+      },
22
+      "windows": {
23
+        "args": [ "-o", "gitea.exe", "\"${workspaceRoot}\\main.go\""]
24
+      },
25
+      "problemMatcher": ["$go"]
26
+    },
27
+    {
28
+      "taskName": "Build (with SQLite3)",
29
+      "type": "shell",
30
+      "command": "go",
31
+      "group": "build",
32
+      "presentation": {
33
+        "echo": true,
34
+        "reveal": "always",
35
+        "focus": false,
36
+        "panel": "shared"
37
+      },
38
+      "args": ["build", "-tags=\"sqlite\""],
39
+      "linux": {
40
+        "args": ["-o", "gitea", "${workspaceRoot}/main.go"]
41
+      },
42
+      "osx": {
43
+        "args": ["-o", "gitea", "${workspaceRoot}/main.go"]
44
+      },
45
+      "windows": {
46
+        "args": ["-o", "gitea.exe", "\"${workspaceRoot}\\main.go\""]
47
+      },
48
+      "problemMatcher": ["$go"]
49
+    }
50
+  ]
51
+}

+ 5 - 1
modules/setting/setting.go

@@ -500,7 +500,11 @@ func DateLang(lang string) string {
500 500
 
501 501
 // execPath returns the executable path.
502 502
 func execPath() (string, error) {
503
-	file, err := exec.LookPath(os.Args[0])
503
+	execFile := os.Args[0]
504
+	if IsWindows && filepath.IsAbs(execFile) {
505
+		return filepath.Clean(execFile), nil
506
+	}
507
+	file, err := exec.LookPath(execFile)
504 508
 	if err != nil {
505 509
 		return "", err
506 510
 	}