Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/languageserver: Log path & version at startup #1326

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cmd/languageserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"

"github.com/spf13/cobra"

"github.com/styrainc/regal/internal/lsp"
"github.com/styrainc/regal/internal/lsp/log"
"github.com/styrainc/regal/pkg/version"
)

func init() {
Expand All @@ -25,6 +27,23 @@ func init() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

exe, err := os.Executable()
if err != nil {
fmt.Fprintln(os.Stderr, "error getting executable:", err)
} else {
absPath, err := filepath.Abs(exe)
if err != nil {
fmt.Fprintln(os.Stderr, "error getting executable path:", err)
} else {
v := version.Version
if v == "" {
v = "Unknown"
}
Comment on lines +38 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know cmp.Or? We could write this as

Suggested change
v := version.Version
if v == "" {
v = "Unknown"
}
v := cmp.Or(version.Version, "Unknown")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nice! Had no idea that was a stdlib thing. I had already merged this but we could easily sprinkle that in lots of places I'm sure.


fmt.Fprintf(os.Stderr, "Regal Language Server (path: %s, version: %s)", absPath, v)
}
}

opts := &lsp.LanguageServerOptions{
LogWriter: os.Stderr,
LogLevel: log.LevelMessage,
Expand Down
Loading