Skip to content

Commit 6c947e1

Browse files
committed
Prompt to code always start at col 0
1 parent c15f77c commit 6c947e1

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

Core/Sources/PromptToCodeService/PromptToCodeService.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public final class PromptToCodeService: ObservableObject {
2121
public var language: CopilotLanguage
2222
public var indentSize: Int
2323
public var usesTabsForIndentation: Bool
24+
public var isContinuous = false
2425

2526
public init(
2627
code: String,

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
202202
}
203203
return .cursor(cursorPosition)
204204
}(),
205-
modifications : extraInfo.modifications
205+
modifications: extraInfo.modifications
206206
)
207207
}
208208

@@ -347,24 +347,27 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
347347
presenter.markAsProcessing(true)
348348
defer { presenter.markAsProcessing(false) }
349349
let fileURL = try await Environment.fetchCurrentFileURL()
350-
let language = UserDefaults.shared.value(for: \.chatGPTLanguage)
351350
let codeLanguage = languageIdentifierFromFileURL(fileURL)
352-
let code = {
353-
guard let selection = editor.selections.last,
354-
selection.start != selection.end else { return "" }
355-
return editor.selectedCode(in: selection)
356-
}()
351+
352+
let (code, selection) = {
353+
guard var selection = editor.selections.last,
354+
selection.start != selection.end
355+
else { return ("", .cursor(editor.cursorPosition)) }
356+
// always start from char 0 so that it can keep the indentation.
357+
selection.start = .init(line: selection.start.line, character: 0)
358+
return (
359+
editor.selectedCode(in: selection),
360+
.init(
361+
start: .init(line: selection.start.line, character: selection.start.character),
362+
end: .init(line: selection.end.line, character: selection.end.character)
363+
)
364+
)
365+
}() as (String, CursorRange)
357366

358367
_ = await WidgetDataSource.shared.createPromptToCode(
359368
for: fileURL,
360369
code: code,
361-
selectionRange: editor.selections.last.map { .init(
362-
start: $0.start,
363-
end: $0.end
364-
) } ?? .init(
365-
start: editor.cursorPosition,
366-
end: editor.cursorPosition
367-
),
370+
selectionRange: selection,
368371
language: codeLanguage
369372
)
370373

0 commit comments

Comments
 (0)