Skip to content

Commit 38d0966

Browse files
committed
Rollback a0efc09 Disable fetchCurrentProjectRootURL
1 parent d40d4f0 commit 38d0966

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

Core/Sources/Environment/Environment.swift

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,43 +41,42 @@ public enum Environment {
4141
}
4242

4343
#warning("""
44-
The current version causes an issue in real-time suggestion that when completion panel is own,
45-
the command handler can not find the correct workspace, so we are not using it for now.
44+
TODO: The current version causes an issue in real-time suggestion that when completion panel is open,
45+
the command handler can not find the correct workspace.
4646
""")
4747
public static var fetchCurrentProjectRootURL: (_ fileURL: URL?) async throws
4848
-> URL? = { fileURL in
49-
return URL(fileURLWithPath: "/")
50-
// let appleScript = """
51-
// tell application "Xcode"
52-
// return path of document of the first window
53-
// end tell
54-
// """
55-
//
56-
// let path = (try? await runAppleScript(appleScript)) ?? ""
57-
// if !path.isEmpty {
58-
// let trimmedNewLine = path.trimmingCharacters(in: .newlines)
59-
// var url = URL(fileURLWithPath: trimmedNewLine)
60-
// while !FileManager.default.fileIsDirectory(atPath: url.path) ||
61-
// !url.pathExtension.isEmpty
62-
// {
63-
// url = url.deletingLastPathComponent()
64-
// }
65-
// return url
66-
// }
67-
//
68-
// guard var currentURL = fileURL else { return nil }
69-
// var firstDirectoryURL: URL?
70-
// while currentURL.pathComponents.count > 1 {
71-
// defer { currentURL.deleteLastPathComponent() }
72-
// guard FileManager.default.fileIsDirectory(atPath: currentURL.path) else { continue }
73-
// if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
74-
// let gitURL = currentURL.appendingPathComponent(".git")
75-
// if FileManager.default.fileIsDirectory(atPath: gitURL.path) {
76-
// return currentURL
77-
// }
78-
// }
79-
//
80-
// return firstDirectoryURL ?? fileURL
49+
let appleScript = """
50+
tell application "Xcode"
51+
return path of document of the first window
52+
end tell
53+
"""
54+
55+
let path = (try? await runAppleScript(appleScript)) ?? ""
56+
if !path.isEmpty {
57+
let trimmedNewLine = path.trimmingCharacters(in: .newlines)
58+
var url = URL(fileURLWithPath: trimmedNewLine)
59+
while !FileManager.default.fileIsDirectory(atPath: url.path) ||
60+
!url.pathExtension.isEmpty
61+
{
62+
url = url.deletingLastPathComponent()
63+
}
64+
return url
65+
}
66+
67+
guard var currentURL = fileURL else { return nil }
68+
var firstDirectoryURL: URL?
69+
while currentURL.pathComponents.count > 1 {
70+
defer { currentURL.deleteLastPathComponent() }
71+
guard FileManager.default.fileIsDirectory(atPath: currentURL.path) else { continue }
72+
if firstDirectoryURL == nil { firstDirectoryURL = currentURL }
73+
let gitURL = currentURL.appendingPathComponent(".git")
74+
if FileManager.default.fileIsDirectory(atPath: gitURL.path) {
75+
return currentURL
76+
}
77+
}
78+
79+
return firstDirectoryURL ?? fileURL
8180
}
8281

8382
public static var fetchCurrentFileURL: () async throws -> URL = {

Core/Sources/Service/RealtimeSuggestionController.swift

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public class RealtimeSuggestionController {
166166
#warning(
167167
"TODO: Any method to avoid using AppleScript to check that completion panel is presented?"
168168
)
169-
if isCommentMode, await Environment.frontmostXcodeWindowIsEditor() {
169+
if await Environment.frontmostXcodeWindowIsEditor() {
170170
if Task.isCancelled { return }
171171
self.triggerPrefetchDebounced(force: true)
172172
}
@@ -191,12 +191,7 @@ public class RealtimeSuggestionController {
191191

192192
os_log(.info, "Prefetch suggestions.")
193193

194-
let isCommentMode = PresentationMode(
195-
rawValue: UserDefaults.shared
196-
.integer(forKey: SettingsKey.suggestionPresentationMode)
197-
) == .comment
198-
199-
if isCommentMode, !force, await !Environment.frontmostXcodeWindowIsEditor() {
194+
if !force, await !Environment.frontmostXcodeWindowIsEditor() {
200195
os_log(.info, "Completion panel is open, blocked.")
201196
return
202197
}

0 commit comments

Comments
 (0)