Skip to content

Commit

Permalink
Merge branch 'main' into lsp/document-content-sync
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Sep 19, 2024
2 parents d1a0ec9 + b140b5c commit 7351dee
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 70 deletions.
22 changes: 18 additions & 4 deletions CodeEdit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
6CD26C7B2C8EA8A500ADBA38 /* LSPCache+Data.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD26C792C8EA8A500ADBA38 /* LSPCache+Data.swift */; };
6CD26C7D2C8EA8F400ADBA38 /* LanguageServer+DocumentSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD26C7C2C8EA8F400ADBA38 /* LanguageServer+DocumentSync.swift */; };
6CD26C812C8F8A4400ADBA38 /* LanguageIdentifier+CodeLanguage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD26C802C8F8A4400ADBA38 /* LanguageIdentifier+CodeLanguage.swift */; };
6CD26C852C8F907800ADBA38 /* CodeEditSourceEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 6CD26C842C8F907800ADBA38 /* CodeEditSourceEditor */; };
6CD26C872C8F90FD00ADBA38 /* LazyServiceWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD26C862C8F90FD00ADBA38 /* LazyServiceWrapper.swift */; };
6CD26C8A2C8F91ED00ADBA38 /* LanguageServer+DocumentTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD26C892C8F91ED00ADBA38 /* LanguageServer+DocumentTests.swift */; };
6CD3CA552C8B508200D83DCD /* CodeEditSourceEditor in Frameworks */ = {isa = PBXBuildFile; productRef = 6CD3CA542C8B508200D83DCD /* CodeEditSourceEditor */; };
Expand Down Expand Up @@ -1301,7 +1302,7 @@
6C85BB442C210EFD00EB5DEF /* SwiftUIIntrospect in Frameworks */,
6CB446402B6DFF3A00539ED0 /* CodeEditSourceEditor in Frameworks */,
2816F594280CF50500DD548B /* CodeEditSymbols in Frameworks */,
6C278CCA2C949D4A0066F6D9 /* CodeEditSourceEditor in Frameworks */,
6CD26C852C8F907800ADBA38 /* CodeEditSourceEditor in Frameworks */,
30CB64942C16CA9100CC8A9E /* LanguageClient in Frameworks */,
6C6BD6F829CD14D100235D17 /* CodeEditKit in Frameworks */,
6C0824A12C5C0C9700A0751E /* SwiftTerm in Frameworks */,
Expand Down Expand Up @@ -3671,7 +3672,7 @@
6CE21E862C650D2C0031B056 /* SwiftTerm */,
6C4E37FB2C73E00700AEE7B5 /* SwiftTerm */,
6CD3CA542C8B508200D83DCD /* CodeEditSourceEditor */,
6C278CC92C949D4A0066F6D9 /* CodeEditSourceEditor */,
6CD26C842C8F907800ADBA38 /* CodeEditSourceEditor */,
);
productName = CodeEdit;
productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */;
Expand Down Expand Up @@ -3768,7 +3769,7 @@
303E88452C276FD100EEA8D9 /* XCRemoteSwiftPackageReference "LanguageClient" */,
303E88462C276FD600EEA8D9 /* XCRemoteSwiftPackageReference "LanguageServerProtocol" */,
6C4E37FA2C73E00700AEE7B5 /* XCRemoteSwiftPackageReference "SwiftTerm" */,
6C278CC82C949D4A0066F6D9 /* XCLocalSwiftPackageReference "../CodeEditSourceEditor" */,
6CD26C832C8F907800ADBA38 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
);
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -5631,7 +5632,7 @@
repositoryURL = "https://github.com/groue/GRDB.swift.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.2.0;
minimumVersion = 6.0.0;
};
};
6C6BD6F229CD142C00235D17 /* XCRemoteSwiftPackageReference "collectionconcurrencykit" */ = {
Expand All @@ -5658,6 +5659,14 @@
minimumVersion = 1.2.0;
};
};
6CD26C832C8F907800ADBA38 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/CodeEditApp/CodeEditSourceEditor";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.8.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -5751,6 +5760,11 @@
isa = XCSwiftPackageProductDependency;
productName = CodeEditSourceEditor;
};
6CD26C842C8F907800ADBA38 /* CodeEditSourceEditor */ = {
isa = XCSwiftPackageProductDependency;
package = 6CD26C832C8F907800ADBA38 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */;
productName = CodeEditSourceEditor;
};
6CD3CA542C8B508200D83DCD /* CodeEditSourceEditor */ = {
isa = XCSwiftPackageProductDependency;
productName = CodeEditSourceEditor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
{
"identity" : "codeeditkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CodeEditApp/CodeEditKit.git",
"location" : "https://github.com/CodeEditApp/CodeEditKit",
"state" : {
"revision" : "ad28213a968586abb0cb21a8a56a3587227895f1",
"version" : "0.1.2"
Expand Down Expand Up @@ -87,8 +87,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/groue/GRDB.swift.git",
"state" : {
"revision" : "dd7e7f39e8e4d7a22d258d9809a882f914690b01",
"version" : "5.26.1"
"revision" : "2cf6c756e1e5ef6901ebae16576a7e4e4b834622",
"version" : "6.29.3"
}
},
{
Expand Down Expand Up @@ -177,8 +177,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-collections.git",
"state" : {
"revision" : "3d2dc41a01f9e49d84f0a3925fb858bed64f702d",
"version" : "1.1.2"
"revision" : "9bf03ff58ce34478e66aaee630e491823326fd06",
"version" : "1.1.3"
}
},
{
Expand Down
3 changes: 0 additions & 3 deletions CodeEdit/Features/Editor/Views/EditorAreaView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,6 @@ struct EditorAreaView: View {
.opacity(dimEditorsWithoutFocus && editor != editorManager.activeEditor ? 0.5 : 1)
} else {
LoadingFileView(selected.file.name)
.onChange(of: selected.file.fileDocument) { _ in
self.codeFile = selected.file.fileDocument
}
}
} else {
CEContentUnavailableView("No Editor")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,41 @@ import Foundation
import LanguageServerProtocol

extension LanguageServer {
// swiftlint:disable line_length
/// Determines the type of document sync the server supports.
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_synchronization_sc
fileprivate func resolveDocumentSyncKind() -> TextDocumentSyncKind {
// swiftlint:enable line_length
var syncKind: TextDocumentSyncKind = .none
switch serverCapabilities.textDocumentSync {
case .optionA(let options):
syncKind = options.change ?? .none
case .optionB(let kind):
syncKind = kind
default:
syncKind = .none
}
return syncKind
}

// MARK: - API
/// Determines whether or not the server supports document tracking.
fileprivate func resolveOpenCloseSupport() -> Bool {
switch serverCapabilities.textDocumentSync {
case .optionA(let options):
return options.openClose ?? false
case .optionB:
return true
default:
return true
}
}

// Used to avoid a lint error (`large_tuple`) for the return type of `getIsolatedDocumentContent`
fileprivate struct DocumentContent {
let uri: String
let language: LanguageIdentifier
let content: String
}

/// Tells the language server we've opened a document and would like to begin working with it.
/// - Parameter document: The code document to open.
Expand All @@ -28,16 +61,26 @@ extension LanguageServer {
uri: content.uri,
languageId: content.language,
version: 0,
text: content.string
text: content.content
)
try await lspInstance.textDocumentDidOpen(DidOpenTextDocumentParams(textDocument: textDocument))
await setCoordinatorServer(for: document)
} catch {
logger.warning("addDocument: Error \(error)")
throw error
}
}

/// Helper function for grabbing a document's content from the main actor.
@MainActor
private func getIsolatedDocumentContent(_ document: CodeFileDocument) -> DocumentContent? {
guard let uri = document.languageServerURI,
let language = document.getLanguage().lspLanguage,
let content = document.content?.string else {
return nil
}
return DocumentContent(uri: uri, language: language, content: content)
}

/// Stops tracking a file and notifies the language server.
/// - Parameter uri: The URI of the document to close.
/// - Throws: Throws errors produced by the language server connection.
Expand Down Expand Up @@ -92,59 +135,4 @@ extension LanguageServer {
throw error
}
}

// MARK: - Helpers

// swiftlint:disable line_length
/// Determines the type of document sync the server supports.
/// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_synchronization_sc
fileprivate func resolveDocumentSyncKind() -> TextDocumentSyncKind {
// swiftlint:enable line_length
var syncKind: TextDocumentSyncKind = .none
switch serverCapabilities.textDocumentSync {
case .optionA(let options):
syncKind = options.change ?? .none
case .optionB(let kind):
syncKind = kind
default:
syncKind = .none
}
return syncKind
}

/// Determines whether or not the server supports document tracking.
fileprivate func resolveOpenCloseSupport() -> Bool {
switch serverCapabilities.textDocumentSync {
case .optionA(let options):
return options.openClose ?? false
case .optionB:
return true
default:
return true
}
}

// Used to avoid a lint error (`large_tuple`) for the return type of `getIsolatedDocumentContent`
fileprivate struct DocumentContent {
let uri: String
let language: LanguageIdentifier
let string: String
}

/// Helper function for grabbing a document's content from the main actor.
@MainActor
fileprivate func getIsolatedDocumentContent(_ document: CodeFileDocument) -> DocumentContent? {
guard let uri = document.languageServerURI,
let language = document.getLanguage().lspLanguage,
let content = document.content?.string else {
return nil
}
return DocumentContent(uri: uri, language: language, string: content)
}

/// Small helper, removed from the main function to make async syntax more straightforward.
@MainActor
fileprivate func setCoordinatorServer(for document: CodeFileDocument) {
document.lspCoordinator.languageServer = self
}
}

0 comments on commit 7351dee

Please sign in to comment.