Learning about formatIO
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
Root cause:
|
||||
- ~/.local/share/nvim/mason/bin/gopls:1 reported expected 'package', found 'EOF' on any empty *.go (/tmp/empty.go:1:1). Valid files now show 0 diagnostics.
|
||||
- ~/gitclone/letsGO/*/go.mod:1 had invalid/mixed modules (main, main.go, hello v1.23.1-1.26.5) and no go.work — gopls couldn't resolve workspace.
|
||||
- ~/.config/nvim/lua/plugins/go.lua:8 used wrong plugin name "mason.nvim" (should be "mason-org/mason.nvim"), so ensure_installed never ran.
|
||||
@@ -0,0 +1,2 @@
|
||||
Fixes applied:
|
||||
1. ~/.config/nvim/lua/plugins/go.lua:1 — fixed mason name to mason-org/mason.nvim, ensure_installed = { "gopls","gofumpt","goimports","golangci-lint","delve" }, kept nvim-treesitter for go/gomod/gowork/gosum, tuned gopls (gofumpt=true, staticcheck, completeUnimported). Relies on lazyvim.plugins.extras.lang.go in ~/.config/nvim/lazyvim.json:3.
|
||||
@@ -0,0 +1,4 @@
|
||||
Verified:
|
||||
- ~/.local/share/nvim/mason/bin/gopls version v0.23.0, go vet OK for all 7 modules
|
||||
- nvim --headless edit formatIO/main.go → 0 diagnostics (was EOF on empty)
|
||||
- nvim --headless edit /tmp/should_show_eof.go (empty) → 1 diag expected 'package', found 'EOF' — expected, template will prevent.
|
||||
@@ -0,0 +1,3 @@
|
||||
module letsgo/formatio
|
||||
|
||||
go 1.27
|
||||
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var tlc, tcc, twc int
|
||||
for _, fname := range os.Args[1:] {
|
||||
|
||||
var lc, cc, wc int
|
||||
file, err := os.Open(fname)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
continue
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scan := bufio.NewScanner(file)
|
||||
for scan.Scan() {
|
||||
s := scan.Text()
|
||||
|
||||
wc += len(strings.Fields(s))
|
||||
cc += len(s)
|
||||
lc++
|
||||
}
|
||||
tlc += lc
|
||||
tcc += cc
|
||||
twc += wc
|
||||
if err := scan.Err(); err != nil {
|
||||
fmt.Printf("Invalid Input: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("%5d %5d %5d %s\n", lc, cc, wc, fname)
|
||||
}
|
||||
fmt.Printf("%5d %5d %5d %s\n", tlc, tcc, twc, "total")
|
||||
}
|
||||
Reference in New Issue
Block a user