Skip to content

Commit 62da7fe

Browse files
committed
Fixes
1 parent f97f3e4 commit 62da7fe

File tree

3 files changed

+37
-14
lines changed

3 files changed

+37
-14
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,16 +1761,23 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
17611761
}
17621762

17631763
// 'Add to Cline' context menu in editor and code action
1764-
async addSelectedCodeToChat(code: string, filePath: string, languageId: string) {
1764+
async addSelectedCodeToChat(code: string, filePath: string, languageId: string, diagnostics?: vscode.Diagnostic[]) {
17651765
// Ensure the sidebar view is visible
17661766
await vscode.commands.executeCommand("claude-dev.SidebarProvider.focus")
17671767
await delay(100)
17681768

17691769
// Post message to webview with the selected code
17701770
const fileMention = this.getFileMentionFromPath(filePath)
1771+
1772+
let input = `${fileMention}\n\`\`\`\n${code}\n\`\`\``
1773+
if (diagnostics) {
1774+
const problemsString = this.convertDiagnosticsToProblemsString(diagnostics)
1775+
input += `\nProblems:\n${problemsString}`
1776+
}
1777+
17711778
await this.postMessageToWebview({
17721779
type: "addToInput",
1773-
text: `${fileMention}\n\`\`\`\n${code}\n\`\`\``,
1780+
text: input,
17741781
})
17751782

17761783
console.log("addSelectedCodeToChat", code, filePath, languageId)
@@ -1804,7 +1811,15 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
18041811
await delay(100)
18051812

18061813
const fileMention = this.getFileMentionFromPath(filePath)
1814+
const problemsString = this.convertDiagnosticsToProblemsString(diagnostics)
1815+
await this.initClineWithTask(
1816+
`Fix the following code in ${fileMention}\n\`\`\`\n${code}\n\`\`\`\n\nProblems:\n${problemsString}`,
1817+
)
18071818

1819+
console.log("fixWithCline", code, filePath, languageId, diagnostics, problemsString)
1820+
}
1821+
1822+
convertDiagnosticsToProblemsString(diagnostics: vscode.Diagnostic[]) {
18081823
let problemsString = ""
18091824
for (const diagnostic of diagnostics) {
18101825
let label: string
@@ -1828,12 +1843,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
18281843
const source = diagnostic.source ? `${diagnostic.source} ` : ""
18291844
problemsString += `\n- [${source}${label}] Line ${line}: ${diagnostic.message}`
18301845
}
1831-
1832-
await this.initClineWithTask(
1833-
`Fix the following code in ${fileMention}\n\`\`\`\n${code}\n\`\`\`\n\nProblems:\n${problemsString.trim()}`,
1834-
)
1835-
1836-
console.log("fixWithCline", code, filePath, languageId, diagnostics, problemsString)
1846+
problemsString = problemsString.trim()
1847+
return problemsString
18371848
}
18381849

18391850
// Task history

src/extension.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ export function activate(context: vscode.ExtensionContext) {
194194
context.subscriptions.push(vscode.window.registerUriHandler({ handleUri }))
195195

196196
context.subscriptions.push(
197-
vscode.commands.registerCommand("cline.addToChat", async (range?: vscode.Range) => {
197+
vscode.commands.registerCommand("cline.addToChat", async (range?: vscode.Range, diagnostics?: vscode.Diagnostic[]) => {
198198
const editor = vscode.window.activeTextEditor
199199
if (!editor) {
200200
return
@@ -214,7 +214,12 @@ export function activate(context: vscode.ExtensionContext) {
214214
const languageId = editor.document.languageId
215215

216216
// Send to sidebar provider
217-
await sidebarProvider.addSelectedCodeToChat(selectedText, filePath, languageId)
217+
await sidebarProvider.addSelectedCodeToChat(
218+
selectedText,
219+
filePath,
220+
languageId,
221+
Array.isArray(diagnostics) ? diagnostics : undefined,
222+
)
218223
}),
219224
)
220225

@@ -280,19 +285,26 @@ export function activate(context: vscode.ExtensionContext) {
280285
range: vscode.Range,
281286
context: vscode.CodeActionContext,
282287
): vscode.CodeAction[] {
283-
// Always offer both actions
288+
// Expand range to include surrounding 3 lines
289+
const expandedRange = new vscode.Range(
290+
Math.max(0, range.start.line - 3),
291+
0,
292+
Math.min(document.lineCount - 1, range.end.line + 3),
293+
document.lineAt(Math.min(document.lineCount - 1, range.end.line + 3)).text.length,
294+
)
295+
284296
const addAction = new vscode.CodeAction("Add to Cline", vscode.CodeActionKind.QuickFix)
285297
addAction.command = {
286298
command: "cline.addToChat",
287299
title: "Add to Cline",
288-
arguments: [range],
300+
arguments: [expandedRange, context.diagnostics],
289301
}
290302

291303
const fixAction = new vscode.CodeAction("Fix with Cline", vscode.CodeActionKind.QuickFix)
292304
fixAction.command = {
293305
command: "cline.fixWithCline",
294306
title: "Fix with Cline",
295-
arguments: [range, context.diagnostics],
307+
arguments: [expandedRange, context.diagnostics],
296308
}
297309

298310
// Only show actions when there are errors

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ const ApiOptions = ({ showModelOptions, apiErrorMessage, modelIdErrorMessage, is
13571357
{(selectedProvider === "openrouter" || selectedProvider === "cline") && showModelOptions && (
13581358
<>
13591359
<VSCodeCheckbox
1360-
style={{ marginTop: -10 }}
1360+
style={{ marginTop: -8 }}
13611361
checked={providerSortingSelected}
13621362
onChange={(e: any) => {
13631363
const isChecked = e.target.checked === true

0 commit comments

Comments
 (0)