Merge pull request #2818 from continuedev/pe/jb-osr-bugfixes

fix(jb): OSR issues + Chromium docs
This commit is contained in:
Nate Sesti 2024-11-05 18:49:53 -08:00 • committed by GitHub
commit eea6f48a4a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 187 additions and 180 deletions

View file

@ -421,7 +421,7 @@ Several experimental config parameters are available, as described below:
- `fix`: Prompt for fixing code.
- `optimize`: Prompt for optimizing code.
- `fixGrammar`: Prompt for fixing grammar or spelling.
- `useChromiumForDocsCrawling`: Use chromium to crawl docs instead of default lighter-weight tool that can't render sites. Downloads and installs Chromium to `~/.continue/.utils`.
- `useChromiumForDocsCrawling`: Use Chromium to crawl docs locally. Useful if the default Cheerio crawler fails on sites that require JavaScript rendering. Downloads and installs Chromium to `~/.continue/.utils`..
Example

View file

@ -22,7 +22,7 @@ class ConfigJsonSchemaProviderFactory : JsonSchemaProviderFactory {
class ConfigJsonSchemaFileProvider : JsonSchemaFileProvider {
override fun isAvailable(file: VirtualFile): Boolean {
return path.endsWith("/.continue/config.json")
return file.path.endsWith("/.continue/config.json")
}
override fun getName(): String {

View file

@ -2,6 +2,7 @@ package com.github.continuedev.continueintellijextension.services
import com.github.continuedev.continueintellijextension.constants.getConfigJsPath
import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath
import com.intellij.openapi.application.ApplicationInfo
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.*
import com.intellij.openapi.options.Configurable
@ -28,6 +29,7 @@ class ContinueSettingsComponent : DumbAware {
val userToken: JTextField = JTextField()
val enableTabAutocomplete: JCheckBox = JCheckBox("Enable Tab Autocomplete")
val enableContinueTeamsBeta: JCheckBox = JCheckBox("Enable Continue for Teams Beta")
val enableOSR: JCheckBox = JCheckBox("Enable Off-Screen Rendering")
val displayEditorTooltip: JCheckBox = JCheckBox("Display Editor Tooltip")
init {
@ -56,6 +58,8 @@ class ContinueSettingsComponent : DumbAware {
constraints.gridy++
panel.add(enableContinueTeamsBeta, constraints)
constraints.gridy++
panel.add(enableOSR, constraints)
constraints.gridy++
panel.add(displayEditorTooltip, constraints)
constraints.gridy++
@ -87,6 +91,7 @@ open class ContinueExtensionSettings : PersistentStateComponent<ContinueExtensio
var enableTabAutocomplete: Boolean = true
var ghAuthToken: String? = null
var enableContinueTeamsBeta: Boolean = false
var enableOSR: Boolean = shouldRenderOffScreen()
var displayEditorTooltip: Boolean = true
}
@ -107,6 +112,7 @@ open class ContinueExtensionSettings : PersistentStateComponent<ContinueExtensio
get() = ServiceManager.getService(ContinueExtensionSettings::class.java)
}
// Sync remote config from server
private fun syncRemoteConfig() {
val state = instance.continueState
@ -198,6 +204,7 @@ class ContinueExtensionConfigurable : Configurable {
mySettingsComponent?.userToken?.text != settings.continueState.userToken ||
mySettingsComponent?.enableTabAutocomplete?.isSelected != settings.continueState.enableTabAutocomplete ||
mySettingsComponent?.enableContinueTeamsBeta?.isSelected != settings.continueState.enableContinueTeamsBeta ||
mySettingsComponent?.enableOSR?.isSelected != settings.continueState.enableOSR ||
mySettingsComponent?.displayEditorTooltip?.isSelected != settings.continueState.displayEditorTooltip
return modified
}
@ -210,6 +217,7 @@ class ContinueExtensionConfigurable : Configurable {
settings.continueState.enableTabAutocomplete = mySettingsComponent?.enableTabAutocomplete?.isSelected ?: false
settings.continueState.enableContinueTeamsBeta =
mySettingsComponent?.enableContinueTeamsBeta?.isSelected ?: false
settings.continueState.enableOSR = mySettingsComponent?.enableOSR?.isSelected ?: true
settings.continueState.displayEditorTooltip = mySettingsComponent?.displayEditorTooltip?.isSelected ?: true
ApplicationManager.getApplication().messageBus.syncPublisher(SettingsListener.TOPIC)
@ -224,6 +232,7 @@ class ContinueExtensionConfigurable : Configurable {
mySettingsComponent?.userToken?.text = settings.continueState.userToken
mySettingsComponent?.enableTabAutocomplete?.isSelected = settings.continueState.enableTabAutocomplete
mySettingsComponent?.enableContinueTeamsBeta?.isSelected = settings.continueState.enableContinueTeamsBeta
mySettingsComponent?.enableOSR?.isSelected = settings.continueState.enableOSR
mySettingsComponent?.displayEditorTooltip?.isSelected = settings.continueState.displayEditorTooltip
ContinueExtensionSettings.instance.addRemoteSyncJob()
@ -237,3 +246,32 @@ class ContinueExtensionConfigurable : Configurable {
return "Continue Extension Settings"
}
}
/**
* This function checks if off-screen rendering (OSR) should be used.
*
* If ui.useOSR is set in config.json, that value is used.
*
* Otherwise, we check if the pluginSinceBuild is greater than or equal to 233, which corresponds
* to IntelliJ platform version 2023.3 and later.
*
* Setting `setOffScreenRendering` to `false` causes a number of issues such as a white screen flash when loading
* the GUI and the inability to set `cursor: pointer`. However, setting `setOffScreenRendering` to `true` on
* platform versions prior to 2023.3.4 causes larger issues such as an inability to type input for certain languages,
* e.g. Korean.
*
* References:
* 1. https://youtrack.jetbrains.com/issue/IDEA-347828/JCEF-white-flash-when-tool-window-show#focus=Comments-27-9334070.0-0
* This issue mentions that white screen flash problems were resolved in platformVersion 2023.3.4.
* 2. https://www.jetbrains.com/idea/download/other.html
* This documentation shows mappings from platformVersion to branchNumber.
*
* We use the branchNumber (e.g., 233) instead of the full version number (e.g., 2023.3.4) because
* it's a simple integer without dot notation, making it easier to compare.
*/
private fun shouldRenderOffScreen(): Boolean {
val minBuildNumber = 233
val applicationInfo = ApplicationInfo.getInstance()
val currentBuildNumber = applicationInfo.build.baselineVersion
return currentBuildNumber >= minBuildNumber
}

View file

@ -5,6 +5,7 @@ import com.github.continuedev.continueintellijextension.constants.MessageTypes
import com.github.continuedev.continueintellijextension.constants.getConfigJsonPath
import com.github.continuedev.continueintellijextension.`continue`.*
import com.github.continuedev.continueintellijextension.factories.CustomSchemeHandlerFactory
import com.github.continuedev.continueintellijextension.services.ContinueExtensionSettings
import com.github.continuedev.continueintellijextension.services.ContinuePluginService
import com.google.gson.Gson
import com.google.gson.JsonObject
@ -78,7 +79,8 @@ class ContinueBrowser(val project: Project, url: String) {
val browser: JBCefBrowser
init {
this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(shouldRenderOffScreen()).build()
val enableOSR = ServiceManager.getService(ContinueExtensionSettings::class.java).continueState.enableOSR
this.browser = JBCefBrowser.createBuilder().setOffScreenRendering(enableOSR).build()
browser.jbCefClient.setProperty(
@ -274,34 +276,4 @@ class ContinueBrowser(val project: Project, url: String) {
return """window.postMessage($jsonData, "*");"""
}
/**
* This function checks if the pluginSinceBuild is greater than or equal to 233, which corresponds
* to IntelliJ platform version 2023.3 and later.
*
* Setting `setOffScreenRendering` to `false` causes a number of issues such as a white screen flash when loading
* the GUI and the inability to set `cursor: pointer`. However, setting `setOffScreenRendering` to `true` on
* platform versions prior to 2023.3.4 causes larger issues such as an inability to type input for certain langauges,
* e.g. Korean.
*
* References:
* 1. https://youtrack.jetbrains.com/issue/IDEA-347828/JCEF-white-flash-when-tool-window-show#focus=Comments-27-9334070.0-0
* This issue mentions that white screen flash problems were resolved in platformVersion 2023.3.4.
* 2. https://www.jetbrains.com/idea/download/other.html
* This documentation shows mappings from platformVersion to branchNumber.
*
* We use the branchNumber (e.g., 233) instead of the full version number (e.g., 2023.3.4) because
* it's a simple integer without dot notation, making it easier to compare.
*/
private fun shouldRenderOffScreen(): Boolean {
// With the 0.0.77 release, non-Mac users have been reporting issues with paste functionality
// in the browser. Disabling OSR for all non-Mac users for now.
if (!SystemInfo.isMac) {
return false
}
val minBuildNumber = 233
val applicationInfo = ApplicationInfo.getInstance()
val currentBuildNumber = applicationInfo.build.baselineVersion
return currentBuildNumber >= minBuildNumber
}
}

View file

@ -3320,6 +3320,11 @@
"default": "If there are any grammar or spelling mistakes in this writing, fix them. Do not make other large changes to the writing."
}
}
},
"useChromiumForDocsCrawling": {
"type": "boolean",
"description": "Use Chromium to crawl docs locally. Useful if the default Cheerio crawler fails on sites that require JavaScript rendering. Downloads and installs Chromium to `~/.continue/.utils`.",
"default": false
}
}
}

View file

@ -50,9 +50,11 @@ import {
getFontSize,
isJetBrains,
isMetaEquivalentKeyPressed,
isWebEnvironment,
} from "../../util";
import { handleMetaKeyPressJetBrains } from "../../util/handleMetaKeyPressJetBrains";
import {
handleJetBrainsMetaKeyPress,
handleMetaKeyPress,
} from "./handleMetaKeyPress";
import { CodeBlockExtension } from "./CodeBlockExtension";
import { SlashCommand } from "./CommandsExtension";
import InputToolbar, { ToolbarOptions } from "./InputToolbar";
@ -78,6 +80,7 @@ const InputBoxDiv = styled.div<{ border?: string }>`
props.border ? props.border : `0.5px solid ${vscInputBorder}`};
outline: none;
font-size: ${getFontSize()}px;
&:focus {
outline: none;
@ -561,7 +564,7 @@ function TipTapEditor(props: TipTapEditorProps) {
/**
* This handles various issues with meta key actions
* - In JetBrains, when using "off screen rendering", there is a bug where using the meta key to
* - In JetBrains, when using OSR in JCEF, there is a bug where using the meta key to
* highlight code using arrow keys is not working
* - In VS Code, while working with .ipynb files there is a problem where copy/paste/cut will affect
* the actual notebook cells, even when performing them in our GUI
@ -571,77 +574,33 @@ function TipTapEditor(props: TipTapEditorProps) {
setActiveKey(e.key);
if (isMetaEquivalentKeyPressed(e)) {
const { key, code } = e;
const isWebEnv = isWebEnvironment();
const text = editor.state.doc.textBetween(
editor.state.selection.from,
editor.state.selection.to,
);
if (isJetBrains()) {
if (code === "KeyJ") {
e.stopPropagation();
e.preventDefault();
setIgnoreHighlightedCode(true);
setTimeout(() => {
setIgnoreHighlightedCode(false);
}, 100);
}
if (isMetaEquivalentKeyPressed(e)) {
e.stopPropagation();
e.preventDefault();
handleMetaKeyPressJetBrains(e, text, editor.commands.setContent);
}
} else {
if (code === "KeyL") {
e.stopPropagation();
e.preventDefault();
setIgnoreHighlightedCode(true);
setTimeout(() => {
setIgnoreHighlightedCode(false);
}, 100);
return;
}
switch (key) {
case "x":
e.stopPropagation();
e.preventDefault();
if (isWebEnv) {
await navigator.clipboard.writeText(text);
editor.commands.deleteSelection();
} else {
document.execCommand("cut");
}
break;
case "c":
e.stopPropagation();
e.preventDefault();
if (isWebEnv) {
await navigator.clipboard.writeText(text);
} else {
document.execCommand("copy");
}
break;
case "v":
e.stopPropagation();
e.preventDefault();
if (isWebEnv) {
const clipboardText = await navigator.clipboard.readText();
editor.commands.insertContent(clipboardText);
} else {
document.execCommand("paste");
}
break;
}
}
} else if (e.key === "Escape") {
if (e.key === "Escape") {
e.stopPropagation();
e.preventDefault();
ideMessenger.post("focusEditor", undefined);
return;
}
if (!isMetaEquivalentKeyPressed(e)) {
return;
}
if (isJetBrains()) {
if (e.code === "KeyJ") {
setTemporaryIgnoreHighlightedCode();
} else {
handleJetBrainsMetaKeyPress(e, editor);
}
}
await handleMetaKeyPress(e, editor);
};
const setTemporaryIgnoreHighlightedCode = () => {
setIgnoreHighlightedCode(true);
setTimeout(() => {
setIgnoreHighlightedCode(false);
}, 100);
};
const handleKeyUp = () => {

View file

@ -0,0 +1,110 @@
import { KeyboardEvent } from "react";
import { isWebEnvironment } from "../../util";
import { Editor } from "@tiptap/react";
const isWebEnv = isWebEnvironment();
export const handleJetBrainsMetaKeyPress = (
e: KeyboardEvent,
editor: Editor,
) => {
const selection = window.getSelection();
const handlers: Record<string, () => void> = {
Backspace: () => handleJetBrainsMetaBackspace(editor),
ArrowLeft: () =>
selection.modify(
e.shiftKey ? "extend" : "move",
"backward",
"lineboundary",
),
ArrowRight: () =>
selection.modify(
e.shiftKey ? "extend" : "move",
"forward",
"lineboundary",
),
ArrowDown: () =>
selection.modify(
e.shiftKey ? "extend" : "move",
"forward",
"documentboundary",
),
ArrowUp: () => {
selection.modify(
e.shiftKey ? "extend" : "move",
"backward",
"documentboundary",
);
},
};
if (e.key in handlers) {
e.stopPropagation();
e.preventDefault();
handlers[e.key]();
}
};
export const handleMetaKeyPress = async (e: KeyboardEvent, editor: Editor) => {
const text = editor.state.doc.textBetween(
editor.state.selection.from,
editor.state.selection.to,
);
const handlers: Record<string, () => Promise<void>> = {
x: () => handleCutOperation(text, editor),
c: () => handleCopyOperation(text),
v: () => handlePasteOperation(editor),
};
if (e.key in handlers) {
e.stopPropagation();
e.preventDefault();
await handlers[e.key]();
}
};
export const handleJetBrainsMetaBackspace = (editor: Editor) => {
const { doc } = editor.state;
for (let i = doc.content.childCount - 1; i >= 0; i--) {
const node = doc.content.child(i);
if (node.type.name !== "codeBlock") {
editor.commands.deleteNode(node.type.name);
}
}
// Add an empty string so the user can keep typing
editor.commands.createParagraphNear();
};
export const handleCutOperation = async (text: string, editor: Editor) => {
const selection = window.getSelection();
selection.deleteFromDocument();
if (isWebEnv) {
await navigator.clipboard.writeText(text);
editor.commands.deleteSelection();
} else {
document.execCommand("cut");
}
};
export const handleCopyOperation = async (text: string) => {
if (isWebEnv) {
await navigator.clipboard.writeText(text);
} else {
document.execCommand("copy");
}
};
export const handlePasteOperation = async (editor: Editor) => {
if (isWebEnv) {
const clipboardText = await navigator.clipboard.readText();
editor.commands.insertContent(clipboardText);
} else {
document.execCommand("paste");
}
};

View file

@ -1,77 +0,0 @@
import { KeyboardEvent } from "react";
import { getPlatform } from ".";
export const handleMetaKeyPressJetBrains = (
e: KeyboardEvent,
text: string,
setText: (text: string) => void,
) => {
const { selectionStart, selectionEnd } = e.target as HTMLTextAreaElement;
if (e.key === "Backspace") {
handleMetaBackspace(e, text, setText, selectionStart, selectionEnd);
}
if (getPlatform() === "mac") {
if (e.key === "ArrowLeft") {
handleMacArrowLeftKey(e);
} else if (e.key === "ArrowRight") {
handleMacArrowRightKey(e);
}
}
};
const handleMetaBackspace = (
e: KeyboardEvent,
text: string,
setText: (text: string) => void,
start: number,
end: number,
) => {
const target = e.target as HTMLTextAreaElement;
let newStart = start;
if (start !== end) {
setText(text.slice(0, start) + text.slice(end));
} else {
newStart =
getPlatform() === "mac"
? text.lastIndexOf("\n", start - 1) + 1
: text.slice(0, start).trimEnd().lastIndexOf(" ") + 1;
setText(text.slice(0, newStart) + text.slice(start));
}
target.setSelectionRange(newStart, newStart);
};
const handleMacArrowLeftKey = (e: KeyboardEvent) => {
const target = e.target as HTMLDivElement;
const selection = window.getSelection();
const range = document.createRange();
if (e.shiftKey) {
selection.modify("extend", "backward", "character");
} else {
range.setStart(target.firstChild, 0);
range.setEnd(target.firstChild, 0);
selection.removeAllRanges();
selection.addRange(range);
}
};
const handleMacArrowRightKey = (e: KeyboardEvent) => {
const selection = window.getSelection();
const range = document.createRange();
const target = e.target as HTMLDivElement;
if (e.shiftKey) {
selection.modify("extend", "forward", "character");
} else {
range.selectNodeContents(target);
range.collapse(false);
selection.removeAllRanges();
selection.addRange(range);
}
};