Skip to content
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

Support for OpenFile to Intellij #35

Closed
wants to merge 19 commits into from
Closed
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
5 changes: 5 additions & 0 deletions .changeset/open-file-intellij.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"click-to-react-component": patch
---

Added Support for OpenFile to Intellij
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ dist

# TernJS port file
.tern-port
/.idea/
7 changes: 7 additions & 0 deletions packages/click-to-react-component/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ If, like me, you use [`vscode-insiders`](https://code.visualstudio.com/insiders/
+<ClickToComponent editor="vscode-insiders" />
```

If, you use [`intellij`], you can set `editor` explicitly:

```diff
-<ClickToComponent />
+<ClickToComponent editor="intellij" />
```

## Run Locally

Clone the project
Expand Down
22 changes: 15 additions & 7 deletions packages/click-to-react-component/src/ClickToComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ export function ClickToComponent({ editor = 'vscode' }) {
if (state === State.HOVER && target instanceof HTMLElement) {
const source = getSourceForElement(target)
const path = getPathToSource(source)
const url = `${editor}://file/${path}`

event.preventDefault()
window.open(url)

openFileInIDE(path)
setState(State.IDLE)
}
},
Expand All @@ -55,15 +52,26 @@ export function ClickToComponent({ editor = 'vscode' }) {
const onClose = React.useCallback(
function handleClose(returnValue) {
if (returnValue) {
const url = `${editor}://file/${returnValue}`
window.open(url)
openFileInIDE(returnValue)
}

setState(State.IDLE)
},
[editor]
)

const openFileInIDE = (file) => {
if (editor === 'intellij') {
const url = `http://localhost:63342/api/file/${file}`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL! I'd like to move this logic up so that lineNumber & columnNumber can be used.

https://github.com/JetBrains/intellij-community/blob/a77365debaadcf00b888a977d89512f3f0f3cf9e/platform/built-in-server/src/org/jetbrains/ide/OpenFileHttpService.kt#L52-L59

This seems related to #28, #29, or #26, too 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirm that in the state it works well, intellij opens the file in the right row and in the right column.
Would you prefer to use another syntax?

Copy link
Collaborator

@dartess dartess May 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericclemmons JetBrain's IDEs support both formats: file.kt:100:34 and file.kt&line=100&column=34. No reason for additional logic here. It is just work.

const cmd = window.open(url)
setTimeout(function() {
cmd.close();
}, 100);
} else {
const url = `${editor}://file/${file}`
window.open(url)
}
}

const onContextMenu = React.useCallback(
function handleContextMenu(
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/click-to-react-component/src/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { ClickToComponent } from './src/ClickToComponent'

export type Editor = 'vscode' | 'vscode-insiders'
export type Editor = 'vscode' | 'vscode-insiders' | 'intellij'

export type ClickToComponentProps = {
editor?: Editor
Expand Down