MyGoland 首次提交:Go 轻量 IDE

- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲)
- 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表)
- 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记
- Git:状态着色、选择性暂存提交、pull/push、历史并排对比
- 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复
- 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈
- 设计文档与验证记录见 docs/plans/
This commit is contained in:
zerorigin committed 2026-11-04 16:37:05 +08:00
commit a80c0f886a
220 files changed
+20784

No files matched your search

+49
View File
@@ -0,0 +1,49 @@
// click <socket> <window> <x> <y>:在窗口坐标里点一下
package main
import (
"bufio"
"encoding/json"
"fmt"
"net"
"os"
"strconv"
)
func main() {
sock, win := os.Args[1], os.Args[2]
x, _ := strconv.ParseFloat(os.Args[3], 64)
y, _ := strconv.ParseFloat(os.Args[4], 64)
// 可选的第五个参数:left(默认)/ right / middle
button := "left"
if len(os.Args) > 5 {
button = os.Args[5]
}
id, _ := strconv.Atoi(win)
c, err := net.Dial("unix", sock)
if err != nil {
fmt.Println("连接失败:", err)
os.Exit(1)
}
defer c.Close()
enc := json.NewEncoder(c)
dec := json.NewDecoder(bufio.NewReader(c))
evs := []map[string]any{
{"type": "pointerMove", "x": x, "y": y},
{"type": "pointerDown", "x": x, "y": y, "button": button},
{"type": "pointerUp", "x": x, "y": y, "button": button},
}
if err := enc.Encode(map[string]any{"id": 1, "method": "input", "params": map[string]any{"window": id, "events": evs}}); err != nil {
fmt.Println("发送失败:", err)
os.Exit(1)
}
var resp struct {
Error any `json:"error"`
}
_ = dec.Decode(&resp)
if resp.Error != nil {
fmt.Printf("失败: %+v\n", resp.Error)
return
}
fmt.Println("点击完成", x, y)
}
+44
View File
@@ -0,0 +1,44 @@
// keys <socket> <window> <key...>:发送按键(语法同菜单快捷键,如 CmdOrCtrl+P)
package main
import (
"bufio"
"encoding/json"
"fmt"
"net"
"os"
"strconv"
)
func main() {
sock, win := os.Args[1], os.Args[2]
id, _ := strconv.Atoi(win)
c, err := net.Dial("unix", sock)
if err != nil {
fmt.Println("连接失败:", err)
os.Exit(1)
}
defer c.Close()
enc := json.NewEncoder(c)
dec := json.NewDecoder(bufio.NewReader(c))
for _, k := range os.Args[3:] {
var evs []map[string]any
if len(k) > 5 && k[:5] == "text=" {
evs = []map[string]any{{"type": "text", "text": k[5:]}}
} else {
evs = []map[string]any{{"type": "keyDown", "key": k}, {"type": "keyUp", "key": k}}
}
if err := enc.Encode(map[string]any{"id": 1, "method": "input", "params": map[string]any{"window": id, "events": evs}}); err != nil {
fmt.Println("发送失败:", err)
os.Exit(1)
}
var resp struct {
Error any `json:"error"`
}
_ = dec.Decode(&resp)
if resp.Error != nil {
fmt.Printf("失败 %s: %+v\n", k, resp.Error)
}
}
fmt.Println("按键完成")
}
+34
View File
@@ -0,0 +1,34 @@
// menu <socket> <window> <path...>:点菜单项,路径如 编辑 快速打开文件
package main
import (
"bufio"
"encoding/json"
"fmt"
"net"
"os"
"strconv"
)
func main() {
sock, win := os.Args[1], os.Args[2]
id, _ := strconv.Atoi(win)
c, err := net.Dial("unix", sock)
if err != nil {
fmt.Println("连接失败:", err)
os.Exit(1)
}
defer c.Close()
enc := json.NewEncoder(c)
dec := json.NewDecoder(bufio.NewReader(c))
_ = enc.Encode(map[string]any{"id": 1, "method": "menu", "params": map[string]any{"window": id, "path": os.Args[3:]}})
var resp struct {
Error any `json:"error"`
}
_ = dec.Decode(&resp)
if resp.Error != nil {
fmt.Printf("失败: %+v\n", resp.Error)
return
}
fmt.Println("菜单已触发")
}
+76
View File
@@ -0,0 +1,76 @@
// 截取正在运行的 MyGoland 窗口,用于本地像素级验证。
package main
import (
"bufio"
"encoding/json"
"fmt"
"net"
"os"
)
type windowInfo struct {
ID int `json:"id"`
Title string `json:"title"`
}
func main() {
if len(os.Args) < 3 {
fmt.Println("用法: shot <socket> <out.png>")
os.Exit(2)
}
c, err := net.Dial("unix", os.Args[1])
if err != nil {
fmt.Println("连接失败:", err)
os.Exit(1)
}
defer c.Close()
enc := json.NewEncoder(c)
dec := json.NewDecoder(bufio.NewReader(c))
if err := enc.Encode(map[string]any{"id": 1, "method": "windows"}); err != nil {
fmt.Println("发送失败:", err)
os.Exit(1)
}
var wr struct {
Result struct {
Windows []windowInfo `json:"windows"`
} `json:"result"`
Error any `json:"error"`
}
if err := dec.Decode(&wr); err != nil {
fmt.Println("解析失败:", err)
os.Exit(1)
}
if len(wr.Result.Windows) == 0 {
fmt.Println("没有窗口")
os.Exit(1)
}
id := wr.Result.Windows[0].ID
if err := enc.Encode(map[string]any{"id": 2, "method": "capture", "params": map[string]any{"window": id}}); err != nil {
fmt.Println("发送失败:", err)
os.Exit(1)
}
var cr struct {
Result struct {
PNG []byte `json:"png"`
Width int `json:"width"`
Height int `json:"height"`
} `json:"result"`
Error any `json:"error"`
}
if err := dec.Decode(&cr); err != nil {
fmt.Println("解析失败:", err)
os.Exit(1)
}
if len(cr.Result.PNG) == 0 {
fmt.Printf("截图失败: %+v\n", cr.Error)
os.Exit(1)
}
if err := os.WriteFile(os.Args[2], cr.Result.PNG, 0o644); err != nil {
fmt.Println("写文件失败:", err)
os.Exit(1)
}
fmt.Printf("ok %dx%d -> %s\n", cr.Result.Width, cr.Result.Height, os.Args[2])
}
+82
View File
@@ -0,0 +1,82 @@
// 列出正在运行的 MyGoland 窗口的无障碍元素树,用于精确定位控件坐标。
//
// 有了它就不用再靠肉眼估坐标:按 Label 一查就知道按钮在哪。
// 用法: tree <socket> [筛选关键词]
package main
import (
"bufio"
"encoding/json"
"fmt"
"net"
"os"
"strings"
)
type node struct {
ID any `json:"id"`
Role string `json:"role"`
Label string `json:"label"`
Value string `json:"value"`
Bounds rect `json:"bounds"`
Actions []string `json:"actions"`
}
type rect struct {
X float32 `json:"x"`
Y float32 `json:"y"`
W float32 `json:"w"`
H float32 `json:"h"`
}
func (r rect) center() (float32, float32) {
return r.X + r.W/2, r.Y + r.H/2
}
func main() {
if len(os.Args) < 2 {
fmt.Println("用法: tree <socket> [关键词]")
os.Exit(2)
}
filter := ""
if len(os.Args) >= 3 {
filter = strings.ToLower(os.Args[2])
}
c, err := net.Dial("unix", os.Args[1])
if err != nil {
fmt.Println("连接失败:", err)
os.Exit(1)
}
defer c.Close()
enc := json.NewEncoder(c)
dec := json.NewDecoder(bufio.NewReader(c))
if err := enc.Encode(map[string]any{"id": 1, "method": "tree"}); err != nil {
fmt.Println("发送失败:", err)
os.Exit(1)
}
var res struct {
Result struct {
Nodes []node `json:"nodes"`
} `json:"result"`
Error any `json:"error"`
}
if err := dec.Decode(&res); err != nil {
fmt.Println("读取失败:", err)
os.Exit(1)
}
for _, n := range res.Result.Nodes {
text := n.Label
if text == "" {
text = n.Value
}
if filter != "" && !strings.Contains(strings.ToLower(text), filter) {
continue
}
cx, cy := n.Bounds.center()
fmt.Printf("%-10s %-14s %6.0f,%-6.0f %4.0fx%-4.0f %s\n",
n.Role, strings.Join(n.Actions, ","), cx, cy,
n.Bounds.W, n.Bounds.H, text)
}
}