Skip to content

Commit

Permalink
build: improve developer experience for VS Code users
Browse files Browse the repository at this point in the history
  • Loading branch information
robertrossmann committed Mar 7, 2024
1 parent cdbbef8 commit 75103c2
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 3 deletions.
15 changes: 15 additions & 0 deletions .github/matchers/golangci-lint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"problemMatcher": [
{
"owner": "golangci-lint",
"pattern": {
"regexp": "^(.+\\.go):(\\d+):(\\d+): \\w+: (.+) \\((\\w+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
}
}
]
}
18 changes: 18 additions & 0 deletions .github/matchers/testify.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "github.com/stretchr/testify/assert",
"pattern": [
{
"regexp": "^\\s+Error Trace:\\s+(.+):(\\d+)$",
"file": 1,
"line": 2
},
{
"regexp": "^\\s+Error:\\s+(.+)(?=:?)",
"message": 1
}
]
}
]
}
4 changes: 4 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
with:
go-version-file: go.mod
- run: go version
- run: echo "::add-matcher::.github/matchers/golangci-lint.json"

- run: make lint

test:
Expand All @@ -32,6 +34,8 @@ jobs:
with:
go-version-file: go.mod
- run: go version
- run: echo "::add-matcher::.github/matchers/testify.json"

- run: make test
- name: Upload coverage reports to Codecov
if: success()
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"editorconfig.editorconfig",
"github.vscode-github-actions",
"github.vscode-pull-request-github",
"golang.go"
]
}
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"task.allowAutomaticTasks": "off",
"window.title": "go.strv.io/background${separator}${activeEditorShort}",
"go.lintTool": "golangci-lint",
"go.testTimeout": "5s",
"go.useLanguageServer": true,
"gopls": {
"ui.semanticTokens": true,
},
}
101 changes: 101 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "make: test",
"detail": "Run the test suite",
"type": "process",
"command": "make",
"args": [
"test"
],
"problemMatcher": {
"owner": "github.com/stretchr/testify/assert",
"applyTo": "allDocuments",
"fileLocation": [
"absolute"
],
"pattern": [
{
"regexp": "^\\s+Error Trace:\\s+(.+):(\\d+)$",
"file": 1,
"line": 2
},
// This is extremely rudimentary because VS Code does not support matching the message across multiple lines
// so this only shows the error but does not show the expected and actual values in the UI 🤦‍♂️
{
"regexp": "^\\s+Error:\\s+(.+)(?=:?)",
"message": 1
}
]
},
"isTestCommand": true,
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"clear": true
},
"icon": {
"id": "beaker",
"color": "terminal.ansiGreen"
}
},
{
"label": "make: lint",
"detail": "Run the linter using Docker (golangci-lint)",
"type": "process",
"command": "make",
"args": [
"lint"
],
"problemMatcher": {
"owner": "golangci-lint",
"applyTo": "allDocuments",
"fileLocation": [
"relative",
"${workspaceFolder}"
],
"pattern": {
"regexp": "^(.+\\.go):(\\d+):(\\d+): \\w+: (.+) \\((\\w+)\\)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4,
"code": 5
},
},
"group": {
"kind": "test",
"isDefault": false
},
"presentation": {
"clear": true,
},
"icon": {
"id": "eye",
"color": "terminal.ansiYellow"
}
},
{
"label": "make: clean",
"detail": "Remove compiled and generated files or caches",
"type": "process",
"command": "make",
"args": [
"clean"
],
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
"clear": true,
"close": true
},
"icon": {
"id": "trash",
"color": "terminal.ansiRed"
}
}
],
}
3 changes: 1 addition & 2 deletions background.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,11 @@ func (m *Manager) Cancel() {
// Close is a convenience method that calls Wait() and Cancel() in parallel. It blocks until all tasks have finished.
func (m *Manager) Close() {
var wg sync.WaitGroup
wg.Add(1)
wg.Add(2)
go func() {
m.Wait()
wg.Done()
}()
wg.Add(1)
go func() {
m.Cancel()
wg.Done()
Expand Down
2 changes: 1 addition & 1 deletion background_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func Test_NewManager(t *testing.T) {
m := background.NewManager()
assert.NotNil(t, m)
assert.IsType(t, &background.Manager{}, m)
assert.IsType(t, background.Manager{}, m)

Check failure on line 18 in background_test.go

View workflow job for this annotation

GitHub Actions / test

Object expected to be of type background.Manager, but was *background.Manager
assert.EqualValues(t, 0, m.CountOf(background.TaskTypeOneOff))
assert.EqualValues(t, 0, m.CountOf(background.TaskTypeLoop))
}
Expand Down
1 change: 1 addition & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ test: force

clean:
rm -rf .cache
rm coverage.txt

.PHONY: force

0 comments on commit 75103c2

Please sign in to comment.