Skip to content

Commit f91cbe5

Browse files
committed
Merge branch 'release/0.23.0'
2 parents 5898b16 + c0746aa commit f91cbe5

116 files changed

Lines changed: 5556 additions & 1946 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Copilot for Xcode.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
C8009BFF2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8009BFE2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift */; };
1111
C8009C032941C576007AA7E8 /* RealtimeSuggestionCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8009C022941C576007AA7E8 /* RealtimeSuggestionCommand.swift */; };
1212
C800DBB1294C624D00B04CAC /* PrefetchSuggestionsCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C800DBB0294C624D00B04CAC /* PrefetchSuggestionsCommand.swift */; };
13+
C80FFB962A95F58200704A25 /* AcceptPromptToCodeCommand.swift in Sources */ = {isa = PBXBuildFile; fileRef = C80FFB952A95F58200704A25 /* AcceptPromptToCodeCommand.swift */; };
1314
C81291D72994FE6900196E12 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C81291D52994FE6900196E12 /* Main.storyboard */; };
1415
C814588F2939EFDC00135263 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C814588E2939EFDC00135263 /* Cocoa.framework */; };
1516
C81458942939EFDC00135263 /* SourceEditorExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = C81458932939EFDC00135263 /* SourceEditorExtension.swift */; };
@@ -139,6 +140,7 @@
139140
C8009BFE2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ToggleRealtimeSuggestionsCommand.swift; sourceTree = "<group>"; };
140141
C8009C022941C576007AA7E8 /* RealtimeSuggestionCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RealtimeSuggestionCommand.swift; sourceTree = "<group>"; };
141142
C800DBB0294C624D00B04CAC /* PrefetchSuggestionsCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrefetchSuggestionsCommand.swift; sourceTree = "<group>"; };
143+
C80FFB952A95F58200704A25 /* AcceptPromptToCodeCommand.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AcceptPromptToCodeCommand.swift; sourceTree = "<group>"; };
142144
C81291D52994FE6900196E12 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
143145
C81291D92994FE7900196E12 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
144146
C814588C2939EFDC00135263 /* Copilot.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = Copilot.appex; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -241,6 +243,7 @@
241243
C8520300293C4D9000460097 /* Helpers.swift */,
242244
C81458952939EFDC00135263 /* GetSuggestionsCommand.swift */,
243245
C87B03A4293B261200C77EAE /* AcceptSuggestionCommand.swift */,
246+
C80FFB952A95F58200704A25 /* AcceptPromptToCodeCommand.swift */,
244247
C87B03A6293B261900C77EAE /* RejectSuggestionCommand.swift */,
245248
C87B03A8293B262600C77EAE /* NextSuggestionCommand.swift */,
246249
C87B03AA293B262E00C77EAE /* PreviousSuggestionCommand.swift */,
@@ -557,6 +560,7 @@
557560
C861A6A329E5503F005C41A3 /* PromptToCodeCommand.swift in Sources */,
558561
C8520301293C4D9000460097 /* Helpers.swift in Sources */,
559562
C8009BFF2941C551007AA7E8 /* ToggleRealtimeSuggestionsCommand.swift in Sources */,
563+
C80FFB962A95F58200704A25 /* AcceptPromptToCodeCommand.swift in Sources */,
560564
C87B03A5293B261200C77EAE /* AcceptSuggestionCommand.swift in Sources */,
561565
C87B03A9293B262600C77EAE /* NextSuggestionCommand.swift in Sources */,
562566
C87B03AB293B262E00C77EAE /* PreviousSuggestionCommand.swift in Sources */,

