Skip to content

Commit

Permalink
Rename note to notification throughout the codebase apple#865
Browse files Browse the repository at this point in the history
  • Loading branch information
issamarabi committed Oct 11, 2023
1 parent f0ee6b1 commit ac36205
Show file tree
Hide file tree
Showing 17 changed files with 426 additions and 426 deletions.
34 changes: 17 additions & 17 deletions Sources/LSPTestSupport/TestJSONRPCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public final class TestClient: MessageHandler {
public var allowUnexpectedNotification: Bool = true

public func appendOneShotNotificationHandler<N>(_ handler: @escaping (Notification<N>) -> Void) {
oneShotNotificationHandlers.append({ anyNote in
guard let note = anyNote as? Notification<N> else {
fatalError("received notification of the wrong type \(anyNote); expected \(N.self)")
oneShotNotificationHandlers.append({ anyNotification in
guard let notification = anyNotification as? Notification<N> else {
fatalError("received notification of the wrong type \(anyNotification); expected \(N.self)")
}
handler(note)
handler(notification)
})
}

Expand Down Expand Up @@ -171,15 +171,15 @@ extension TestClient: Connection {

/// Send a notification and expect a notification in reply synchronously.
/// For testing notifications that behave like requests - e.g. didChange & publishDiagnostics.
public func sendNoteSync<NReply>(
public func sendnotificationSync<NReply>(
_ notification: some NotificationType,
_ handler: @escaping (Notification<NReply>) -> Void
) {

let expectation = XCTestExpectation(description: "sendNoteSync - note received")
let expectation = XCTestExpectation(description: "sendnotificationSync - notification received")

handleNextNotification { (note: Notification<NReply>) in
handler(note)
handleNextNotification { (notification: Notification<NReply>) in
handler(notification)
expectation.fulfill()
}

Expand All @@ -194,21 +194,21 @@ extension TestClient: Connection {

/// Send a notification and expect two notifications in reply synchronously.
/// For testing notifications that behave like requests - e.g. didChange & publishDiagnostics.
public func sendNoteSync<NSend, NReply1, NReply2>(
public func sendnotificationSync<NSend, NReply1, NReply2>(
_ notification: NSend,
_ handler1: @escaping (Notification<NReply1>) -> Void,
_ handler2: @escaping (Notification<NReply2>) -> Void
) where NSend: NotificationType {

let expectation = XCTestExpectation(description: "sendNoteSync - note received")
let expectation = XCTestExpectation(description: "sendnotificationSync - notification received")
expectation.expectedFulfillmentCount = 2

handleNextNotification { (note: Notification<NReply1>) in
handler1(note)
handleNextNotification { (notification: Notification<NReply1>) in
handler1(notification)
expectation.fulfill()
}
appendOneShotNotificationHandler { (note: Notification<NReply2>) in
handler2(note)
appendOneShotNotificationHandler { (notification: Notification<NReply2>) in
handler2(notification)
expectation.fulfill()
}

Expand All @@ -230,9 +230,9 @@ public final class TestServer: MessageHandler {
}

public func handle<N: NotificationType>(_ params: N, from clientID: ObjectIdentifier) {
let note = Notification(params, clientID: clientID)
let notification = Notification(params, clientID: clientID)
if params is EchoNotification {
self.client.send(note.params)
self.client.send(notification.params)
} else {
fatalError("Unhandled notification")
}
Expand Down Expand Up @@ -312,7 +312,7 @@ public struct EchoError: RequestType {
}

public struct EchoNotification: NotificationType {
public static var method: String = "test_server/echo_note"
public static var method: String = "test_server/echo_notification"

public var string: String

Expand Down
40 changes: 20 additions & 20 deletions Sources/SourceKitLSP/Clang/ClangLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import WinSDK
#endif

extension NSLock {
/// NOTE: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
/// notification: Keep in sync with SwiftPM's 'Sources/Basics/NSLock+Extensions.swift'
fileprivate func withLock<T>(_ body: () throws -> T) rethrows -> T {
lock()
defer { unlock() }
Expand Down Expand Up @@ -366,8 +366,8 @@ extension ClangLanguageServerShim {

/// Intercept clangd's `PublishDiagnosticsNotification` to withold it if we're using fallback
/// build settings.
func publishDiagnostics(_ note: Notification<PublishDiagnosticsNotification>) async {
let params = note.params
func publishDiagnostics(_ notification: Notification<PublishDiagnosticsNotification>) async {
let params = notification.params
// Technically, the publish diagnostics notification could still originate
// from when we opened the file with fallback build settings and we could
// have received real build settings since, which haven't been acknowledged
Expand All @@ -394,7 +394,7 @@ extension ClangLanguageServerShim {
)
)
} else {
await sourceKitServer.sendNotificationToClient(note.params)
await sourceKitServer.sendNotificationToClient(notification.params)
}
}

Expand Down Expand Up @@ -431,30 +431,30 @@ extension ClangLanguageServerShim {

// MARK: - Text synchronization

public func openDocument(_ note: DidOpenTextDocumentNotification) async {
openDocuments[note.textDocument.uri] = note.textDocument.language
public func openDocument(_ notification: DidOpenTextDocumentNotification) async {
openDocuments[notification.textDocument.uri] = notification.textDocument.language
// Send clangd the build settings for the new file. We need to do this before
// sending the open notification, so that the initial diagnostics already
// have build settings.
await documentUpdatedBuildSettings(note.textDocument.uri)
clangd.send(note)
await documentUpdatedBuildSettings(notification.textDocument.uri)
clangd.send(notification)
}

public func closeDocument(_ note: DidCloseTextDocumentNotification) {
openDocuments[note.textDocument.uri] = nil
clangd.send(note)
public func closeDocument(_ notification: DidCloseTextDocumentNotification) {
openDocuments[notification.textDocument.uri] = nil
clangd.send(notification)
}

public func changeDocument(_ note: DidChangeTextDocumentNotification) {
clangd.send(note)
public func changeDocument(_ notification: DidChangeTextDocumentNotification) {
clangd.send(notification)
}

public func willSaveDocument(_ note: WillSaveTextDocumentNotification) {
public func willSaveDocument(_ notification: WillSaveTextDocumentNotification) {

}

public func didSaveDocument(_ note: DidSaveTextDocumentNotification) {
clangd.send(note)
public func didSaveDocument(_ notification: DidSaveTextDocumentNotification) {
clangd.send(notification)
}

// MARK: - Build System Integration
Expand All @@ -476,26 +476,26 @@ extension ClangLanguageServerShim {
if let compileCommand = clangBuildSettings?.compileCommand,
let pathString = (try? AbsolutePath(validating: url.path))?.pathString
{
let note = DidChangeConfigurationNotification(
let notification = DidChangeConfigurationNotification(
settings: .clangd(
ClangWorkspaceSettings(
compilationDatabaseChanges: [pathString: compileCommand])
)
)
clangd.send(note)
clangd.send(notification)
}
}

public func documentDependenciesUpdated(_ uri: DocumentURI) {
// In order to tell clangd to reload an AST, we send it an empty `didChangeTextDocument`
// with `forceRebuild` set in case any missing header files have been added.
// This works well for us as the moment since clangd ignores the document version.
let note = DidChangeTextDocumentNotification(
let notification = DidChangeTextDocumentNotification(
textDocument: VersionedTextDocumentIdentifier(uri, version: 0),
contentChanges: [],
forceRebuild: true
)
clangd.send(note)
clangd.send(notification)
}

// MARK: - Text Document
Expand Down
16 changes: 8 additions & 8 deletions Sources/SourceKitLSP/DocumentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,32 +200,32 @@ extension DocumentManager {

/// Convenience wrapper for `open(_:language:version:text:)` that logs on failure.
@discardableResult
func open(_ note: DidOpenTextDocumentNotification) -> DocumentSnapshot? {
let doc = note.textDocument
func open(_ notification: DidOpenTextDocumentNotification) -> DocumentSnapshot? {
let doc = notification.textDocument
return orLog("failed to open document", level: .error) {
try open(doc.uri, language: doc.language, version: doc.version, text: doc.text)
}
}

/// Convenience wrapper for `close(_:)` that logs on failure.
func close(_ note: DidCloseTextDocumentNotification) {
func close(_ notification: DidCloseTextDocumentNotification) {
orLog("failed to close document", level: .error) {
try close(note.textDocument.uri)
try close(notification.textDocument.uri)
}
}

/// Convenience wrapper for `edit(_:newVersion:edits:willEditDocument:updateDocumentTokens:)`
/// that logs on failure.
@discardableResult
func edit(
_ note: DidChangeTextDocumentNotification,
_ notification: DidChangeTextDocumentNotification,
willEditDocument: ((_ before: LineTable, TextDocumentContentChangeEvent) -> Void)? = nil
) -> (preEditSnapshot: DocumentSnapshot, postEditSnapshot: DocumentSnapshot)? {
return orLog("failed to edit document", level: .error) {
return try edit(
note.textDocument.uri,
newVersion: note.textDocument.version,
edits: note.contentChanges,
notification.textDocument.uri,
newVersion: notification.textDocument.version,
edits: notification.contentChanges,
willEditDocument: willEditDocument
)
}
Expand Down
20 changes: 10 additions & 10 deletions Sources/SourceKitLSP/SourceKitServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1033,12 +1033,12 @@ extension SourceKitServer {
await openDocument(notification, workspace: workspace)
}

private func openDocument(_ note: DidOpenTextDocumentNotification, workspace: Workspace) async {
private func openDocument(_ notification: DidOpenTextDocumentNotification, workspace: Workspace) async {
// Immediately open the document even if the build system isn't ready. This is important since
// we check that the document is open when we receive messages from the build system.
documentManager.open(note)
documentManager.open(notification)

let textDocument = note.textDocument
let textDocument = notification.textDocument
let uri = textDocument.uri
let language = textDocument.language

Expand All @@ -1050,7 +1050,7 @@ extension SourceKitServer {
await workspace.buildSystemManager.registerForChangeNotifications(for: uri, language: language)

// If the document is ready, we can immediately send the notification.
await service.openDocument(note)
await service.openDocument(notification)
}

func closeDocument(_ notification: DidCloseTextDocumentNotification) async {
Expand All @@ -1062,16 +1062,16 @@ extension SourceKitServer {
await self.closeDocument(notification, workspace: workspace)
}

func closeDocument(_ note: DidCloseTextDocumentNotification, workspace: Workspace) async {
func closeDocument(_ notification: DidCloseTextDocumentNotification, workspace: Workspace) async {
// Immediately close the document. We need to be sure to clear our pending work queue in case
// the build system still isn't ready.
documentManager.close(note)
documentManager.close(notification)

let uri = note.textDocument.uri
let uri = notification.textDocument.uri

await workspace.buildSystemManager.unregisterForChangeNotifications(for: uri)

await workspace.documentService[uri]?.closeDocument(note)
await workspace.documentService[uri]?.closeDocument(notification)
}

func changeDocument(_ notification: DidChangeTextDocumentNotification) async {
Expand All @@ -1098,10 +1098,10 @@ extension SourceKitServer {
}

func didSaveDocument(
_ note: DidSaveTextDocumentNotification,
_ notification: DidSaveTextDocumentNotification,
languageService: ToolchainLanguageServer
) async {
await languageService.didSaveDocument(note)
await languageService.didSaveDocument(notification)
}

func didChangeWorkspaceFolders(_ notification: DidChangeWorkspaceFoldersNotification) async {
Expand Down

0 comments on commit ac36205

Please sign in to comment.