- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲) - 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表) - 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记 - Git:状态着色、选择性暂存提交、pull/push、历史并排对比 - 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复 - 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈 - 设计文档与验证记录见 docs/plans/
76 lines
1.7 KiB
Go
76 lines
1.7 KiB
Go
package app
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
)
|
|
|
|
// openFromArgs 处理启动时的命令行参数。
|
|
//
|
|
// 第一个参数可能是目录(当工作区)也可能是文件(当要打开的文件);
|
|
// 文件则用它所在的目录当工作区。
|
|
func (a *App) openFromArgs(args []string) {
|
|
if len(args) == 0 {
|
|
if last := lastWorkspace(); last != "" {
|
|
a.setRoot(last)
|
|
}
|
|
return
|
|
}
|
|
first := args[0]
|
|
if st, err := os.Stat(first); err == nil && !st.IsDir() {
|
|
a.setRoot(filepath.Dir(first))
|
|
a.OpenFile(first)
|
|
return
|
|
}
|
|
a.setRoot(first)
|
|
if len(args) > 1 {
|
|
a.OpenFile(args[1])
|
|
}
|
|
}
|
|
|
|
// secondInstance 处理「又一个 MyGoland 被启动」:把窗口叫到前台,
|
|
// 并按对方传来的参数打开文件或工作区。
|
|
func (a *App) secondInstance(args []string, wd string) {
|
|
if a.win == nil {
|
|
return
|
|
}
|
|
a.win.Show()
|
|
a.win.Focus()
|
|
|
|
for _, arg := range args {
|
|
// 相对路径按对方的当前目录解析。
|
|
p := arg
|
|
if !filepath.IsAbs(p) {
|
|
p = filepath.Join(wd, p)
|
|
}
|
|
st, err := os.Stat(p)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if st.IsDir() {
|
|
dir := p
|
|
a.win.Update(func() { a.setRoot(dir) })
|
|
continue
|
|
}
|
|
file := p
|
|
a.win.Update(func() {
|
|
// 文件不在当前工作区里,连工作区一起换过去。
|
|
if a.root == "" || !within(a.root, file) {
|
|
a.setRoot(filepath.Dir(file))
|
|
}
|
|
go a.OpenFile(file)
|
|
})
|
|
}
|
|
}
|
|
|
|
// within 判断 path 是否在 root 之下(忽略大小写,Windows 路径习惯)。
|
|
func within(root, path string) bool {
|
|
r := strings.ToLower(filepath.Clean(root))
|
|
p := strings.ToLower(filepath.Clean(path))
|
|
if r == p {
|
|
return true
|
|
}
|
|
return strings.HasPrefix(p, r+string(filepath.Separator))
|
|
}
|