Skip to content

Rename note to notification throughout the codebase wherever necessary #1353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/LSPTestSupport/TestJSONRPCConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ public actor TestClient: MessageHandler {
}

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

Expand Down
32 changes: 16 additions & 16 deletions Sources/SourceKitLSP/Clang/ClangLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,30 +464,30 @@ extension ClangLanguageService {

// 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 @@ -505,26 +505,26 @@ extension ClangLanguageService {
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 @@ -210,31 +210,31 @@ 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:updateDocumentTokens:)`
/// that logs on failure.
@discardableResult
func edit(
_ note: DidChangeTextDocumentNotification
_ notification: DidChangeTextDocumentNotification
) -> (preEditSnapshot: DocumentSnapshot, postEditSnapshot: DocumentSnapshot, edits: [SourceEdit])? {
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
)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/SourceKitLSP/LanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ public protocol LanguageService: AnyObject, Sendable {
/// Sent to open up a document on the Language Server.
/// This may be called before or after a corresponding
/// `documentUpdatedBuildSettings` call for the same document.
func openDocument(_ note: DidOpenTextDocumentNotification) async
func openDocument(_ notification: DidOpenTextDocumentNotification) async

/// Sent to close a document on the Language Server.
func closeDocument(_ note: DidCloseTextDocumentNotification) async
func changeDocument(_ note: DidChangeTextDocumentNotification) async
func willSaveDocument(_ note: WillSaveTextDocumentNotification) async
func didSaveDocument(_ note: DidSaveTextDocumentNotification) async
func closeDocument(_ notification: DidCloseTextDocumentNotification) async
func changeDocument(_ notification: DidChangeTextDocumentNotification) async
func willSaveDocument(_ notification: WillSaveTextDocumentNotification) async
func didSaveDocument(_ notification: DidSaveTextDocumentNotification) async

// MARK: - Build System Integration

Expand Down
20 changes: 10 additions & 10 deletions Sources/SourceKitLSP/SourceKitLSPServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1269,12 +1269,12 @@ extension SourceKitLSPServer {
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 @@ -1286,7 +1286,7 @@ extension SourceKitLSPServer {
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 @@ -1300,16 +1300,16 @@ extension SourceKitLSPServer {
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.value[uri]?.closeDocument(note)
await workspace.documentService.value[uri]?.closeDocument(notification)
}

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

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

func didChangeWorkspaceFolders(_ notification: DidChangeWorkspaceFoldersNotification) async {
Expand Down
38 changes: 19 additions & 19 deletions Sources/SourceKitLSP/Swift/SwiftLanguageService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -392,17 +392,17 @@ extension SwiftLanguageService {
])
}

public func openDocument(_ note: DidOpenTextDocumentNotification) async {
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
await diagnosticReportManager.removeItemsFromCache(with: note.textDocument.uri)
public func openDocument(_ notification: DidOpenTextDocumentNotification) async {
cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri)
await diagnosticReportManager.removeItemsFromCache(with: notification.textDocument.uri)

guard let snapshot = self.documentManager.open(note) else {
guard let snapshot = self.documentManager.open(notification) else {
// Already logged failure.
return
}

let buildSettings = await self.buildSettings(for: snapshot.uri)
if buildSettings == nil || buildSettings!.isFallback, let fileUrl = note.textDocument.uri.fileURL {
if buildSettings == nil || buildSettings!.isFallback, let fileUrl = notification.textDocument.uri.fileURL {
// Do not show this notification for non-file URIs to make sure we don't see this notificaiton for newly created
// files (which get opened as with a `untitled:Unitled-1` URI by VS Code.
sourceKitLSPServer?.sendNotificationToClient(
Expand All @@ -419,17 +419,17 @@ extension SwiftLanguageService {

let req = openDocumentSourcekitdRequest(snapshot: snapshot, compileCommand: buildSettings)
_ = try? await self.sourcekitd.send(req, fileContents: snapshot.text)
await publishDiagnosticsIfNeeded(for: note.textDocument.uri)
await publishDiagnosticsIfNeeded(for: notification.textDocument.uri)
}

public func closeDocument(_ note: DidCloseTextDocumentNotification) async {
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
inFlightPublishDiagnosticsTasks[note.textDocument.uri] = nil
await diagnosticReportManager.removeItemsFromCache(with: note.textDocument.uri)
public func closeDocument(_ notification: DidCloseTextDocumentNotification) async {
cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri)
inFlightPublishDiagnosticsTasks[notification.textDocument.uri] = nil
await diagnosticReportManager.removeItemsFromCache(with: notification.textDocument.uri)

self.documentManager.close(note)
self.documentManager.close(notification)

let req = closeDocumentSourcekitdRequest(uri: note.textDocument.uri)
let req = closeDocumentSourcekitdRequest(uri: notification.textDocument.uri)
_ = try? await self.sourcekitd.send(req, fileContents: nil)
}

Expand Down Expand Up @@ -511,8 +511,8 @@ extension SwiftLanguageService {
}
}

public func changeDocument(_ note: DidChangeTextDocumentNotification) async {
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
public func changeDocument(_ notification: DidChangeTextDocumentNotification) async {
cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri)

let keys = self.keys
struct Edit {
Expand All @@ -521,14 +521,14 @@ extension SwiftLanguageService {
let replacement: String
}

guard let (preEditSnapshot, postEditSnapshot, edits) = self.documentManager.edit(note) else {
guard let (preEditSnapshot, postEditSnapshot, edits) = self.documentManager.edit(notification) else {
return
}

for edit in edits {
let req = sourcekitd.dictionary([
keys.request: self.requests.editorReplaceText,
keys.name: note.textDocument.uri.pseudoPath,
keys.name: notification.textDocument.uri.pseudoPath,
keys.enableSyntaxMap: 0,
keys.enableStructure: 0,
keys.enableDiagnostics: 0,
Expand Down Expand Up @@ -558,14 +558,14 @@ extension SwiftLanguageService {
edits: concurrentEdits
)

await publishDiagnosticsIfNeeded(for: note.textDocument.uri)
await publishDiagnosticsIfNeeded(for: notification.textDocument.uri)
}

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

}

public func didSaveDocument(_ note: DidSaveTextDocumentNotification) {
public func didSaveDocument(_ notification: DidSaveTextDocumentNotification) {

}

Expand Down
Loading