Skip to content

Commit 4c2b1be

Browse files
lafrikslunny
authored andcommitted
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
1 parent 8c3a2e8 commit 4c2b1be

File tree

6 files changed

+105
-1
lines changed

6 files changed

+105
-1
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ _test
1010
# IntelliJ
1111
.idea
1212

13+
# MS VSCode
14+
.vscode
15+
1316
# Architecture specific extensions/prefixes
1417
*.[568vq]
1518
[568vq].out
@@ -36,6 +39,7 @@ _testmain.go
3639
*.log
3740

3841
/gitea
42+
/debug
3943
/integrations.test
4044

4145
/bin

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ It assumes you have followed the
2626
Sensitive security-related issues should be reported to
2727
2828

29+
For configuring IDE or code editor to develop Gitea see [IDE and code editor configuration](contrib/ide/)
30+
2931
## Bug reports
3032

3133
Please search the issues on the issue tracker with a variety of keywords

contrib/ide/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

contrib/ide/vscode/launch.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

contrib/ide/vscode/tasks.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
}

modules/setting/setting.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,11 @@ func DateLang(lang string) string {
500500

501501
// execPath returns the executable path.
502502
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)
504508
if err != nil {
505509
return "", err
506510
}

0 commit comments

Comments
 (0)