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..0e2ea12 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,28 @@ 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: + +- PyCharm Community Edition: `.py` +- PhpStorm: All other file types + ## Contributing Contributions are welcome! Please feel free to submit a Pull Request. diff --git a/package.json b/package.json index 5691d02..80b1427 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { - "name": "open-in-phpstorm", - "displayName": "Open in PhpStorm", - "description": "Open files easily in PhpStorm", - "version": "0.2.0", + "name": "open-in-jetbrains-ides", + "displayName": "Open in JetBrains IDEs", + "description": "Open files easily in PhpStorm and PyCharm Community Edition", + "version": "0.3.0", "publisher": "MaartenBode", "repository": { "type": "git", @@ -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() {}