-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1128 from bummoblizard/lsp
LSP (Python and Java Intellisense) #1104
- Loading branch information
Showing
185 changed files
with
1,619 additions
and
131,766 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,36 @@ | ||
// | ||
// LanguageService.swift | ||
// Code | ||
// | ||
// Created by Ken Chung on 09/08/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
class LanguageService { | ||
struct Configuration { | ||
let languageIdentifier: String | ||
let extensions: [String] | ||
let args: [String] | ||
} | ||
|
||
var candidateLanguageIdentifier: String? = nil | ||
|
||
static let shared = LanguageService() | ||
static let configurations: [Configuration] = [ | ||
Configuration( | ||
languageIdentifier: "python", | ||
extensions: ["py"], | ||
args: ["jedi-language-server", "-v"]), | ||
Configuration( | ||
languageIdentifier: "java", | ||
extensions: ["java"], | ||
args: ["java", "-jar", "${JAVA_LSP_FAT_JAR_PATH}"]), | ||
] | ||
|
||
static func configurationFor(url: URL) -> Configuration? { | ||
return LanguageService.configurations.first(where: { | ||
$0.extensions.contains(url.pathExtension) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,121 @@ | ||
// | ||
// AppExtensionService.swift | ||
// Code App | ||
// | ||
// Created by Ken Chung on 02/07/2024. | ||
// | ||
|
||
import Dynamic | ||
import Foundation | ||
import ios_system | ||
|
||
class AppExtensionService: NSObject { | ||
static let PORT = 50002 | ||
static let shared = AppExtensionService() | ||
private var task: URLSessionWebSocketTask? = nil | ||
|
||
func startServer() { | ||
let BLE: AnyClass = (NSClassFromString("TlNFeHRlbnNpb24=".base64Decoded()!)!) | ||
let ext = Dynamic(BLE).extensionWithIdentifier( | ||
"thebaselab.VS-Code.extension", error: nil) | ||
let frameworkDir = Bundle.main.privateFrameworksPath! | ||
let frameworkDirBookmark = try! URL(fileURLWithPath: frameworkDir).bookmarkData() | ||
let item = NSExtensionItem() | ||
item.userInfo = [ | ||
"frameworksDirectoryBookmark": frameworkDirBookmark, | ||
"port": AppExtensionService.PORT, | ||
] | ||
ext.setRequestInterruptionBlock( | ||
{ uuid in | ||
print("Extension server crashed, attempting to restart") | ||
self.startServer() | ||
} as RequestInterruptionBlock) | ||
|
||
ext.beginExtensionRequestWithInputItems( | ||
[item], | ||
completion: { uuid in | ||
let pid = ext.pid(forRequestIdentifier: uuid) | ||
if let uuid = uuid { | ||
print("Started extension request: \(uuid). Extension PID is \(pid)") | ||
} | ||
print("Extension server listening on 127.0.0.1:\(AppExtensionService.PORT)") | ||
} as RequestBeginBlock) | ||
|
||
} | ||
|
||
func stopServer() { | ||
let notificationName = CFNotificationName( | ||
"com.thebaselab.code.node.stop" as CFString) | ||
let notificationCenter = CFNotificationCenterGetDarwinNotifyCenter() | ||
CFNotificationCenterPostNotification( | ||
notificationCenter, notificationName, nil, nil, false) | ||
} | ||
|
||
func terminate() { | ||
self.task?.cancel() | ||
} | ||
|
||
func prepareServer() async { | ||
if LanguageService.shared.candidateLanguageIdentifier == nil { return } | ||
stopServer() | ||
|
||
try? await Task.sleep(nanoseconds: 1 * 1_000_000_000) | ||
} | ||
|
||
func call( | ||
args: [String], | ||
t_stdin: UnsafeMutablePointer<FILE>, | ||
t_stdout: UnsafeMutablePointer<FILE> | ||
) async throws { | ||
await prepareServer() | ||
|
||
defer { | ||
self.task = nil | ||
signal(SIGINT, SIG_DFL) | ||
} | ||
|
||
let signalCallback: sig_t = { signal in | ||
// TODO: send real signal instead | ||
AppExtensionService.shared.terminate() | ||
} | ||
signal(SIGINT, signalCallback) | ||
|
||
let task = URLSession.shared.webSocketTask( | ||
with: URL(string: "ws://127.0.0.1:\(String(AppExtensionService.PORT))/websocket")!) | ||
self.task = task | ||
task.resume() | ||
|
||
let handle = FileHandle(fileDescriptor: fileno(t_stdin), closeOnDealloc: false) | ||
handle.readabilityHandler = { fileHandle in | ||
if let str = String(data: fileHandle.availableData, encoding: .utf8) { | ||
Task { | ||
try await task.send(.string(str)) | ||
print("Sending -> \(str)") | ||
} | ||
} | ||
} | ||
|
||
let frame = ExecutionRequestFrame( | ||
args: args, | ||
redirectStderr: true, | ||
workingDirectoryBookmark: try? URL( | ||
fileURLWithPath: FileManager.default.currentDirectoryPath | ||
).bookmarkData(), | ||
isLanguageService: false | ||
) | ||
|
||
try await task.send(.string(frame.stringRepresentation)) | ||
|
||
print("Sending -> \(frame.stringRepresentation)") | ||
|
||
while let message = try? await task.receive() { | ||
switch message { | ||
case .string(let text): | ||
print("Receiving <- \(text)") | ||
fputs(text, t_stdout) | ||
default: | ||
continue | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.