Skip to content

Commit e5967e0

Browse files
committed
Merge branch 'feature/informative-suggestion-wip' into develop
2 parents ecfdfc0 + 02900cb commit e5967e0

14 files changed

Lines changed: 400 additions & 80 deletions

File tree

Core/Sources/ChatGPTChatTab/ChatPanel.swift

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -540,26 +540,14 @@ struct ChatPanelInputArea: View {
540540
removeDuplicates: {
541541
$0.typedMessage == $1.typedMessage && $0.focusedField == $1.focusedField
542542
}) { viewStore in
543-
ZStack(alignment: .center) {
544-
// a hack to support dynamic height of TextEditor
545-
Text(
546-
viewStore.state.typedMessage.isEmpty ? "Hi" : viewStore.state.typedMessage
547-
).opacity(0)
548-
.font(.system(size: 14))
549-
.frame(maxWidth: .infinity, maxHeight: 400)
550-
.padding(.top, 1)
551-
.padding(.bottom, 2)
552-
.padding(.horizontal, 4)
553-
554-
CustomTextEditor(
555-
text: viewStore.$typedMessage,
556-
font: .systemFont(ofSize: 14),
557-
onSubmit: { viewStore.send(.sendButtonTapped) },
558-
completions: chatAutoCompletion
559-
)
560-
.padding(.top, 1)
561-
.padding(.bottom, -1)
562-
}
543+
AutoresizingCustomTextEditor(
544+
text: viewStore.$typedMessage,
545+
font: .systemFont(ofSize: 14),
546+
isEditable: true,
547+
maxHeight: 400,
548+
onSubmit: { viewStore.send(.sendButtonTapped) },
549+
completions: chatAutoCompletion
550+
)
563551
.focused($focusedField, equals: .textField)
564552
.bind(viewStore.$focusedField, to: $focusedField)
565553
.padding(8)

Core/Sources/Service/GUI/WidgetDataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import SuggestionWidget
1414
final class WidgetDataSource {}
1515

1616
extension WidgetDataSource: SuggestionWidgetDataSource {
17-
func suggestionForFile(at url: URL) async -> SuggestionProvider? {
17+
func suggestionForFile(at url: URL) async -> CodeSuggestionProvider? {
1818
for workspace in Service.shared.workspacePool.workspaces.values {
1919
if let filespace = workspace.filespaces[url],
2020
let suggestion = filespace.presentingSuggestion

Core/Sources/SuggestionWidget/FeatureReducers/PanelFeature.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public struct PanelFeature: ReducerProtocol {
2323

2424
public enum Action: Equatable {
2525
case presentSuggestion
26-
case presentSuggestionProvider(SuggestionProvider, displayContent: Bool)
26+
case presentSuggestionProvider(CodeSuggestionProvider, displayContent: Bool)
2727
case presentError(String)
2828
case presentPromptToCode(PromptToCodeGroup.PromptToCodeInitialState)
2929
case displayPanelContent
@@ -136,7 +136,7 @@ public struct PanelFeature: ReducerProtocol {
136136
}
137137
}
138138

139-
func fetchSuggestionProvider(fileURL: URL) async -> SuggestionProvider? {
139+
func fetchSuggestionProvider(fileURL: URL) async -> CodeSuggestionProvider? {
140140
guard let provider = await suggestionWidgetControllerDependency
141141
.suggestionWidgetDataSource?
142142
.suggestionForFile(at: fileURL) else { return nil }

Core/Sources/SuggestionWidget/FeatureReducers/SharedPanelFeature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import SwiftUI
66
public struct SharedPanelFeature: ReducerProtocol {
77
public struct Content: Equatable {
88
public var promptToCodeGroup = PromptToCodeGroup.State()
9-
var suggestion: SuggestionProvider?
9+
var suggestion: CodeSuggestionProvider?
1010
public var promptToCode: PromptToCode.State? { promptToCodeGroup.activePromptToCode }
1111
var error: String?
1212
}

Core/Sources/SuggestionWidget/FeatureReducers/SuggestionPanelFeature.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import SwiftUI
44

55
public struct SuggestionPanelFeature: ReducerProtocol {
66
public struct State: Equatable {
7-
var content: SuggestionProvider?
7+
var content: CodeSuggestionProvider?
88
var colorScheme: ColorScheme = .light
99
var alignTopToAnchor = false
1010
var isPanelDisplayed: Bool = false

Core/Sources/SuggestionWidget/Providers/SuggestionProvider.swift renamed to Core/Sources/SuggestionWidget/Providers/CodeSuggestionProvider.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import Foundation
22
import SwiftUI
33

4-
public final class SuggestionProvider: ObservableObject, Equatable {
5-
public static func == (lhs: SuggestionProvider, rhs: SuggestionProvider) -> Bool {
4+
public final class CodeSuggestionProvider: ObservableObject, Equatable {
5+
public static func == (lhs: CodeSuggestionProvider, rhs: CodeSuggestionProvider) -> Bool {
66
lhs.code == rhs.code && lhs.language == rhs.language
77
}
88

@@ -12,6 +12,7 @@ public final class SuggestionProvider: ObservableObject, Equatable {
1212
@Published public var suggestionCount: Int = 0
1313
@Published public var currentSuggestionIndex: Int = 0
1414
@Published public var commonPrecedingSpaceCount = 0
15+
@Published public var extraInformation: String = ""
1516

1617
public var onSelectPreviousSuggestionTapped: () -> Void
1718
public var onSelectNextSuggestionTapped: () -> Void

Core/Sources/SuggestionWidget/SuggestionPanelContent/CodeBlockSuggestionPanel.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import SharedUIComponents
22
import SwiftUI
33

44
struct CodeBlockSuggestionPanel: View {
5-
@ObservedObject var suggestion: SuggestionProvider
5+
@ObservedObject var suggestion: CodeSuggestionProvider
66
@Environment(\.colorScheme) var colorScheme
77
@AppStorage(\.suggestionCodeFontSize) var fontSize
88
@AppStorage(\.suggestionDisplayCompactMode) var suggestionDisplayCompactMode
99

1010
struct ToolBar: View {
11-
@ObservedObject var suggestion: SuggestionProvider
11+
@ObservedObject var suggestion: CodeSuggestionProvider
1212

1313
var body: some View {
1414
HStack {
@@ -50,7 +50,7 @@ struct CodeBlockSuggestionPanel: View {
5050
}
5151

5252
struct CompactToolBar: View {
53-
@ObservedObject var suggestion: SuggestionProvider
53+
@ObservedObject var suggestion: CodeSuggestionProvider
5454

5555
var body: some View {
5656
HStack {
@@ -114,7 +114,7 @@ struct CodeBlockSuggestionPanel: View {
114114

115115
struct CodeBlockSuggestionPanel_Dark_Preview: PreviewProvider {
116116
static var previews: some View {
117-
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(
117+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
118118
code: """
119119
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
120120
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
@@ -142,7 +142,7 @@ struct CodeBlockSuggestionPanel_Dark_Preview: PreviewProvider {
142142

143143
struct CodeBlockSuggestionPanel_Bright_Preview: PreviewProvider {
144144
static var previews: some View {
145-
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(
145+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
146146
code: """
147147
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
148148
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
@@ -176,7 +176,7 @@ struct CodeBlockSuggestionPanel_CompactToolBar_Preview: PreviewProvider {
176176
}()
177177

178178
static var previews: some View {
179-
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(
179+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
180180
code: """
181181
LazyVGrid(columns: [GridItem(.fixed(30)), GridItem(.flexible())]) {
182182
ForEach(0..<viewModel.suggestion.count, id: \\.self) { index in // lkjaskldjalksjdlkasjdlkajslkdjas
@@ -208,7 +208,7 @@ struct CodeBlockSuggestionPanel_CompactToolBar_Preview: PreviewProvider {
208208

209209
struct CodeBlockSuggestionPanel_Dark_Objc_Preview: PreviewProvider {
210210
static var previews: some View {
211-
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(
211+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
212212
code: """
213213
- (void)addSubview:(UIView *)view {
214214
[self addSubview:view];
@@ -233,7 +233,7 @@ struct CodeBlockSuggestionPanel_Dark_Objc_Preview: PreviewProvider {
233233

234234
struct CodeBlockSuggestionPanel_Bright_Objc_Preview: PreviewProvider {
235235
static var previews: some View {
236-
CodeBlockSuggestionPanel(suggestion: SuggestionProvider(
236+
CodeBlockSuggestionPanel(suggestion: CodeSuggestionProvider(
237237
code: """
238238
- (void)addSubview:(UIView *)view {
239239
[self addSubview:view];

Core/Sources/SuggestionWidget/SuggestionPanelContent/PromptToCodePanel.swift

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -372,27 +372,15 @@ extension PromptToCodePanel {
372372
)
373373
}
374374
) { viewStore in
375-
ZStack(alignment: .center) {
376-
// a hack to support dynamic height of TextEditor
377-
Text(viewStore.state.prompt.isEmpty ? "Hi" : viewStore.state.prompt)
378-
.opacity(0)
379-
.font(.system(size: 14))
380-
.frame(maxWidth: .infinity, maxHeight: 400)
381-
.padding(.top, 1)
382-
.padding(.bottom, 2)
383-
.padding(.horizontal, 4)
384-
385-
CustomTextEditor(
386-
text: viewStore.$prompt,
387-
font: .systemFont(ofSize: 14),
388-
isEditable: !viewStore.state.isResponding,
389-
onSubmit: { viewStore.send(.modifyCodeButtonTapped) }
390-
)
391-
.padding(.top, 1)
392-
.padding(.bottom, -1)
393-
.opacity(viewStore.state.isResponding ? 0.5 : 1)
394-
.disabled(viewStore.state.isResponding)
395-
}
375+
AutoresizingCustomTextEditor(
376+
text: viewStore.$prompt,
377+
font: .systemFont(ofSize: 14),
378+
isEditable: !viewStore.state.isResponding,
379+
maxHeight: 400,
380+
onSubmit: { viewStore.send(.modifyCodeButtonTapped) }
381+
)
382+
.opacity(viewStore.state.isResponding ? 0.5 : 1)
383+
.disabled(viewStore.state.isResponding)
396384
.focused($focusField, equals: .textField)
397385
.bind(viewStore.$focusField, to: $focusField)
398386
}

Core/Sources/SuggestionWidget/SuggestionWidgetDataSource.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Foundation
22

33
public protocol SuggestionWidgetDataSource {
4-
func suggestionForFile(at url: URL) async -> SuggestionProvider?
4+
func suggestionForFile(at url: URL) async -> CodeSuggestionProvider?
55
}
66

77
struct MockWidgetDataSource: SuggestionWidgetDataSource {
8-
func suggestionForFile(at url: URL) async -> SuggestionProvider? {
9-
return SuggestionProvider(
8+
func suggestionForFile(at url: URL) async -> CodeSuggestionProvider? {
9+
return CodeSuggestionProvider(
1010
code: """
1111
func test() {
1212
let x = 1

Pro

Submodule Pro updated from c0ffa88 to 7b8199f

0 commit comments

Comments
 (0)