Copilot for Xcode.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Core/Package.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ let package = Package(
5050
url: "https://github.com/pointfreeco/swift-composable-architecture",
5151
from: "0.55.0"
5252
),
53-
.package(url: "https://github.com/apple/swift-syntax.git", branch: "main"),
5453
].pro,
5554
targets: [
5655
// MARK: - Main
@@ -158,9 +157,11 @@ let package = Package(
158157
.target(
159158
name: "PromptToCodeService",
160159
dependencies: [
160+
.product(name: "FocusedCodeFinder", package: "Tool"),
161161
.product(name: "SuggestionModel", package: "Tool"),
162162
.product(name: "Environment", package: "Tool"),
163163
.product(name: "OpenAIService", package: "Tool"),
164+
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
164165
]
165166
),
166167
.testTarget(name: "PromptToCodeServiceTests", dependencies: ["PromptToCodeService"]),
@@ -227,6 +228,7 @@ let package = Package(
227228
.target(
228229
name: "SuggestionWidget",
229230
dependencies: [
231+
"PromptToCodeService",
230232
"ChatGPTChatTab",
231233
.product(name: "UserDefaultsObserver", package: "Tool"),
232234
.product(name: "SharedUIComponents", package: "Tool"),
@@ -258,6 +260,13 @@ let package = Package(
258260
dependencies: [
259261
"GitHubCopilotService",
260262
.product(name: "Preferences", package: "Tool"),
263+
.product(name: "Keychain", package: "Tool"),
264+
]
265+
),
266+
.testTarget(
267+
name: "ServiceUpdateMigrationTests",
268+
dependencies: [
269+
"ServiceUpdateMigration",
261270
]
262271
),
263272
.target(
@@ -361,12 +370,9 @@ let package = Package(
361370
name: "ActiveDocumentChatContextCollector",
362371
dependencies: [
363372
"ChatContextCollector",
364-
.product(name: "LangChain", package: "Tool"),
365373
.product(name: "OpenAIService", package: "Tool"),
366374
.product(name: "Preferences", package: "Tool"),
367-
.product(name: "ASTParser", package: "Tool"),
368-
.product(name: "SwiftSyntax", package: "swift-syntax"),
369-
.product(name: "SwiftParser", package: "swift-syntax"),
375+
.product(name: "FocusedCodeFinder", package: "Tool"),
370376
],
371377
path: "Sources/ChatContextCollectors/ActiveDocumentChatContextCollector"
372378
),

Core/Sources/ChatContextCollector/ChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public protocol ChatContextCollector {
1414
func generateContext(
1515
history: [ChatMessage],
1616
scopes: Set<String>,
17-
content: String
17+
content: String,
18+
configuration: ChatGPTConfiguration
1819
) -> ChatContext?
1920
}
2021

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/ActiveDocumentChatContextCollector.swift

Lines changed: 3 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import ASTParser
22
import ChatContextCollector
3+
import FocusedCodeFinder
34
import Foundation
45
import OpenAIService
56
import Preferences
@@ -14,7 +15,8 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
1415
public func generateContext(
1516
history: [ChatMessage],
1617
scopes: Set<String>,
17-
content: String
18+
content: String,
19+
configuration: ChatGPTConfiguration
1820
) -> ChatContext? {
1921
guard let info = getEditorInformation() else { return nil }
2022
let context = getActiveDocumentContext(info)
@@ -188,107 +190,3 @@ public final class ActiveDocumentChatContextCollector: ChatContextCollector {
188190
}
189191
}
190192

191-
struct ActiveDocumentContext {
192-
var filePath: String
193-
var relativePath: String
194-
var language: CodeLanguage
195-
var fileContent: String
196-
var lines: [String]
197-
var selectedCode: String
198-
var selectionRange: CursorRange
199-
var lineAnnotations: [EditorInformation.LineAnnotation]
200-
var imports: [String]
201-
202-
struct FocusedContext {
203-
var context: [String]
204-
var contextRange: CursorRange
205-
var codeRange: CursorRange
206-
var code: String
207-
var lineAnnotations: [EditorInformation.LineAnnotation]
208-
var otherLineAnnotations: [EditorInformation.LineAnnotation]
209-
}
210-
211-
var focusedContext: FocusedContext?
212-
213-
mutating func moveToFocusedCode() {
214-
moveToCodeContainingRange(selectionRange)
215-
}
216-
217-
mutating func moveToCodeAroundLine(_ line: Int) {
218-
moveToCodeContainingRange(.init(
219-
start: .init(line: line, character: 0),
220-
end: .init(line: line, character: 0)
221-
))
222-
}
223-
224-
mutating func expandFocusedRangeToContextRange() {
225-
guard let focusedContext else { return }
226-
moveToCodeContainingRange(focusedContext.contextRange)
227-
}
228-
229-
mutating func moveToCodeContainingRange(_ range: CursorRange) {
230-
let finder: FocusedCodeFinder = {
231-
switch language {
232-
case .builtIn(.swift):
233-
return SwiftFocusedCodeFinder()
234-
default:
235-
return UnknownLanguageFocusedCodeFinder(proposedSearchRange: 5)
236-
}
237-
}()
238-
239-
let codeContext = finder.findFocusedCode(
240-
containingRange: range,
241-
activeDocumentContext: self
242-
)
243-
244-
imports = codeContext.imports
245-
246-
let startLine = codeContext.focusedRange.start.line
247-
let endLine = codeContext.focusedRange.end.line
248-
var matchedAnnotations = [EditorInformation.LineAnnotation]()
249-
var otherAnnotations = [EditorInformation.LineAnnotation]()
250-
for annotation in lineAnnotations {
251-
if annotation.line >= startLine, annotation.line <= endLine {
252-
matchedAnnotations.append(annotation)
253-
} else {
254-
otherAnnotations.append(annotation)
255-
}
256-
}
257-
258-
focusedContext = .init(
259-
context: codeContext.scopeSignatures,
260-
contextRange: codeContext.contextRange,
261-
codeRange: codeContext.focusedRange,
262-
code: codeContext.focusedCode,
263-
lineAnnotations: matchedAnnotations,
264-
otherLineAnnotations: otherAnnotations
265-
)
266-
}
267-
268-
mutating func update(_ info: EditorInformation) {
269-
/// Whenever the file content, relative path, or selection range changes,
270-
/// we should reset the context.
271-
let changed: Bool = {
272-
if info.relativePath != relativePath { return true }
273-
if info.editorContent?.content != fileContent { return true }
274-
if let range = info.editorContent?.selections.first,
275-
range != selectionRange { return true }
276-
return false
277-
}()
278-
279-
filePath = info.documentURL.path
280-
relativePath = info.relativePath
281-
language = info.language
282-
fileContent = info.editorContent?.content ?? ""
283-
lines = info.editorContent?.lines ?? []
284-
selectedCode = info.selectedContent
285-
selectionRange = info.editorContent?.selections.first ?? .zero
286-
lineAnnotations = info.editorContent?.lineAnnotations ?? []
287-
imports = []
288-
289-
if changed {
290-
moveToFocusedCode()
291-
}
292-
}
293-
}
294-

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/GetEditorInfo.swift

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,6 @@ import SuggestionModel
33
import XcodeInspector
44

55
func getEditorInformation() -> EditorInformation? {
6-
guard !XcodeInspector.shared.xcodes.isEmpty else { return nil }
7-
8-
let editorContent = XcodeInspector.shared.focusedEditor?.content
9-
let documentURL = XcodeInspector.shared.activeDocumentURL
10-
let projectURL = XcodeInspector.shared.activeProjectURL
11-
let language = languageIdentifierFromFileURL(documentURL)
12-
let relativePath = documentURL.path
13-
.replacingOccurrences(of: projectURL.path, with: "")
14-
15-
if let editorContent, let range = editorContent.selections.first {
16-
let (selectedContent, selectedLines) = EditorInformation.code(
17-
in: editorContent.lines,
18-
inside: range
19-
)
20-
return .init(
21-
editorContent: editorContent,
22-
selectedContent: selectedContent,
23-
selectedLines: selectedLines,
24-
documentURL: documentURL,
25-
projectURL: projectURL,
26-
relativePath: relativePath,
27-
language: language
28-
)
29-
}
30-
31-
return .init(
32-
editorContent: editorContent,
33-
selectedContent: "",
34-
selectedLines: [],
35-
documentURL: documentURL,
36-
projectURL: projectURL,
37-
relativePath: relativePath,
38-
language: language
39-
)
6+
return XcodeInspector.shared.focusedEditorContent
407
}
418

Core/Sources/ChatContextCollectors/ActiveDocumentChatContextCollector/LegacyActiveDocumentChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public struct LegacyActiveDocumentChatContextCollector: ChatContextCollector {
1111
public func generateContext(
1212
history: [ChatMessage],
1313
scopes: Set<String>,
14-
content: String
14+
content: String,
15+
configuration: ChatGPTConfiguration
1516
) -> ChatContext? {
1617
guard let content = getEditorInformation() else { return nil }
1718
let relativePath = content.relativePath

Core/Sources/ChatContextCollectors/SystemInfoChatContextCollector/SystemInfoChatContextCollector.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ public final class SystemInfoChatContextCollector: ChatContextCollector {
1414
public func generateContext(
1515
history: [ChatMessage],
1616
scopes: Set<String>,
17-
content: String
17+
content: String,
18+
configuration: ChatGPTConfiguration
1819
) -> ChatContext? {
1920
return .init(
2021
systemPrompt: """

Core/Sources/ChatContextCollectors/WebChatContextCollector/SearchFunction.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct SearchFunction: ChatGPTFunction {
2828
}.joined(separator: "\n")
2929
}
3030
}
31+
32+
let maxTokens: Int
3133

3234
var reportProgress: (String) async -> Void = { _ in }
3335

@@ -72,9 +74,10 @@ struct SearchFunction: ChatGPTFunction {
7274
subscriptionKey: UserDefaults.shared.value(for: \.bingSearchSubscriptionKey),
7375
searchURL: UserDefaults.shared.value(for: \.bingSearchEndpoint)
7476
)
77+
7578
let result = try await bingSearch.search(
7679
query: arguments.query,
77-
numberOfResult: UserDefaults.shared.value(for: \.chatGPTMaxToken) > 5000 ? 5 : 3,
80+
numberOfResult: maxTokens > 5000 ? 5 : 3,
7881
freshness: arguments.freshness
7982
)
8083

Core/Sources/ChatContextCollectors/WebChatContextCollector/WebChatContextCollector.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ public final class WebChatContextCollector: ChatContextCollector {
1010
public func generateContext(
1111
history: [ChatMessage],
1212
scopes: Set<String>,
13-
content: String
13+
content: String,
14+
configuration: ChatGPTConfiguration
1415
) -> ChatContext? {
1516
guard scopes.contains("web") || scopes.contains("w") else { return nil }
1617
let links = Self.detectLinks(from: history) + Self.detectLinks(from: content)
1718
let functions: [(any ChatGPTFunction)?] = [
18-
SearchFunction(),
19+
SearchFunction(maxTokens: configuration.maxTokens),
1920
// allow this function only when there is a link in the memory.
2021
links.isEmpty ? nil : QueryWebsiteFunction(),
2122
]

0 commit comments

Comments
 (0)