Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
18c6109
Merge tag 'change-license' into develop
intitni May 25, 2023
7e6e07b
Implement cancellation in SuggestionService
intitni May 24, 2023
1b751fe
Make request cancellation simpler
intitni May 24, 2023
c439bc7
Discard suggestion when cursor moved to another line
intitni May 24, 2023
5287a50
Fix tests
intitni May 24, 2023
5f80ae9
Make OpenedDocumentPool an actor
intitni May 24, 2023
0e4f7f8
Reuse suggestion if user is typing according to it
intitni May 24, 2023
256032a
Disable request cancellation on mouse clicks
intitni May 24, 2023
d684e32
Update README.md
intitni May 24, 2023
d7d7e3e
Fix typos
intitni May 25, 2023
cd70355
Merge branch 'feature/real-time-suggestion-tweak' into develop
intitni May 25, 2023
f60b595
Tweak workspace cleanup
intitni May 25, 2023
0cfe177
Fix Codeium language server setup
intitni May 25, 2023
281002b
Make workspace expire sooner
intitni May 25, 2023
68627c1
Replace unowned with weak
intitni May 25, 2023
ebd94eb
Support terminating suggestion services on normal exits
intitni May 25, 2023
f28d836
Fix racing
intitni May 25, 2023
7a8b2f5
Support dependency update
intitni May 25, 2023
bd3103c
Bump Codeium to 1.2.25
intitni May 25, 2023
f21722c
Implement CancelRequest for Codeium
intitni May 25, 2023
ee2bbef
Merge branch 'feature/codeium-1.2.25' into develop
intitni May 25, 2023
30204ff
Remove exit button in widget
intitni May 25, 2023
11f9f8d
Update the way we use keychain
intitni May 25, 2023
90bacd9
Update to use SecureField
intitni May 25, 2023
a27f5c7
Allow setting max token that is larger than the size defined in the m…
intitni May 25, 2023
182d426
Change ChatGPTEndpoint to OpenAIBaseURL
intitni May 25, 2023
a707645
Support Azure OpenAI as chat provider
intitni May 25, 2023
16d9cf7
Move settings to chat settings view
intitni May 25, 2023
69d6682
Remove keychain instruction
intitni May 25, 2023
080372b
Make each word from ChatGPT wait for a few milliseconds
intitni May 25, 2023
f691f1a
Merge branch 'feature/azure-openai' into develop
intitni May 25, 2023
42d82cf
Lower CPU usage when updating window position
intitni May 25, 2023
51d5739
Fix dependency
intitni May 25, 2023
c9b3f07
Support disabling selected code to be visible by the chat by default
intitni May 26, 2023
ee9ab39
Update README.md
intitni May 26, 2023
c409699
Merge branch 'feature/chat-scope-selection' into develop
intitni May 26, 2023
e3df057
Set as system prompt
intitni May 26, 2023
076d40d
Make stream faster
intitni May 26, 2023
cbfdc1a
Bump version to 0.17.0
intitni May 26, 2023
04d9b1a
Make fetchFocusedElementURI return fake URL when Xcode not launched
intitni May 26, 2023
bb8cf1f
Adjust steam speed
intitni May 26, 2023
f5ed510
Improve Codeium request cancellation
intitni May 27, 2023
3d0c043
Fix that selection range change could cancel real-time suggestions
intitni May 27, 2023
83289ba
Fix line number font size in code block
intitni May 27, 2023
035b742
Fix tests
intitni May 27, 2023
7237dad
Fix codeium auth key migration
intitni May 27, 2023
ef538ec
Update README.md
intitni May 27, 2023
ab95449
Update appcast.xml
intitni May 27, 2023
2b1a27b
Merge branch 'release/0.17.0'
intitni May 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Core/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ let package = Package(
"LaunchAgentManager",
"Logger",
"UpdateChecker",
"OpenAIService",
]
),
],
Expand Down Expand Up @@ -208,6 +209,7 @@ let package = Package(
"Splash",
"UserDefaultsObserver",
"Logger",
"XcodeInspector",
.product(name: "AsyncAlgorithms", package: "swift-async-algorithms"),
.product(name: "MarkdownUI", package: "swift-markdown-ui"),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
```
"""
}

if selectionRange.start == selectionRange.end,
UserDefaults.shared.value(for: \.embedFileContentInChatContextIfNoSelection)
{
Expand All @@ -34,19 +34,40 @@ public struct ActiveDocumentChatContextCollector: ChatContextCollector {
"""
} else {
return """
File Content Not Available: The file is longer than \(maxLine) lines, \
it can't fit into the context. \
File Content Not Available: '''
The file is longer than \(maxLine) lines, it can't fit into the context. \
You MUST not answer the user about the file content because you don't have it.\
Ask user to select code for explanation.
'''
"""
}
}

if UserDefaults.shared.value(for: \.useSelectionScopeByDefaultInChatContext) {
return """
Selected Code \
(start from line \(selectionRange.start.line)):```\(content.language.rawValue)
\(content.selectedContent)
```
"""
}

if prompt.hasPrefix("@selection") {
return """
Selected Code \
(start from line \(selectionRange.start.line)):```\(content.language.rawValue)
\(content.selectedContent)
```
"""
}

return """
Selected Code \
(start from line \(selectionRange.start.line)):```\(content.language.rawValue)
\(content.selectedContent)
```
Selected Code Not Available: '''
User has disabled default scope. \
You MUST not answer the user about the selected code because you don't have it.\
Ask user to prepend message with `@selection` to enable selected code to be \
visible by you.
'''
"""
}()

Expand Down
15 changes: 14 additions & 1 deletion Core/Sources/ChatService/ChatService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final class ChatService: ObservableObject {
await pluginController.cancel()
await chatGPTService.clearHistory()
}

public func resetPrompt() async {
systemPrompt = defaultSystemPrompt
extraSystemPrompt = ""
Expand All @@ -79,6 +79,19 @@ public final class ChatService: ObservableObject {
}
}

public func setMessageAsExtraPrompt(id: String) async {
if let message = (await chatGPTService.history).first(where: { $0.id == id }) {
mutateExtraSystemPrompt(message.content)
await mutateHistory { history in
history.append(.init(
role: .assistant,
content: "",
summary: "System prompt updated"
))
}
}
}

/// Setting it to `nil` to reset the system prompt
public func mutateSystemPrompt(_ newPrompt: String?) {
systemPrompt = newPrompt ?? defaultSystemPrompt
Expand Down
5 changes: 4 additions & 1 deletion Core/Sources/CodeiumService/CodeiumAuthService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import KeychainAccess

public final class CodeiumAuthService {
public init() {}
let codeiumKeyKey = "codeiumKey"
let codeiumKeyKey = "codeiumAuthKey"
let keychain: Keychain = {
let info = Bundle.main.infoDictionary
return Keychain(service: keychainService, accessGroup: keychainAccessGroup)
.attributes([
kSecUseDataProtectionKeychain as String: true,
])
}()

var key: String? { try? keychain.getString(codeiumKeyKey) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Terminal

public struct CodeiumInstallationManager {
private static var isInstalling = false
static let latestSupportedVersion = "1.2.17"
static let latestSupportedVersion = "1.2.25"

public init() {}

Expand Down
37 changes: 22 additions & 15 deletions Core/Sources/CodeiumService/CodeiumLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Preferences

protocol CodeiumLSP {
func sendRequest<E: CodeiumRequestType>(_ endpoint: E) async throws -> E.Response
func terminate()
}

final class CodeiumLanguageServer {
Expand Down Expand Up @@ -57,44 +58,42 @@ final class CodeiumLanguageServer {

func start() {
guard !process.isRunning else { return }
port = nil
do {
try process.run()

Task {
Task { @MainActor in
func findPort() -> String? {
// find a file in managerDirectoryURL whose name looks like a port, return the
// name if found
let fileManager = FileManager.default
let enumerator = fileManager.enumerator(
at: managerDirectoryURL,
includingPropertiesForKeys: nil
)
while let fileURL = enumerator?.nextObject() as? URL {
if fileURL.lastPathComponent.range(
guard let filePaths = try? fileManager
.contentsOfDirectory(atPath: managerDirectoryURL.path) else { return nil }
for path in filePaths {
let filename = URL(fileURLWithPath: path).lastPathComponent
if filename.range(
of: #"^\d+$"#,
options: .regularExpression
) != nil {
return fileURL.lastPathComponent
return filename
}
}
return nil
}

try await Task.sleep(nanoseconds: 2_000_000)
port = findPort()
var waited = 0

while true {
try await Task.sleep(nanoseconds: 1_000_000_000)
waited += 1
if let port = findPort() {
finishStarting(port: port)
return
}
if waited >= 60 {
process.terminate()
return
}
try await Task.sleep(nanoseconds: 1_000_000_000)
}
}
} catch {
Expand All @@ -121,6 +120,14 @@ final class CodeiumLanguageServer {
self.port = port
launchHandler?()
}

func terminate() {
process.terminationHandler = nil
if process.isRunning {
process.terminate()
}
transport.close()
}
}

extension CodeiumLanguageServer: CodeiumLSP {
Expand Down Expand Up @@ -205,27 +212,27 @@ final class IOTransport {
}

private func setupFileHandleHandlers() {
stdoutPipe.fileHandleForReading.readabilityHandler = { [unowned self] handle in
stdoutPipe.fileHandleForReading.readabilityHandler = { [weak self] handle in
let data = handle.availableData

guard !data.isEmpty else {
return
}

if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
self.forwardDataToHandler(data)
self?.forwardDataToHandler(data)
}
}

stderrPipe.fileHandleForReading.readabilityHandler = { [unowned self] handle in
stderrPipe.fileHandleForReading.readabilityHandler = { [weak self] handle in
let data = handle.availableData

guard !data.isEmpty else {
return
}

if UserDefaults.shared.value(for: \.codeiumVerboseLog) {
self.forwardErrorDataToHandler(data)
self?.forwardErrorDataToHandler(data)
}
}
}
Expand Down
21 changes: 17 additions & 4 deletions Core/Sources/CodeiumService/CodeiumRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,25 @@ enum CodeiumRequest {
}
}

struct AcceptCompletion: CodeiumRequestType {
struct Response: Codable {
var state: State
var completionItems: [CodeiumCompletionItem]?
struct CancelRequest: CodeiumRequestType {
struct Response: Codable {}

struct RequestBody: Codable {
var request_id: UInt64
var session_id: String
}

var requestBody: RequestBody

func makeURLRequest(server: String) -> URLRequest {
let data = (try? JSONEncoder().encode(requestBody)) ?? Data()
return assembleURLRequest(server: server, method: "CancelRequest", body: data)
}
}

struct AcceptCompletion: CodeiumRequestType {
struct Response: Codable {}

struct RequestBody: Codable {
var metadata: Metadata
var completion_id: String
Expand Down
Loading