From 3d76b1bcde5a29aee1a7202a24fef702275f64d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 5 Jan 2026 10:42:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=9C=A8IDE=E4=B8=AD=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E7=9A=84=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.go | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/project.go b/project.go index 4799352..34ab169 100644 --- a/project.go +++ b/project.go @@ -36,8 +36,8 @@ func (p *project) GetFileSystemSeparator() string { // BuildPath 构建路径 func (p *project) BuildPath(filePathList ...string) string { projectRootPath, _ := p.GetExecutablePath() - if p.IsRunningWithGoRun() { - // go run 运行, 则工作目录为项目目录 + if p.IsRunningWithGoRun() || p.IsInIDE() { + // go run 运行 或 者 ide 中运行, 则工作目录为项目目录 projectRootPath = p.GetWorkDir() } if len(filePathList) == 0 { @@ -98,3 +98,34 @@ func (p *project) IsRunningWithGoRun() bool { return false } + +// IsInIDE 检查当前程序是否在IDE中运行 +func (p *project) IsInIDE() bool { + // 检查常见的 IDE环境变量 + ideEnvVars := []string{ + "PYCHARM_HOSTED", // PyCharm + "IDEA_INITIAL_DIRECTORY", // IntelliJ IDEA + "VSCODE_PID", // VS Code + "GOLAND", // GoLand + "PHPSTORM", // PhpStorm + } + + for _, env := range ideEnvVars { + if os.Getenv(env) != "" { + return true + } + } + + // 检查父进程 + parentProcess := os.Getenv("_") + if parentProcess != "" { + ideProcesses := []string{"goland", "idea", "pycharm", "vscode", "code"} + for _, ide := range ideProcesses { + if strings.Contains(strings.ToLower(parentProcess), ide) { + return true + } + } + } + + return false +}