Skip to content

Add format-on-save, health check system, and cursor visibility fix - #7

Open
lecheel wants to merge 3 commits into
wig-editor:masterfrom
lecheel:master
Open

Add format-on-save, health check system, and cursor visibility fix#7
lecheel wants to merge 3 commits into
wig-editor:masterfrom
lecheel:master

Conversation

@lecheel

@lecheel lecheel commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

there is issue for the end newline all the time i've using 'go fmt ' every commit
what do you think still using memory cat %s | goimports or simple the process

Format on Save – automatically formats the current buffer when saving.
Health Check System – validates dependencies and environment, with a new CLI flag and editor command.
Cursor Visibility Fix – corrects the clamping logic for cursor positioning to ensure symmetric context.
Together, these changes enhance developer experience, improve reliability, and fix a subtle UI bug.

diff --git a/commands/commands.go b/commands/commands.go
index 8375c1a..9927b3a 100644
--- a/commands/commands.go
+++ b/commands/commands.go
@@ -274,20 +274,19 @@ func CmdCurrentBufferDirFilePicker(ctx wig.Context) {
 
 func CmdFormatBuffer(ctx wig.Context) {
     if strings.HasSuffix(ctx.Buf.FilePath, ".go") {
-        formatcmd := fmt.Sprintf("cat %s | goimports", ctx.Buf.FilePath)
-        cmd := exec.Command("bash", "-c", formatcmd)
-        stdout, err := cmd.Output()
+        var cmd *exec.Cmd
+        if _, err := exec.LookPath("goimports"); err == nil {
+            cmd = exec.Command("goimports", "-w", ctx.Buf.FilePath)
+        } else {
+            cmd = exec.Command("go", "fmt", ctx.Buf.FilePath)
+        }
+        stdout, err := cmd.CombinedOutput()
         if err != nil {
-            ctx.Editor.LogMessage(err.Error())
+            ctx.Editor.LogError(err)
             ctx.Editor.LogMessage(string(stdout))
             return
         }
-        // TODO: update only changed lines
-        ctx.Buf.ResetLines()
-        lines := strings.Split(string(stdout), "\n")
-        for _, line := range lines {
-            ctx.Buf.Append(line)
-        }
+        CmdReloadBuffer(ctx)
    }

- Correct bottom clamp offset to ensure symmetric context
- Remove trailing newlines across multiple files
- Implement dependency and environment verification
- Add `--health` CLI flag and `:checkhealth` command
- Add syntax highlighting for health report buffer
- Refactor Go formatting to use `goimports` or `go fmt` directly
- Add `FormatOnSave` to editor configuration
- Trigger `CmdFormatBuffer` during file save process
- Update LSP and highlighter states after formatting
@firstrow

Copy link
Copy Markdown
Collaborator

I can not find commands.PrintCLIHealth()

@lecheel

lecheel commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author
image

@firstrow

Copy link
Copy Markdown
Collaborator

🤦 github decided to not load health.go diff. thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants