Elffuss BraidHub

kikocis/continue public

Merge pull request #6507 from uinstinct/current-file-context

fix: add current file context when setting is enabled
Changesetf90cd713edb943fb7c8cc6410795f623af42b45ddc394037aa165f86b5a59b4d
AuthorDallin Romney <dallinromney@gmail.com> · 2025-07-11 00:22 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-11 00:22 -07:00
Parentsa4e52f074c38, 89b0d08ea1d4

Browse the files at this changeset

2 files changed

modified core/config/profile/doLoadConfig.ts +12 −0
@@ -20,6 +20,7 @@
2020 Tool,
2121 } from "../../";
2222 import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton";
23+import CurrentFileContextProvider from "../../context/providers/CurrentFileContextProvider";
2324 import MCPContextProvider from "../../context/providers/MCPContextProvider";
2425 import RulesContextProvider from "../../context/providers/RulesContextProvider";
2526 import { ControlPlaneProxyInfo } from "../../control-plane/analytics/IAnalyticsProvider.js";
@@ -152,6 +153,17 @@
152153 newConfig.rules.unshift(...rules);
153154 newConfig.contextProviders.push(new RulesContextProvider({}));
154155
156+ // Add current file as context if setting is enabled
157+ if (
158+ newConfig.experimental?.useCurrentFileAsContext === true &&
159+ !newConfig.contextProviders.find(
160+ (c) =>
161+ c.description.title === CurrentFileContextProvider.description.title,
162+ )
163+ ) {
164+ newConfig.contextProviders.push(new CurrentFileContextProvider({}));
165+ }
166+
155167 // Add rules from colocated rules.md files in the codebase
156168 const { rules: codebaseRules, errors: codebaseRulesErrors } =
157169 await loadCodebaseRules(ide);
modified gui/src/components/mainInput/TipTapEditor/utils/insertCurrentFileContextMention.ts +24 −0
@@ -2,15 +2,39 @@
22 import { ContextProviderDescription } from "core";
33 import { Mention } from "../extensions";
44
5+function isEditorContentEmpty(editor: Editor): boolean {
6+ const editorContent = editor.getJSON();
7+
8+ if (!editorContent.content || editorContent.content.length === 0) {
9+ return true;
10+ }
11+
12+ const firstNode = editorContent.content[0];
13+ if (
14+ firstNode.type === "paragraph" &&
15+ (firstNode.content || []).length === 0
16+ ) {
17+ return true;
18+ }
19+
20+ return false;
21+}
22+
523 /**
624 * inserts the current file context as a removable mention in the editor area
725 *
26+ * skips if there is any other content in the editor
27+ *
828 * uses tiptap's `create` method to create a new node under the hood
929 */
1030 export function insertCurrentFileContextMention(
1131 editor: Editor,
1232 contextProviders: ContextProviderDescription[],
1333 ) {
34+ if (!isEditorContentEmpty(editor)) {
35+ return;
36+ }
37+
1438 const foundCurrentFileProvider = contextProviders.find(
1539 (provider) => provider.title === "currentFile",
1640 );