Skip to content

Commit

Permalink
Properly embed version information
Browse files Browse the repository at this point in the history
  • Loading branch information
netmute committed Nov 22, 2024
1 parent 4680801 commit 5668133
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ builds:
- amd64
- arm64
ldflags:
- -s -w -X main.version={{ .Version }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }}
- -s -w -X main.version={{ .Version }}

archives:
- format: tar.gz
Expand Down
37 changes: 3 additions & 34 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"path/filepath"
"regexp"
"runtime"
"runtime/debug"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -228,6 +227,8 @@ func checkCtagsInstallation() error {
return nil
}

var version = "unknown" // Populated with -X main.version

// Main Function
func main() {
config := parseFlags()
Expand All @@ -244,8 +245,7 @@ func main() {
}

if config.showVersion {
version, commitHash := getVersionInfo()
fmt.Printf("CTags Language Server version %s (commit %s)\n", version, commitHash)
fmt.Printf("CTags Language Server version %s\n", version)
os.Exit(0)
}

Expand Down Expand Up @@ -329,37 +329,6 @@ Options:
`, os.Args[0])
}

func getVersionInfo() (version, commitHash string) {
buildInfo, ok := debug.ReadBuildInfo()
if !ok || buildInfo == nil {
return "unknown", "unknown"
}

version = buildInfo.Main.Version

var revision, modified string
for _, setting := range buildInfo.Settings {
switch setting.Key {
case "vcs.revision":
revision = setting.Value
case "vcs.modified":
modified = setting.Value
}
}

if len(revision) >= 7 {
commitHash = revision[:7]
} else {
commitHash = revision
}

if modified == "true" {
commitHash += "-dirty"
}

return version, commitHash
}

// handleRequest routes JSON-RPC requests to appropriate handlers
func handleRequest(server *Server, req RPCRequest) {
switch req.Method {
Expand Down

0 comments on commit 5668133

Please sign in to comment.