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

fix: add current file context when setting is enabled
This commit is contained in:
Dallin Romney 2025-07-11 00:22:26 -07:00 • committed by GitHub
commit 4e3ccde101
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 0 deletions

View file

@ -20,6 +20,7 @@ import {
Tool,
} from "../../";
import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton";
import CurrentFileContextProvider from "../../context/providers/CurrentFileContextProvider";
import MCPContextProvider from "../../context/providers/MCPContextProvider";
import RulesContextProvider from "../../context/providers/RulesContextProvider";
import { ControlPlaneProxyInfo } from "../../control-plane/analytics/IAnalyticsProvider.js";
@ -152,6 +153,17 @@ export default async function doLoadConfig(options: {
newConfig.rules.unshift(...rules);
newConfig.contextProviders.push(new RulesContextProvider({}));
// Add current file as context if setting is enabled
if (
newConfig.experimental?.useCurrentFileAsContext === true &&
!newConfig.contextProviders.find(
(c) =>
c.description.title === CurrentFileContextProvider.description.title,
)
) {
newConfig.contextProviders.push(new CurrentFileContextProvider({}));
}
// Add rules from colocated rules.md files in the codebase
const { rules: codebaseRules, errors: codebaseRulesErrors } =
await loadCodebaseRules(ide);

View file

@ -2,15 +2,39 @@ import { Editor } from "@tiptap/core";
import { ContextProviderDescription } from "core";
import { Mention } from "../extensions";
function isEditorContentEmpty(editor: Editor): boolean {
const editorContent = editor.getJSON();
if (!editorContent.content || editorContent.content.length === 0) {
return true;
}
const firstNode = editorContent.content[0];
if (
firstNode.type === "paragraph" &&
(firstNode.content || []).length === 0
) {
return true;
}
return false;
}
/**
* inserts the current file context as a removable mention in the editor area
*
* skips if there is any other content in the editor
*
* uses tiptap's `create` method to create a new node under the hood
*/
export function insertCurrentFileContextMention(
editor: Editor,
contextProviders: ContextProviderDescription[],
) {
if (!isEditorContentEmpty(editor)) {
return;
}
const foundCurrentFileProvider = contextProviders.find(
(provider) => provider.title === "currentFile",
);