From 9651b720127fb726f7bc1d9ddfd0b3b90ea9ca27 Mon Sep 17 00:00:00 2001 From: Thomas-Vos00 Date: Wed, 19 Mar 2025 15:37:14 +0100 Subject: [PATCH 1/3] feat: add open-in-pycharm --- .gitignore | 1 + README.md | 27 ++++++++++++++++-------- package.json | 34 ++++++++++++++++++++++++------ pycharm-logo.svg | 19 +++++++++++++++++ src/extension.ts | 55 +++++++++++++++++++++++++++++++++++++++--------- 5 files changed, 111 insertions(+), 25 deletions(-) create mode 100644 pycharm-logo.svg diff --git a/.gitignore b/.gitignore index 0b60dfa..51703fe 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dist node_modules .vscode-test/ *.vsix +.idea \ No newline at end of file diff --git a/README.md b/README.md index efe8937..0e0ac2b 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,14 @@ # Open in PhpStorm -A VS Code/Cursor extension that allows you to quickly open files and projects in PhpStorm directly from your editor. +A VS Code/Cursor extension that allows you to quickly open files and projects in PhpStorm and PyCharm Community Edition directly from your editor. ## Features -- Open files and folders in PhpStorm with a single click +- Open files and folders in PhpStorm or PyCharm Community Edition with a single click +- File extension to IDE mapping - Context menu integration in VS Code/Cursor's file explorer - Command palette support -- Maintains your current workspace organization while leveraging PhpStorm's powerful features +- Maintains your current workspace organization while leveraging your preferred IDE's powerful features ## Screenshots @@ -26,22 +27,30 @@ A VS Code/Cursor extension that allows you to quickly open files and projects in ## Requirements - Visual Studio Code or Cursor -- PhpStorm installed on your system +- PhpStorm and/or PyCharm Community Edition installed on your system ## Installation 1. Install the extension from the VS Code Marketplace -2. Ensure PhpStorm is installed on your system -3. (Optional) Configure the extension settings if PhpStorm is installed in a non-standard location +2. Ensure your preferred IDEs are installed on your system ## Usage -There are several ways to open files in PhpStorm: +There are several ways to open files in your preferred IDE: -1. Right-click on a file or folder in the VS Code/Cursor file explorer and select "Open in PhpStorm" -2. Use the command palette (Cmd/Ctrl + Shift + P) and search for "Open in PhpStorm" +1. Right-click on a file or folder in the VS Code/Cursor file explorer and select "Open in PhpStorm" or "Open in PyCharm Community Edition" +2. Use the command palette (Cmd/Ctrl + Shift + P) and search for "Open in PhpStorm" or "Open in PyCharm Community Edition" 3. Use the keyboard shortcut (configurable in VS Code settings) +## Configuration + +The extension is configured to open the following file types in each IDE: + +- PhpStorm: `.php`, `.ts`, `.tsx`, `.js`, `.jsx` +- PyCharm Community Edition: `.py` + +You can modify these mappings in the VS Code settings under "IDE Integration". + ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. diff --git a/package.json b/package.json index 5691d02..6663ff5 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "open-in-phpstorm", - "displayName": "Open in PhpStorm", - "description": "Open files easily in PhpStorm", + "name": "open-in-jetbrains-ides", + "displayName": "Open in JetBrains IDEs", + "description": "Open files easily in PhpStorm and PyCharm Community Edition", "version": "0.2.0", "publisher": "MaartenBode", "repository": { @@ -23,25 +23,47 @@ "command": "open-in-phpstorm.openFile", "title": "Open in PhpStorm", "icon": "phpstorm-logo.svg" + }, + { + "command": "open-in-pycharm-ce.openFile", + "title": "Open in PyCharm Community Edition", + "icon": "pycharm-logo.svg" } ], "menus": { "editor/title": [ { "command": "open-in-phpstorm.openFile", - "group": "navigation" + "group": "navigation", + "when": "resourceExtname != .py" + }, + { + "command": "open-in-pycharm-ce.openFile", + "group": "navigation", + "when": "resourceExtname == .py" } ], "editor/context": [ { "command": "open-in-phpstorm.openFile", - "group": "navigation" + "group": "navigation", + "when": "resourceExtname != .py" + }, + { + "command": "open-in-pycharm-ce.openFile", + "group": "navigation", + "when": "resourceExtname == .py" } ], "menuBar": [ { "command": "open-in-phpstorm.openFile", - "when": "editorIsOpen", + "when": "editorIsOpen && resourceExtname != .py", + "group": "navigation" + }, + { + "command": "open-in-pycharm-ce.openFile", + "when": "editorIsOpen && resourceExtname == .py", "group": "navigation" } ] diff --git a/pycharm-logo.svg b/pycharm-logo.svg new file mode 100644 index 0000000..0092bf3 --- /dev/null +++ b/pycharm-logo.svg @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + diff --git a/src/extension.ts b/src/extension.ts index 905d9cd..fba5755 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,8 +1,33 @@ import * as vscode from "vscode"; + import { exec } from "child_process"; +function openFileInIDE(filePath: string, line: number, position: number, ide: string) { + if (ide === "pycharm-ce") { + const command = `open -a "PyCharm CE" "${filePath}"`; + + exec(command, (error, stdout, stderr) => { + if (error) { + vscode.window.showErrorMessage( + `Error opening PyCharm CE: ${stderr}` + ); + } + }); + } else { + const command = `open "${ide}://open?file=${filePath}&line=${line}&column=${position}"`; + + exec(command, (error, stdout, stderr) => { + if (error) { + vscode.window.showErrorMessage( + `Error when opening ${ide}: ${stderr}` + ); + } + }); + } +} + export function activate(context: vscode.ExtensionContext) { - let disposable = vscode.commands.registerCommand( + let phpStormDisposable = vscode.commands.registerCommand( "open-in-phpstorm.openFile", () => { const editor = vscode.window.activeTextEditor; @@ -15,19 +40,29 @@ export function activate(context: vscode.ExtensionContext) { const line = editor.selection.active.line + 1; const position = editor.selection.active.character; - const command = `open "phpstorm://open?file=${filePath}&line=${line}&column=${position}"`; + openFileInIDE(filePath, line, position, "phpstorm"); + } + ); + + let pyCharmCEDisposable = vscode.commands.registerCommand( + "open-in-pycharm-ce.openFile", + () => { + const editor = vscode.window.activeTextEditor; + if (!editor) { + vscode.window.showErrorMessage("No file opened."); + return; + } + + const filePath = editor.document.fileName; + const line = editor.selection.active.line + 1; + const position = editor.selection.active.character; - exec(command, (error, stdout, stderr) => { - if (error) { - vscode.window.showErrorMessage( - `Error when opening PhpStorm: ${stderr}` - ); - } - }); + openFileInIDE(filePath, line, position, "pycharm-ce"); } ); - context.subscriptions.push(disposable); + context.subscriptions.push(phpStormDisposable); + context.subscriptions.push(pyCharmCEDisposable); } export function deactivate() {} From 63d638a1aee38a0f2c5fcd9022c5ae0c96c69c0e Mon Sep 17 00:00:00 2001 From: Thomas-Vos00 Date: Wed, 19 Mar 2025 15:38:31 +0100 Subject: [PATCH 2/3] fix: wrong info in readme --- README.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 0e0ac2b..0e2ea12 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,8 @@ There are several ways to open files in your preferred IDE: The extension is configured to open the following file types in each IDE: -- PhpStorm: `.php`, `.ts`, `.tsx`, `.js`, `.jsx` - PyCharm Community Edition: `.py` - -You can modify these mappings in the VS Code settings under "IDE Integration". +- PhpStorm: All other file types ## Contributing From d0bf881bbe783c14fbc996c8066618039226e277 Mon Sep 17 00:00:00 2001 From: Thomas-Vos00 Date: Wed, 19 Mar 2025 15:39:15 +0100 Subject: [PATCH 3/3] chore: bump to 0.3.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6663ff5..80b1427 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "open-in-jetbrains-ides", "displayName": "Open in JetBrains IDEs", "description": "Open files easily in PhpStorm and PyCharm Community Edition", - "version": "0.2.0", + "version": "0.3.0", "publisher": "MaartenBode", "repository": { "type": "git",