🎨 jetbrains improvements
This commit is contained in:
parent
b0397f46cc
commit
ae756270cd
5 changed files with 84 additions and 137 deletions
|
|
@ -137,5 +137,9 @@ export const defaultContextProvidersVsCode: ContextProviderWithParams[] = [
|
|||
];
|
||||
|
||||
export const defaultContextProvidersJetBrains: ContextProviderWithParams[] = [
|
||||
{ name: "code", params: {} },
|
||||
{ name: "diff", params: {} },
|
||||
{ name: "open", params: {} },
|
||||
{ name: "folder", params: {} },
|
||||
{ name: "codebase", params: {} },
|
||||
];
|
||||
|
|
|
|||
|
|
@ -140,7 +140,9 @@ class CoreMessenger(private val project: Project, esbuildPath: String, continueC
|
|||
"getRepoName",
|
||||
"listDir",
|
||||
"getGitRootPath",
|
||||
"getLastModified"
|
||||
"getLastModified",
|
||||
"insertAtCursor",
|
||||
"applyToFile"
|
||||
)
|
||||
|
||||
private val forwardToWebview = listOf<String>(
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import com.intellij.ide.plugins.PluginManagerCore
|
|||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.application.ApplicationInfo
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.openapi.components.ServiceManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.editor.SelectionModel
|
||||
import com.intellij.openapi.extensions.PluginId
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
|
|
@ -145,8 +147,6 @@ class IdeProtocolClient (
|
|||
}
|
||||
val data = parsedMessage["data"]
|
||||
|
||||
val historyManager = HistoryManager()
|
||||
|
||||
try {
|
||||
when (messageType) {
|
||||
"uniqueId" -> respond(
|
||||
|
|
@ -288,8 +288,8 @@ class IdeProtocolClient (
|
|||
"showLines" -> {
|
||||
val data = data as Map<String, Any>
|
||||
val filepath = data["filepath"] as String
|
||||
val startLine = data["startLine"] as Int
|
||||
val endLine = data["endLine"] as Int
|
||||
val startLine = (data["startLine"] as Double).toInt()
|
||||
val endLine = (data["endLine"] as Double).toInt()
|
||||
highlightCode(
|
||||
RangeInFile(
|
||||
filepath,
|
||||
|
|
@ -428,22 +428,6 @@ class IdeProtocolClient (
|
|||
respond(null)
|
||||
}
|
||||
|
||||
// History
|
||||
"history" -> {
|
||||
respond(historyManager.list());
|
||||
}
|
||||
"saveSession" -> {
|
||||
historyManager.save(data as MutableMap<String, Any>);
|
||||
respond(null);
|
||||
}
|
||||
"deleteSession" -> {
|
||||
historyManager.delete(data as String);
|
||||
respond(null);
|
||||
}
|
||||
"loadSession" -> {
|
||||
val session = historyManager.load(data as String)
|
||||
respond(session)
|
||||
}
|
||||
"getSearchResults" -> {
|
||||
respond("")
|
||||
}
|
||||
|
|
@ -461,59 +445,24 @@ class IdeProtocolClient (
|
|||
val openFiles = visibleFiles()
|
||||
respond(openFiles)
|
||||
}
|
||||
"logDevData" -> {
|
||||
val data = data as Map<String, Any>
|
||||
val filename = data["tableName"] as String
|
||||
val jsonLine = data["data"]
|
||||
val filepath = getDevDataFilepath(filename)
|
||||
val contents = Gson().toJson(jsonLine) + "\n"
|
||||
File(filepath).appendText(contents)
|
||||
}
|
||||
"addModel" -> {
|
||||
val data = data as Map<String, Any>
|
||||
val model = data["model"] as Map<String, Any>
|
||||
val updatedConfig = editConfigJson {
|
||||
val models = it["models"] as MutableList<Map<String, Any>>
|
||||
models.add(model)
|
||||
it
|
||||
"insertAtCursor" -> {
|
||||
val msg = data as Map<String, String>;
|
||||
val text = msg["text"] as String
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
val editor = FileEditorManager.getInstance(project).selectedTextEditor ?: return@invokeLater
|
||||
val selectionModel: SelectionModel = editor.selectionModel
|
||||
|
||||
val document = editor.document
|
||||
val startOffset = selectionModel.selectionStart
|
||||
val endOffset = selectionModel.selectionEnd
|
||||
|
||||
WriteCommandAction.runWriteCommandAction(project) {
|
||||
document.replaceString(startOffset, endOffset, text)
|
||||
}
|
||||
}
|
||||
|
||||
configUpdate()
|
||||
setFileOpen(getConfigJsonPath())
|
||||
}
|
||||
"deleteModel" -> {
|
||||
val configJson = editConfigJson { config ->
|
||||
var models: MutableList<Map<String, Any>> = config["models"] as MutableList<Map<String, Any>>
|
||||
val data = data as Map<String, Any>
|
||||
val model = data["title"] as String
|
||||
models = models.filter { it["title"] != model }.toMutableList()
|
||||
config["models"] = models
|
||||
config
|
||||
}
|
||||
configUpdate()
|
||||
"applyToFile" -> {
|
||||
}
|
||||
"addOpenAIKey" -> {
|
||||
val updatedConfig = editConfigJson { config ->
|
||||
val data = data as Map<String, Any>
|
||||
val key = data["key"] as String
|
||||
var models = config["models"] as MutableList<MutableMap<String, Any>>
|
||||
models = models.map {
|
||||
if (it["provider"] == "free-trial") {
|
||||
it["apiKey"] = key
|
||||
it["provider"] = "openai"
|
||||
it
|
||||
} else {
|
||||
it
|
||||
}
|
||||
}.toMutableList()
|
||||
config["models"] = models
|
||||
config
|
||||
}
|
||||
configUpdate()
|
||||
}
|
||||
|
||||
|
||||
|
||||
else -> {
|
||||
println("Unknown messageType: $messageType")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ import {
|
|||
getAltKeyLabel,
|
||||
getFontSize,
|
||||
getMetaKeyLabel,
|
||||
isJetBrains,
|
||||
isMetaEquivalentKeyPressed,
|
||||
} from "../../util";
|
||||
|
||||
|
|
@ -154,27 +153,23 @@ function InputToolbar(props: InputToolbarProps) {
|
|||
{useActiveFile ? "No context" : "Use active file"}
|
||||
</span>
|
||||
) : (
|
||||
isJetBrains() || (
|
||||
<span
|
||||
style={{
|
||||
color: props.usingCodebase ? vscBadgeBackground : lightGray,
|
||||
backgroundColor: props.usingCodebase
|
||||
? lightGray + "33"
|
||||
: undefined,
|
||||
borderRadius: defaultBorderRadius,
|
||||
padding: "2px 4px",
|
||||
}}
|
||||
onClick={(e) => {
|
||||
props.onEnter({
|
||||
useCodebase: true,
|
||||
noContext: !useActiveFile,
|
||||
});
|
||||
}}
|
||||
className={"hover:underline cursor-pointer float-right"}
|
||||
>
|
||||
{getMetaKeyLabel()} ⏎ Use codebase
|
||||
</span>
|
||||
)
|
||||
<span
|
||||
style={{
|
||||
color: props.usingCodebase ? vscBadgeBackground : lightGray,
|
||||
backgroundColor: props.usingCodebase ? lightGray + "33" : undefined,
|
||||
borderRadius: defaultBorderRadius,
|
||||
padding: "2px 4px",
|
||||
}}
|
||||
onClick={(e) => {
|
||||
props.onEnter({
|
||||
useCodebase: true,
|
||||
noContext: !useActiveFile,
|
||||
});
|
||||
}}
|
||||
className={"hover:underline cursor-pointer float-right"}
|
||||
>
|
||||
{getMetaKeyLabel()} ⏎ Use codebase
|
||||
</span>
|
||||
)}
|
||||
<EnterButton
|
||||
offFocus={props.usingCodebase}
|
||||
|
|
|
|||
|
|
@ -80,53 +80,50 @@ function CodeBlockToolBar(props: CodeBlockToolBarProps) {
|
|||
<TopDiv>
|
||||
<SecondDiv bottom={props.bottom || false}>
|
||||
{isJetBrains() || (
|
||||
<>
|
||||
<HeaderButtonWithText
|
||||
text={
|
||||
isTerminalCodeBlock(props.language, props.text)
|
||||
? "Run in terminal"
|
||||
: applying
|
||||
? "Applying..."
|
||||
: "Apply to current file"
|
||||
}
|
||||
disabled={applying}
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={() => {
|
||||
if (terminalLanguages.includes(props.language)) {
|
||||
let text = props.text;
|
||||
if (text.startsWith("$ ")) {
|
||||
text = text.slice(2);
|
||||
}
|
||||
ideMessenger.ide.runCommand(text);
|
||||
return;
|
||||
<HeaderButtonWithText
|
||||
text={
|
||||
isTerminalCodeBlock(props.language, props.text)
|
||||
? "Run in terminal"
|
||||
: applying
|
||||
? "Applying..."
|
||||
: "Apply to current file"
|
||||
}
|
||||
disabled={applying}
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={() => {
|
||||
if (terminalLanguages.includes(props.language)) {
|
||||
let text = props.text;
|
||||
if (text.startsWith("$ ")) {
|
||||
text = text.slice(2);
|
||||
}
|
||||
ideMessenger.ide.runCommand(text);
|
||||
return;
|
||||
}
|
||||
|
||||
if (applying) return;
|
||||
ideMessenger.post("applyToCurrentFile", {
|
||||
text: props.text,
|
||||
});
|
||||
setApplying(true);
|
||||
setTimeout(() => setApplying(false), 2000);
|
||||
}}
|
||||
>
|
||||
{applying ? (
|
||||
<CheckIcon className="w-4 h-4 text-green-500" />
|
||||
) : (
|
||||
<PlayIcon className="w-4 h-4" />
|
||||
)}
|
||||
</HeaderButtonWithText>
|
||||
<HeaderButtonWithText
|
||||
text="Insert at cursor"
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={() => {
|
||||
ideMessenger.post("insertAtCursor", { text: props.text });
|
||||
}}
|
||||
>
|
||||
<ArrowLeftEndOnRectangleIcon className="w-4 h-4" />
|
||||
</HeaderButtonWithText>
|
||||
</>
|
||||
if (applying) return;
|
||||
ideMessenger.post("applyToCurrentFile", {
|
||||
text: props.text,
|
||||
});
|
||||
setApplying(true);
|
||||
setTimeout(() => setApplying(false), 2000);
|
||||
}}
|
||||
>
|
||||
{applying ? (
|
||||
<CheckIcon className="w-4 h-4 text-green-500" />
|
||||
) : (
|
||||
<PlayIcon className="w-4 h-4" />
|
||||
)}
|
||||
</HeaderButtonWithText>
|
||||
)}
|
||||
|
||||
<HeaderButtonWithText
|
||||
text="Insert at cursor"
|
||||
style={{ backgroundColor: vscEditorBackground }}
|
||||
onClick={() => {
|
||||
ideMessenger.post("insertAtCursor", { text: props.text });
|
||||
}}
|
||||
>
|
||||
<ArrowLeftEndOnRectangleIcon className="w-4 h-4" />
|
||||
</HeaderButtonWithText>
|
||||
<CopyButton text={props.text} />
|
||||
</SecondDiv>
|
||||
</TopDiv>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue