Skip to content

Show code snippet in fix problems #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2025
Merged

Show code snippet in fix problems #745

merged 4 commits into from
Jul 30, 2025

Conversation

wwwillchen
Copy link
Contributor

No description provided.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cubic analysis

3 issues found across 4 files • Review in cubic

React with 👍 or 👎 to teach cubic. You can also tag @cubic-dev-ai to give feedback, ask questions, or re-run the review.

@@ -16,6 +16,10 @@ export function createProblemFixPrompt(problemReport: ProblemReport): string {

problems.forEach((problem, index) => {
prompt += `${index + 1}. ${problem.file}:${problem.line}:${problem.column} - ${problem.message} (TS${problem.code})\n`;
if (problem.snippet) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code snippet is inserted into a Markdown code block without escaping, which could break formatting or allow prompt injection if the snippet contains triple backticks or other Markdown syntax.

Prompt for AI agents
Address the following comment on src/shared/problem_prompt.ts at line 19:

<comment>Code snippet is inserted into a Markdown code block without escaping, which could break formatting or allow prompt injection if the snippet contains triple backticks or other Markdown syntax.</comment>

<file context>
@@ -16,6 +16,10 @@ export function createProblemFixPrompt(problemReport: ProblemReport): string {
 
   problems.forEach((problem, index) =&gt; {
     prompt += `${index + 1}. ${problem.file}:${problem.line}:${problem.column} - ${problem.message} (TS${problem.code})\n`;
+    if (problem.snippet) {
+      prompt += `\`\`\`\n${problem.snippet}\n\`\`\`\n`;
+    }
</file context>

problems.push({
file: normalizePath(path.relative(appPath, diagnostic.file.fileName)),
line: line + 1, // Convert to 1-based
column: character + 1, // Convert to 1-based
message,
code: diagnostic.code,
snippet: snippet.trim(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use trimEnd() so trailing new-lines are removed while preserving leading indentation needed for a readable code snippet. (Based on your team's feedback about preserving code formatting in snippets)

Prompt for AI agents
Address the following comment on workers/tsc/tsc_worker.ts at line 209:

<comment>Use trimEnd() so trailing new-lines are removed while preserving leading indentation needed for a readable code snippet. (Based on your team&#39;s feedback about preserving code formatting in snippets)</comment>

<file context>
@@ -188,12 +188,25 @@ async function runSingleProject(
       continue;
     }
 
+    // Extract the problematic line with context
+    const sourceLines = diagnostic.file.getFullText().split(&quot;\n&quot;);
+    const lineBefore = line &gt; 0 ? sourceLines[line - 1] : &quot;&quot;;
+    const problematicLine = sourceLines[line] || &quot;&quot;;
+    const lineAfter =
+      line &lt; sourceLines.length - 1 ? sourceLines[line + 1] : &quot;&quot;;
</file context>
Suggested change
snippet: snippet.trim(),
snippet: snippet.trimEnd(),

@@ -188,12 +188,25 @@
continue;
}

// Extract the problematic line with context
const sourceLines = diagnostic.file.getFullText().split("\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use a CR-LF tolerant splitter so snippets render correctly on Windows too.

Prompt for AI agents
Address the following comment on workers/tsc/tsc_worker.ts at line 192:

<comment>Use a CR-LF tolerant splitter so snippets render correctly on Windows too.</comment>

<file context>
@@ -188,12 +188,25 @@ async function runSingleProject(
       continue;
     }
 
+    // Extract the problematic line with context
+    const sourceLines = diagnostic.file.getFullText().split(&quot;\n&quot;);
+    const lineBefore = line &gt; 0 ? sourceLines[line - 1] : &quot;&quot;;
+    const problematicLine = sourceLines[line] || &quot;&quot;;
</file context>
Suggested change
const sourceLines = diagnostic.file.getFullText().split("\n");
const sourceLines = diagnostic.file.getFullText().split(/\r?\n/);

@wwwillchen wwwillchen merged commit 510d288 into main Jul 30, 2025
4 checks passed
@wwwillchen wwwillchen deleted the tsc-snippet branch July 30, 2025 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant