File tree Expand file tree Collapse file tree 1 file changed +9
-11
lines changed
Core/Sources/CodeiumService Expand file tree Collapse file tree 1 file changed +9
-11
lines changed Original file line number Diff line number Diff line change @@ -57,44 +57,42 @@ final class CodeiumLanguageServer {
5757
5858 func start( ) {
5959 guard !process. isRunning else { return }
60- port = nil
6160 do {
6261 try process. run ( )
6362
64- Task {
63+ Task { @ MainActor in
6564 func findPort( ) -> String ? {
6665 // find a file in managerDirectoryURL whose name looks like a port, return the
6766 // name if found
6867 let fileManager = FileManager . default
69- let enumerator = fileManager. enumerator (
70- at: managerDirectoryURL,
71- includingPropertiesForKeys: nil
72- )
73- while let fileURL = enumerator? . nextObject ( ) as? URL {
74- if fileURL. lastPathComponent. range (
68+ guard let filePaths = try ? fileManager
69+ . contentsOfDirectory ( atPath: managerDirectoryURL. path) else { return nil }
70+ for path in filePaths {
71+ let filename = URL ( fileURLWithPath: path) . lastPathComponent
72+ if filename. range (
7573 of: #"^\d+$"# ,
7674 options: . regularExpression
7775 ) != nil {
78- return fileURL . lastPathComponent
76+ return filename
7977 }
8078 }
8179 return nil
8280 }
8381
8482 try await Task . sleep ( nanoseconds: 2_000_000 )
85- port = findPort ( )
8683 var waited = 0
8784
8885 while true {
89- try await Task . sleep ( nanoseconds: 1_000_000_000 )
9086 waited += 1
9187 if let port = findPort ( ) {
9288 finishStarting ( port: port)
9389 return
9490 }
9591 if waited >= 60 {
9692 process. terminate ( )
93+ return
9794 }
95+ try await Task . sleep ( nanoseconds: 1_000_000_000 )
9896 }
9997 }
10098 } catch {
You can’t perform that action at this time.
0 commit comments