Merge pull request #9576 from uinstinct/remove-rule-button
feat: add remove rule button
This commit is contained in:
commit
1a848432b9
13 changed files with 103 additions and 0 deletions
23
core/core.ts
23
core/core.ts
|
|
@ -432,6 +432,29 @@ export class Core {
|
|||
}
|
||||
});
|
||||
|
||||
on("config/deleteRule", async (msg) => {
|
||||
try {
|
||||
const filepath = msg.data.filepath;
|
||||
if (
|
||||
!isColocatedRulesFile(filepath) &&
|
||||
!isContinueConfigRelatedUri(filepath)
|
||||
) {
|
||||
throw new Error("Only rule files can be deleted");
|
||||
}
|
||||
const fileExists = await this.ide.fileExists(filepath);
|
||||
if (fileExists) {
|
||||
await this.ide.removeFile(filepath);
|
||||
walkDirCache.invalidate();
|
||||
await this.configHandler.reloadConfig(
|
||||
"Rule file deleted (config/deleteRule message)",
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to delete rule file:", error);
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
|
||||
on("config/openProfile", async (msg) => {
|
||||
await this.configHandler.openConfigProfile(msg.data.profileId);
|
||||
});
|
||||
|
|
|
|||
2
core/index.d.ts
vendored
2
core/index.d.ts
vendored
|
|
@ -841,6 +841,8 @@ export interface IDE {
|
|||
|
||||
writeFile(path: string, contents: string): Promise<void>;
|
||||
|
||||
removeFile(path: string): Promise<void>;
|
||||
|
||||
showVirtualFile(title: string, contents: string): Promise<void>;
|
||||
|
||||
openFile(path: string): Promise<void>;
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ export type ToCoreFromIdeOrWebviewProtocol = {
|
|||
void,
|
||||
];
|
||||
"config/addGlobalRule": [undefined | { baseFilename?: string }, void];
|
||||
"config/deleteRule": [{ filepath: string }, void];
|
||||
"config/newPromptFile": [undefined, void];
|
||||
"config/newAssistantFile": [undefined, void];
|
||||
"config/ideSettingsUpdate": [IdeSettings, void];
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ export type ToIdeFromWebviewOrCoreProtocol = {
|
|||
getIdeInfo: [undefined, IdeInfo];
|
||||
getWorkspaceDirs: [undefined, string[]];
|
||||
writeFile: [{ path: string; contents: string }, void];
|
||||
removeFile: [{ path: string }, void];
|
||||
showVirtualFile: [{ name: string; content: string }, void];
|
||||
openFile: [{ path: string }, void];
|
||||
openUrl: [string, void];
|
||||
|
|
|
|||
|
|
@ -168,6 +168,10 @@ export class MessageIde implements IDE {
|
|||
await this.request("writeFile", { path: fileUri, contents });
|
||||
}
|
||||
|
||||
async removeFile(fileUri: string): Promise<void> {
|
||||
await this.request("removeFile", { path: fileUri });
|
||||
}
|
||||
|
||||
async showVirtualFile(title: string, contents: string): Promise<void> {
|
||||
await this.request("showVirtualFile", { name: title, content: contents });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ export const WEBVIEW_TO_CORE_PASS_THROUGH: (keyof ToCoreFromWebviewProtocol)[] =
|
|||
"config/ideSettingsUpdate",
|
||||
"config/addLocalWorkspaceBlock",
|
||||
"config/addGlobalRule",
|
||||
"config/deleteRule",
|
||||
"config/getSerializedProfileInfo",
|
||||
"config/deleteModel",
|
||||
"config/refreshProfiles",
|
||||
|
|
|
|||
|
|
@ -204,6 +204,18 @@ class FileSystemIde implements IDE {
|
|||
});
|
||||
}
|
||||
|
||||
removeFile(fileUri: string): Promise<void> {
|
||||
const filepath = fileURLToPath(fileUri);
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.unlink(filepath, (err) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
showVirtualFile(title: string, contents: string): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -84,6 +84,8 @@ class MessageTypes {
|
|||
"config/newAssistantFile",
|
||||
"config/ideSettingsUpdate",
|
||||
"config/addLocalWorkspaceBlock",
|
||||
"config/addGlobalRule",
|
||||
"config/deleteRule",
|
||||
"config/getSerializedProfileInfo",
|
||||
"config/deleteModel",
|
||||
"config/refreshProfiles",
|
||||
|
|
|
|||
|
|
@ -253,6 +253,11 @@ class IntelliJIDE(
|
|||
fileUtils.writeFile(path, contents)
|
||||
}
|
||||
|
||||
override suspend fun removeFile(path: String) =
|
||||
withContext(Dispatchers.EDT) {
|
||||
fileUtils.removeFile(path)
|
||||
}
|
||||
|
||||
override suspend fun showVirtualFile(title: String, contents: String) {
|
||||
val virtualFile = LightVirtualFile(title, contents)
|
||||
ApplicationManager.getApplication().invokeLater {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,14 @@ class FileUtils(
|
|||
}
|
||||
}
|
||||
|
||||
fun removeFile(fileUri: String) {
|
||||
val found = findFile(fileUri)
|
||||
?: return LOG.warn("File not found: $fileUri")
|
||||
runWriteAction {
|
||||
found.delete(this)
|
||||
}
|
||||
}
|
||||
|
||||
fun listDir(fileUri: String): List<List<Any>> {
|
||||
val found = findFile(fileUri)
|
||||
?: return emptyList()
|
||||
|
|
|
|||
|
|
@ -187,6 +187,8 @@ interface IDE {
|
|||
|
||||
suspend fun writeFile(path: String, contents: String)
|
||||
|
||||
suspend fun removeFile(path: String)
|
||||
|
||||
suspend fun showVirtualFile(title: String, contents: String)
|
||||
|
||||
suspend fun getContinueDir(): String
|
||||
|
|
|
|||
|
|
@ -301,6 +301,10 @@ class VsCodeIde implements IDE {
|
|||
);
|
||||
}
|
||||
|
||||
async removeFile(fileUri: string): Promise<void> {
|
||||
await vscode.workspace.fs.delete(vscode.Uri.parse(fileUri));
|
||||
}
|
||||
|
||||
async showVirtualFile(title: string, contents: string): Promise<void> {
|
||||
this.ideUtils.showVirtualFile(title, contents);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import {
|
|||
BookmarkIcon as BookmarkOutline,
|
||||
EyeIcon,
|
||||
PencilIcon,
|
||||
TrashIcon,
|
||||
} from "@heroicons/react/24/outline";
|
||||
import { BookmarkIcon as BookmarkSolid } from "@heroicons/react/24/solid";
|
||||
import {
|
||||
|
|
@ -21,6 +22,7 @@ import { getRuleDisplayName } from "core/llm/rules/rules-utils";
|
|||
import { useContext, useMemo, useState } from "react";
|
||||
import { DropdownButton } from "../../../components/DropdownButton";
|
||||
import AddRuleDialog from "../../../components/dialogs/AddRuleDialog";
|
||||
import ConfirmationDialog from "../../../components/dialogs/ConfirmationDialog";
|
||||
import HeaderButtonWithToolTip from "../../../components/gui/HeaderButtonWithToolTip";
|
||||
import Switch from "../../../components/gui/Switch";
|
||||
import {
|
||||
|
|
@ -132,6 +134,7 @@ interface RuleCardProps {
|
|||
|
||||
const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
||||
const dispatch = useAppDispatch();
|
||||
const ideMessenger = useContext(IdeMessengerContext);
|
||||
const policy = useAppSelector((state) =>
|
||||
rule.name
|
||||
? state.ui.ruleSettings[rule.name] || DEFAULT_RULE_SETTING
|
||||
|
|
@ -162,6 +165,36 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
|||
);
|
||||
}
|
||||
|
||||
const handleDelete = () => {
|
||||
if (!rule.sourceFile) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(
|
||||
setDialogMessage(
|
||||
<ConfirmationDialog
|
||||
title="Delete Rule"
|
||||
text="Are you sure you want to delete this rule file?"
|
||||
confirmText="Delete"
|
||||
onConfirm={async () => {
|
||||
try {
|
||||
await ideMessenger.request("config/deleteRule", {
|
||||
filepath: rule.sourceFile!,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to delete rule file:", error);
|
||||
}
|
||||
}}
|
||||
/>,
|
||||
),
|
||||
);
|
||||
dispatch(setShowDialog(true));
|
||||
};
|
||||
|
||||
const canDeleteRule =
|
||||
rule.sourceFile &&
|
||||
!["default-chat", "default-agent", "default-plan"].includes(rule.source);
|
||||
|
||||
const smallFont = fontSize(-2);
|
||||
const tinyFont = fontSize(-3);
|
||||
return (
|
||||
|
|
@ -209,6 +242,11 @@ const RuleCard: React.FC<RuleCardProps> = ({ rule }) => {
|
|||
<PencilIcon className="h-3 w-3 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
{canDeleteRule && (
|
||||
<HeaderButtonWithToolTip onClick={handleDelete} text="Delete">
|
||||
<TrashIcon className="h-3 w-3 text-gray-400" />
|
||||
</HeaderButtonWithToolTip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue