-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Conversation
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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) => {
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(), |
There was a problem hiding this comment.
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'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("\n");
+ const lineBefore = line > 0 ? sourceLines[line - 1] : "";
+ const problematicLine = sourceLines[line] || "";
+ const lineAfter =
+ line < sourceLines.length - 1 ? sourceLines[line + 1] : "";
</file context>
snippet: snippet.trim(), | |
snippet: snippet.trimEnd(), |
workers/tsc/tsc_worker.ts
Outdated
@@ -188,12 +188,25 @@ | |||
continue; | |||
} | |||
|
|||
// Extract the problematic line with context | |||
const sourceLines = diagnostic.file.getFullText().split("\n"); |
There was a problem hiding this comment.
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("\n");
+ const lineBefore = line > 0 ? sourceLines[line - 1] : "";
+ const problematicLine = sourceLines[line] || "";
</file context>
const sourceLines = diagnostic.file.getFullText().split("\n"); | |
const sourceLines = diagnostic.file.getFullText().split(/\r?\n/); |
No description provided.