From f6c651f9e7446e453acc71c25f19fd8d533f9365 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Mon, 16 Sep 2024 09:59:26 +0200 Subject: [PATCH 1/4] Upgrade goInfo to v0.1.0-wakatime.9 for Windows platform detection --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 7195f9ad..4d75703e 100644 --- a/go.mod +++ b/go.mod @@ -57,4 +57,4 @@ require ( replace github.com/alecthomas/chroma/v2 => github.com/gandarez/chroma/v2 v2.9.1-wakatime.1 -replace github.com/matishsiao/goInfo => github.com/wakatime/goInfo v0.1.0-wakatime.8 +replace github.com/matishsiao/goInfo => github.com/wakatime/goInfo v0.1.0-wakatime.9 diff --git a/go.sum b/go.sum index a3d6fc8f..8fa79d49 100644 --- a/go.sum +++ b/go.sum @@ -270,6 +270,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8 github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= github.com/wakatime/goInfo v0.1.0-wakatime.8 h1:MgyeRnCkynEmUxLKXnYUAP5Dd+vhKxhqg6Nx1PdAZy4= github.com/wakatime/goInfo v0.1.0-wakatime.8/go.mod h1:aEt7p9Rvh67BYApmZwNDPpgircTO2kgdmDUoF/1QmwA= +github.com/wakatime/goInfo v0.1.0-wakatime.9 h1:QkFBcdCcUwFb2CxacFdt4I4aVPcJRY7nXh0sq1gqu3o= +github.com/wakatime/goInfo v0.1.0-wakatime.9/go.mod h1:aEt7p9Rvh67BYApmZwNDPpgircTO2kgdmDUoF/1QmwA= github.com/yookoala/realpath v1.0.0 h1:7OA9pj4FZd+oZDsyvXWQvjn5oBdcHRTV44PpdMSuImQ= github.com/yookoala/realpath v1.0.0/go.mod h1:gJJMA9wuX7AcqLy1+ffPatSCySA1FQ2S8Ya9AIoYBpE= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= From 7acb0a91f38ef3c1b97fd684cbe541ee5fe98b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= Date: Mon, 16 Sep 2024 17:13:47 -0300 Subject: [PATCH 2/4] Bump Chroma to v2.10.0 --- go.mod | 7 ++++--- go.sum | 8 ++++---- pkg/deps/java.go | 6 +++--- pkg/heartbeat/language.go | 14 ++++++++++++++ pkg/heartbeat/language_test.go | 2 ++ 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 4d75703e..6ff11ba1 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22.5 require ( github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 github.com/alecthomas/assert v1.0.0 - github.com/alecthomas/chroma/v2 v2.9.1 + github.com/alecthomas/chroma/v2 v2.10.0 github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964 github.com/dlclark/regexp2 v1.10.0 github.com/gandarez/go-olson-timezone v0.1.0 @@ -30,7 +30,7 @@ require ( require ( github.com/alecthomas/colour v0.1.0 // indirect - github.com/alecthomas/repr v0.2.0 // indirect + github.com/alecthomas/repr v0.3.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/fsnotify/fsnotify v1.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect @@ -55,6 +55,7 @@ require ( gopkg.in/yaml.v3 v3.0.1 // indirect ) -replace github.com/alecthomas/chroma/v2 => github.com/gandarez/chroma/v2 v2.9.1-wakatime.1 +// replace github.com/alecthomas/chroma/v2 => github.com/gandarez/chroma/v2 v2.9.1-wakatime.1 +// replace github.com/alecthomas/chroma/v2 => /Users/gandarez/development/git/gandarez/chroma replace github.com/matishsiao/goInfo => github.com/wakatime/goInfo v0.1.0-wakatime.9 diff --git a/go.sum b/go.sum index 8fa79d49..aa425f6b 100644 --- a/go.sum +++ b/go.sum @@ -44,10 +44,12 @@ github.com/alecthomas/assert v1.0.0 h1:3XmGh/PSuLzDbK3W2gUbRXwgW5lqPkuqvRgeQ30FI github.com/alecthomas/assert v1.0.0/go.mod h1:va/d2JC+M7F6s+80kl/R3G7FUiW6JzUO+hPhLyJ36ZY= github.com/alecthomas/assert/v2 v2.2.1 h1:XivOgYcduV98QCahG8T5XTezV5bylXe+lBxLG2K2ink= github.com/alecthomas/assert/v2 v2.2.1/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ= +github.com/alecthomas/chroma/v2 v2.10.0 h1:T2iQOCCt4pRmRMfL55gTodMtc7cU0y7lc1Jb8/mK/64= +github.com/alecthomas/chroma/v2 v2.10.0/go.mod h1:4TQu7gdfuPjSh76j78ietmqh9LiurGF0EpseFXdKMBw= github.com/alecthomas/colour v0.1.0 h1:nOE9rJm6dsZ66RGWYSFrXw461ZIt9A6+nHgL7FRrDUk= github.com/alecthomas/colour v0.1.0/go.mod h1:QO9JBoKquHd+jz9nshCh40fOfO+JzsoXy8qTHF68zU0= -github.com/alecthomas/repr v0.2.0 h1:HAzS41CIzNW5syS8Mf9UwXhNH1J9aix/BvDRf1Ml2Yk= -github.com/alecthomas/repr v0.2.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/alecthomas/repr v0.3.0 h1:NeYzUPfjjlqHY4KtzgKJiWd6sVq2eNUPTi34PiFGjY8= +github.com/alecthomas/repr v0.3.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= @@ -75,8 +77,6 @@ github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0X github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY= github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw= -github.com/gandarez/chroma/v2 v2.9.1-wakatime.1 h1:czvEuO+JRT4y2HTTh0REP0p0ebfleH6eY70UI0WF4OQ= -github.com/gandarez/chroma/v2 v2.9.1-wakatime.1/go.mod h1:4TQu7gdfuPjSh76j78ietmqh9LiurGF0EpseFXdKMBw= github.com/gandarez/go-olson-timezone v0.1.0 h1:cDRlHKQE0uC3mJNZyKoQIpAuvQtV8KXwIVj8bDEEyuo= github.com/gandarez/go-olson-timezone v0.1.0/go.mod h1:+yV/cYNjgs2JqdGShznAD4R13r8lKMGR2XlWAJqa5Yo= github.com/gandarez/go-realpath v1.0.0 h1:fhQBRDshH/MZNmDLWM9vbBameK2fxyLr+ctqkRwbHEU= diff --git a/pkg/deps/java.go b/pkg/deps/java.go index 12b05f3b..dc1f13fe 100644 --- a/pkg/deps/java.go +++ b/pkg/deps/java.go @@ -102,8 +102,8 @@ func (p *ParserJava) processToken(token chroma.Token) { p.processNameAttribute(token.Value) case chroma.NameNamespace: p.processNameNamespace(token.Value) - case chroma.Operator: - p.processOperator(token.Value) + case chroma.Punctuation: + p.processPunctuation(token.Value) } } @@ -170,7 +170,7 @@ func (p *ParserJava) processNameNamespace(value string) { } } -func (p *ParserJava) processOperator(value string) { +func (p *ParserJava) processPunctuation(value string) { if value == ";" { p.State = StateJavaImportFinished p.processKeywordNamespace(p.Buffer) diff --git a/pkg/heartbeat/language.go b/pkg/heartbeat/language.go index 7d586992..04487846 100644 --- a/pkg/heartbeat/language.go +++ b/pkg/heartbeat/language.go @@ -319,6 +319,8 @@ const ( LanguageCSV // LanguageCUDA represents the CUDA programming language. LanguageCUDA + // LanguageCUE represents the CUE programming language. + LanguageCUE // LanguagecURLConfig represents the cURLConfig programming language. LanguagecURLConfig // LanguageCVS represents the CVS programming language. @@ -1061,6 +1063,8 @@ const ( LanguagePromQL // LanguageProtocolBuffer represents the ProtocolBuffer programming language. LanguageProtocolBuffer + // LanguagePRQL represents the PRQL programming language. + LanguagePRQL // LanguagePSL represents the Property Specification Language programming language. LanguagePSL // LanguagePsyShPHP represents the PHPPsySH programming language. @@ -1728,6 +1732,7 @@ const ( languageCSSStr = "CSS" languageCSVStr = "CSV" languageCUDAStr = "Cuda" + languageCUEStr = "CUE" languagecURLConfigStr = "cURL Config" languageCVSStr = "CVS" languageCWebStr = "CWeb" @@ -2098,6 +2103,7 @@ const ( languagePrologStr = "Prolog" languagePromQLStr = "PromQL" languageProtocolBufferStr = "Protocol Buffer" + languagePRQLStr = "PRQL" languagePSLStr = "Property Specification Language" languagePsyShPHPStr = "PsySH console session for PHP" languagePugStr = "Pug" @@ -2723,6 +2729,8 @@ func ParseLanguage(s string) (Language, bool) { return LanguageCSV, true case normalizeString(languageCUDAStr): return LanguageCUDA, true + case normalizeString(languageCUEStr): + return LanguageCUE, true case normalizeString(languagecURLConfigStr): return LanguagecURLConfig, true case normalizeString(languageCVSStr): @@ -3463,6 +3471,8 @@ func ParseLanguage(s string) (Language, bool) { return LanguagePromQL, true case normalizeString(languageProtocolBufferStr): return LanguageProtocolBuffer, true + case normalizeString(languagePRQLStr): + return LanguagePRQL, true case normalizeString(languagePSLStr): return LanguagePSL, true case normalizeString(languagePsyShPHPStr): @@ -4411,6 +4421,8 @@ func (l Language) String() string { return languageCSVStr case LanguageCUDA: return languageCUDAStr + case LanguageCUE: + return languageCUEStr case LanguagecURLConfig: return languagecURLConfigStr case LanguageCVS: @@ -5149,6 +5161,8 @@ func (l Language) String() string { return languagePromQLStr case LanguageProtocolBuffer: return languageProtocolBufferStr + case LanguagePRQL: + return languagePRQLStr case LanguagePsyShPHP: return languagePsyShPHPStr case LanguagePug: diff --git a/pkg/heartbeat/language_test.go b/pkg/heartbeat/language_test.go index 226f2314..bba94067 100644 --- a/pkg/heartbeat/language_test.go +++ b/pkg/heartbeat/language_test.go @@ -168,6 +168,7 @@ func languageTests() map[string]heartbeat.Language { "CSS": heartbeat.LanguageCSS, "CSV": heartbeat.LanguageCSV, "Cuda": heartbeat.LanguageCUDA, + "CUE": heartbeat.LanguageCUE, "cURL Config": heartbeat.LanguagecURLConfig, "CVS": heartbeat.LanguageCVS, "CWeb": heartbeat.LanguageCWeb, @@ -537,6 +538,7 @@ func languageTests() map[string]heartbeat.Language { "PromQL": heartbeat.LanguagePromQL, "Property Specification Language": heartbeat.LanguagePSL, "Protocol Buffer": heartbeat.LanguageProtocolBuffer, + "PRQL": heartbeat.LanguagePRQL, "PsySH console session for PHP": heartbeat.LanguagePsyShPHP, "Pug": heartbeat.LanguagePug, "Puppet": heartbeat.LanguagePuppet, From dcf9a724c63d1d494414149ddcfbc6261cd250d9 Mon Sep 17 00:00:00 2001 From: Alan Hamlett Date: Tue, 17 Sep 2024 11:23:23 +0200 Subject: [PATCH 3/4] Prevent race condition when Windows tests reading same config file --- cmd/heartbeat/heartbeat_test.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/heartbeat/heartbeat_test.go b/cmd/heartbeat/heartbeat_test.go index b3acf85a..a84dc982 100644 --- a/cmd/heartbeat/heartbeat_test.go +++ b/cmd/heartbeat/heartbeat_test.go @@ -48,6 +48,9 @@ func TestSendHeartbeats(t *testing.T) { projectFolder, err := filepath.Abs("../..") require.NoError(t, err) + tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime-config") + require.NoError(t, err) + subfolders := project.CountSlashesInProjectFolder(projectFolder) router.HandleFunc("/users/current/heartbeats.bulk", func(w http.ResponseWriter, req *http.Request) { @@ -96,6 +99,7 @@ func TestSendHeartbeats(t *testing.T) { v := viper.New() v.SetDefault("sync-offline-activity", 1000) v.Set("api-url", testServerURL) + v.Set("config", tmpFile.Name()) v.Set("category", "debugging") v.Set("cursorpos", 42) v.Set("entity", "testdata/main.go") @@ -122,6 +126,10 @@ func TestSendHeartbeats(t *testing.T) { } func TestSendHeartbeats_RateLimited(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("Skipping because OS is windows.") + } + resetSingleton(t) testServerURL, router, tearDown := setupTestServer() @@ -137,7 +145,10 @@ func TestSendHeartbeats_RateLimited(t *testing.T) { numCalls++ }) - tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime-internal-config") + tmpFile, err := os.CreateTemp(t.TempDir(), "wakatime-config") + require.NoError(t, err) + + tmpFileInternal, err := os.CreateTemp(t.TempDir(), "wakatime-internal-config") require.NoError(t, err) offlineQueueFile, err := os.CreateTemp(t.TempDir(), "offline-queue-file") @@ -162,7 +173,8 @@ func TestSendHeartbeats_RateLimited(t *testing.T) { v.Set("timeout", 5) v.Set("write", true) v.Set("heartbeat-rate-limit-seconds", 500) - v.Set("internal-config", tmpFile.Name()) + v.Set("config", tmpFile.Name()) + v.Set("internal-config", tmpFileInternal.Name()) v.Set("offline-queue-file", offlineQueueFile.Name()) v.Set("internal.heartbeats_last_sent_at", time.Now().Add(-time.Minute).Format(time.RFC3339)) @@ -1189,13 +1201,18 @@ func TestResetRateLimit(t *testing.T) { defer tmpFile.Close() + tmpFileInternal, err := os.CreateTemp(t.TempDir(), "wakatime-internal") + require.NoError(t, err) + + defer tmpFileInternal.Close() + v := viper.New() - v.Set("config", tmpFile.Name()) - v.Set("internal-config", tmpFile.Name()) + v.Set("config", tmpFileInternal.Name()) + v.Set("internal-config", tmpFileInternal.Name()) writer, err := ini.NewWriter(v, func(vp *viper.Viper) (string, error) { assert.Equal(t, v, vp) - return tmpFile.Name(), nil + return tmpFileInternal.Name(), nil }) require.NoError(t, err) From c17fc7284d62ffbe1661f97fe3605f83e77df0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Guard=C3=A3o=20Gandarez?= Date: Mon, 16 Sep 2024 15:33:19 -0300 Subject: [PATCH 4/4] Improve docs for project map usage --- USAGE.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/USAGE.md b/USAGE.md index 30dfe773..2722b1e0 100644 --- a/USAGE.md +++ b/USAGE.md @@ -116,7 +116,7 @@ some/submodule/name = new project name ### Project Map Section -A key value pair list separated by new line. Use when a project should be renamed to another when sent to the API. +A key value pair list separated by new line, where the value before equal sign is the regex pattern and the latter is the override project name. Use when a project should be renamed to another when sent to the API. The order of the project map is important, the first match is used. Do not add any leading space before the regex pattern. ```ini [projectmap] @@ -126,7 +126,7 @@ projects/foo = new project name ### Project Api Key Section -A key value pair list separated by new line. Use when a project should be sent using another api key other than the default on `settings.api_key`. +A key value pair list separated by new line, where the value before equal sign is the regex pattern and the latter is the override api key. Use when a project should be sent using another api key other than the default on `settings.api_key`. The order of the project api key is important, the first match is used. Do not add any leading space before the regex pattern. ```ini [project_api_key] @@ -148,7 +148,7 @@ However, if an api key exists in your `~/.wakatime.cfg` file then it takes prece ### Git Submodule Project Map Section -A key value pair list separated by new line. Use when a submodule project should be renamed to another when sent to the API. +A key value pair list separated by new line, where the value before equal sign is the regex pattern and the latter is the override project name for submodule. Use when a submodule project should be renamed to another when sent to the API. The order of the git submodule project map is important, the first match is used. Do not add any leading space before the regex pattern. ```ini [git_submodule_projectmap]