✨ feat(vscode): PyCharm 启动命令可配置(支持 ~/绝对路径),抽 expandTilde 复用
GUI 启动的 VS Code 扩展进程 PATH 常不含 JetBrains 启动器,裸 pycharm 易 ENOENT。 新增设置 pycharmCommand(默认 pycharm),贯穿 store/settings handler/messages/ KanbanPanel 与 webview,「钩子」分组在选 PyCharm 时显示「PyCharm 启动命令」输入框。 handleOpenWorktree 用该命令并经 expandTilde 展开 ~。expandTilde 从 resolveWorktreePath 抽出共用。 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cacc60eb0e
commit
02b0aca891
10 files changed
+84
-9
No files matched your search
@@ -4,7 +4,7 @@ import { execFile } from 'node:child_process'
|
||||
import { commands, Uri, window, workspace } from 'vscode'
|
||||
import { getToken } from '../../auth/secrets'
|
||||
import { detectRepo } from '../../git/remote'
|
||||
import { resolveWorktreePath } from '../../git/worktree'
|
||||
import { expandTilde, resolveWorktreePath } from '../../git/worktree'
|
||||
import {
|
||||
runImplTabPostCloseHook,
|
||||
runImplTabPreCreateHook,
|
||||
@@ -32,13 +32,16 @@ export async function handleOpenWorktree(panel: KanbanWebviewPanel, relPath: str
|
||||
|
||||
// PyCharm 分支用 JetBrains 启动器打开目录。错误在回调里自行处理,不要落进
|
||||
// 下面 openFolder 的 catch。
|
||||
const { worktreeOpenWith } = getSettings(panel.context)
|
||||
const { worktreeOpenWith, pycharmCommand } = getSettings(panel.context)
|
||||
if (worktreeOpenWith === 'pycharm') {
|
||||
execFile('pycharm', [abs], (err) => {
|
||||
// GUI 启动的 VS Code 进程 PATH 常不含 JetBrains 启动器,故命令可配置;
|
||||
// 允许填 `~`/绝对路径,execFile 不走 shell,`~` 需自己展开。
|
||||
const cmd = expandTilde(pycharmCommand)
|
||||
execFile(cmd, [abs], (err) => {
|
||||
if (err) {
|
||||
const code = (err as NodeJS.ErrnoException).code ?? 'unknown'
|
||||
const message = code === 'ENOENT'
|
||||
? '找不到 pycharm 命令,请在 JetBrains Toolbox 里启用命令行启动器或把 pycharm 加入 PATH'
|
||||
? `找不到 ${cmd} 命令,请在「PyCharm 启动命令」里填启动器的完整路径,或确保它在 PATH 中`
|
||||
: err.message
|
||||
void window.showErrorMessage(`用 PyCharm 打开失败: ${message}`)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user