Skip to content
Merged
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
4 changes: 2 additions & 2 deletions extensions/intellij/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ intellijPlatformTesting {
"-Dapple.laf.useScreenMenuBar=false",
"-Didea.trust.all.projects=true",
"-Dide.show.tips.on.startup.default.value=false",
"-Dide.browser.jcef.jsQueryPoolSize=10000",
"-Dide.browser.jcef.contextMenu.devTools.enabled=true"
"-Dide.browser.jcef.sandbox.enable=false"
)
}
}
Expand Down Expand Up @@ -145,5 +144,6 @@ tasks {

test {
useJUnitPlatform()
jvmArgumentProviders += CommandLineArgumentProvider { listOf("-Dide.browser.jcef.sandbox.enable=false") }
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package com.github.continuedev.continueintellijextension.actions

import com.github.continuedev.continueintellijextension.HighlightedCodePayload
import com.github.continuedev.continueintellijextension.RangeInFileWithContents
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService.Companion.getBrowser
import com.github.continuedev.continueintellijextension.editor.DiffStreamService
import com.github.continuedev.continueintellijextension.editor.EditorUtils
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.PlatformDataKeys
import com.intellij.openapi.components.service
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import java.io.File

class RestartContinueProcess : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val pluginService = getContinuePluginService(e.project) ?: return
pluginService.coreMessengerManager?.coreMessenger?.restart()
e.project?.service<ContinuePluginService>()?.coreMessenger?.restart()
}
}

Expand All @@ -21,7 +27,7 @@ class AcceptDiffAction : AnAction() {
}

private fun acceptHorizontalDiff(e: AnActionEvent) {
val continuePluginService = getPluginService(e.project) ?: return
val continuePluginService = e.project?.service<ContinuePluginService>() ?: return
continuePluginService.diffManager?.acceptDiff(null)
}

Expand All @@ -41,8 +47,7 @@ class RejectDiffAction : AnAction() {
}

private fun rejectHorizontalDiff(e: AnActionEvent) {
val continuePluginService = getPluginService(e.project) ?: return
continuePluginService.diffManager?.rejectDiff(null)
e.project?.service<ContinuePluginService>()?.diffManager?.rejectDiff(null)
}

private fun rejectVerticalDiff(e: AnActionEvent) {
Expand All @@ -54,54 +59,53 @@ class RejectDiffAction : AnAction() {
}
}


class FocusContinueInputWithoutClearAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project
focusContinueInput(project)
class FocusContinueInputWithoutClearAction : ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) {
project.getBrowser()?.sendToWebview("focusContinueInputWithoutClear")
project.getBrowser()?.focusOnInput()
}
}

class FocusContinueInputAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val continuePluginService = getContinuePluginService(e.project) ?: return

continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus()
continuePluginService.sendToWebview("focusContinueInputWithNewSession", null)
class FocusContinueInputAction : ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) =
focusContinueInput(project)

continuePluginService.ideProtocolClient?.sendHighlightedCode()
companion object {
fun focusContinueInput(project: Project?) {
val browser = project?.getBrowser()
?: return
browser.sendToWebview("focusContinueInputWithNewSession")
browser.focusOnInput()
val rif = EditorUtils.getEditor(project)?.getHighlightedRIF()
?: return
val code = HighlightedCodePayload(RangeInFileWithContents(rif.filepath, rif.range, rif.contents))
browser.sendToWebview("highlightedCode", code)
}
}
}

class NewContinueSessionAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val continuePluginService = getContinuePluginService(e.project) ?: return
continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus()
continuePluginService.sendToWebview("focusContinueInputWithNewSession", null)
class NewContinueSessionAction : ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) {
project.getBrowser()?.sendToWebview("focusContinueInputWithNewSession")
}
}

class ViewHistoryAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val continuePluginService = getContinuePluginService(e.project) ?: return
val params = mapOf("path" to "/history", "toggle" to true)
continuePluginService.sendToWebview("navigateTo", params)
class ViewHistoryAction : ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) {
project.getBrowser()?.sendToWebview("navigateTo", mapOf("path" to "/history", "toggle" to true))
}
}

class OpenConfigAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val continuePluginService = getContinuePluginService(e.project) ?: return
continuePluginService.continuePluginWindow?.content?.components?.get(0)?.requestFocus()
val params = mapOf("path" to "/config", "toggle" to true)
continuePluginService.sendToWebview("navigateTo", params)
class OpenConfigAction : ContinueToolbarAction() {
override fun toolbarActionPerformed(project: Project) {
project.getBrowser()?.sendToWebview("navigateTo", mapOf("path" to "/config", "toggle" to true))
}
}

class OpenLogsAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val project = e.project ?: return
val logFile = java.io.File(System.getProperty("user.home") + "/.continue/logs/core.log")
val logFile = File(System.getProperty("user.home") + "/.continue/logs/core.log")
if (logFile.exists()) {
val virtualFile = com.intellij.openapi.vfs.LocalFileSystem.getInstance().findFileByIoFile(logFile)
if (virtualFile != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.continuedev.continueintellijextension.actions

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import com.intellij.openapi.wm.ToolWindowManager

/**
* Extend your action with [ContinueToolbarAction] if you need a visible, active toolbar.
*/
abstract class ContinueToolbarAction : AnAction() {

abstract fun toolbarActionPerformed(project: Project)

final override fun actionPerformed(event: AnActionEvent) {
val project = event.project
?: return
val tool = ToolWindowManager.getInstance(project).getToolWindow("Continue")
?: return
tool.activate(null) // un-collapse toolbar
toolbarActionPerformed(project)
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.intellij.openapi.fileEditor.FileEditorManagerListener
import com.github.continuedev.continueintellijextension.auth.AuthListener
import com.github.continuedev.continueintellijextension.auth.ContinueAuthService
import com.github.continuedev.continueintellijextension.auth.ControlPlaneSessionInfo
import com.github.continuedev.continueintellijextension.browser.ContinueBrowserService.Companion.getBrowser
import com.github.continuedev.continueintellijextension.constants.getContinueGlobalPath
import com.github.continuedev.continueintellijextension.`continue`.*
import com.github.continuedev.continueintellijextension.listeners.ContinuePluginSelectionListener
Expand Down Expand Up @@ -212,11 +213,8 @@ class ContinuePluginStartupActivity : StartupActivity, DumbAware {

// Listen for theme changes
connection.subscribe(LafManagerListener.TOPIC, LafManagerListener {
val colors = GetTheme().getTheme();
continuePluginService.sendToWebview(
"jetbrains/setColors",
colors
)
val colors = GetTheme().getTheme()
project.getBrowser()?.sendToWebview("jetbrains/setColors", colors)
})

// Listen for clicking settings button to start the auth flow
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package com.github.continuedev.continueintellijextension.browser

import com.github.continuedev.continueintellijextension.constants.MessageTypes
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.github.continuedev.continueintellijextension.utils.uuid
import com.google.gson.Gson
import com.intellij.openapi.components.service
import com.intellij.openapi.diagnostic.Logger
import com.intellij.openapi.project.Project
import com.intellij.ui.jcef.*
import org.cef.CefApp
import org.cef.browser.CefBrowser
import org.cef.handler.CefLoadHandlerAdapter
import javax.swing.JComponent

class ContinueBrowser(private val project: Project) {

private val log = Logger.getInstance(ContinueBrowser::class.java.simpleName)
private val browser: JBCefBrowser = JBCefBrowser.createBuilder().setOffScreenRendering(true).build()

init {
CefApp.getInstance().registerSchemeHandlerFactory("http", "continue", CustomSchemeHandlerFactory())
browser.jbCefClient.setProperty(JBCefClient.Properties.JS_QUERY_POOL_SIZE, 200)
val myJSQueryOpenInBrowser = JBCefJSQuery.create(browser as JBCefBrowserBase)
myJSQueryOpenInBrowser.addHandler { msg: String? ->
val json = Gson().fromJson(msg, BrowserMessage::class.java)
val messageType = json.messageType
val data = json.data
val messageId = json.messageId

if (MessageTypes.PASS_THROUGH_TO_CORE.contains(messageType)) {
project.service<ContinuePluginService>().coreMessenger?.request(messageType, data, messageId) { data ->
sendToWebview(messageType, data, messageId ?: uuid())
}
return@addHandler null
}

// If not pass through, then put it in the status/content/done format for webview
// Core already sends this format
if (msg != null) {
project.service<ContinuePluginService>().ideProtocolClient?.handleMessage(msg) { data ->
sendToWebview(
messageType,
mapOf(
"status" to "success",
"content" to data,
"done" to true
),
messageId ?: uuid()
)
}
}

null
}

browser.jbCefClient.addLoadHandler(OnPageLoad {
executeJavaScript(myJSQueryOpenInBrowser)
}, browser.cefBrowser)

// Load the url only after the protocolClient is initialized,
// otherwise some messages will be lost, which are some configurations when the page is loaded.
// Moreover, we should add LoadHandler before loading the url.
project.service<ContinuePluginService>().onProtocolClientInitialized {
browser.loadURL(getGuiUrl())
}

browser.createImmediately()
}

fun getComponent(): JComponent =
browser.component

fun focusOnInput() {
browser.component.components?.get(0)?.requestFocus()
}

fun openDevTools() {
browser.openDevtools()
}

fun sendToWebview(messageType: String, data: Any? = null, messageId: String = uuid()) {
val json = Gson().toJson(BrowserMessage(messageType, messageId, data))
val jsCode = """window.postMessage($json, "*");"""
try {
browser.executeJavaScriptAsync(jsCode)
} catch (error: IllegalStateException) {
log.warn(error)
}
}

private fun executeJavaScript(myJSQueryOpenInBrowser: JBCefJSQuery) {
val script = """
window.postIntellijMessage = function(messageType, data, messageId) {
const msg = JSON.stringify({messageType, data, messageId});
${myJSQueryOpenInBrowser.inject("msg")}
}
"""
browser.cefBrowser.executeJavaScript(script, getGuiUrl(), 0)
}

// todo: remove and use types.Message
private data class BrowserMessage(
val messageType: String,
val messageId: String?,
val data: Any?
)

private class OnPageLoad(
private val onLoad: () -> Unit
) : CefLoadHandlerAdapter() {
override fun onLoadingStateChange(
browser: CefBrowser?,
isLoading: Boolean,
canGoBack: Boolean,
canGoForward: Boolean
) {
if (!isLoading)
onLoad()
}
}

private companion object {

private fun getGuiUrl() =
System.getenv("GUI_URL") ?: "http://continue/index.html"

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.github.continuedev.continueintellijextension.browser

import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
import com.intellij.openapi.project.Project
import com.intellij.ui.jcef.JBCefApp

@Service(Service.Level.PROJECT)
class ContinueBrowserService(project: Project) {

private val browser: ContinueBrowser? =
if (JBCefApp.isSupported())
ContinueBrowser(project)
else null

companion object {

fun Project.getBrowser() =
service<ContinueBrowserService>().browser

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.github.continuedev.continueintellijextension.factories
package com.github.continuedev.continueintellijextension.browser

import com.intellij.openapi.project.DumbAware
import org.cef.browser.CefBrowser
Expand Down
Loading
Loading