Skip to content

feat: add open-in-pycharm-ce #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
node_modules
.vscode-test/
*.vsix
.idea
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand Down
36 changes: 29 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
}
]
Expand Down
19 changes: 19 additions & 0 deletions pycharm-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 45 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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() {}