Skip to content

Commit 83f8287

Browse files
authored
Merge pull request #1353 from lokesh-tr/rename-note-to-notification-wherever-necessary
Rename `note` to `notification` throughout the codebase wherever necessary
2 parents c2bf81c + 1a45220 commit 83f8287

File tree

9 files changed

+95
-93
lines changed

9 files changed

+95
-93
lines changed

Sources/LSPTestSupport/TestJSONRPCConnection.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,11 @@ public actor TestClient: MessageHandler {
111111
}
112112

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

Sources/SourceKitLSP/Clang/ClangLanguageService.swift

+16-16
Original file line numberDiff line numberDiff line change
@@ -464,30 +464,30 @@ extension ClangLanguageService {
464464

465465
// MARK: - Text synchronization
466466

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

476-
public func closeDocument(_ note: DidCloseTextDocumentNotification) {
477-
openDocuments[note.textDocument.uri] = nil
478-
clangd.send(note)
476+
public func closeDocument(_ notification: DidCloseTextDocumentNotification) {
477+
openDocuments[notification.textDocument.uri] = nil
478+
clangd.send(notification)
479479
}
480480

481-
public func changeDocument(_ note: DidChangeTextDocumentNotification) {
482-
clangd.send(note)
481+
public func changeDocument(_ notification: DidChangeTextDocumentNotification) {
482+
clangd.send(notification)
483483
}
484484

485-
public func willSaveDocument(_ note: WillSaveTextDocumentNotification) {
485+
public func willSaveDocument(_ notification: WillSaveTextDocumentNotification) {
486486

487487
}
488488

489-
public func didSaveDocument(_ note: DidSaveTextDocumentNotification) {
490-
clangd.send(note)
489+
public func didSaveDocument(_ notification: DidSaveTextDocumentNotification) {
490+
clangd.send(notification)
491491
}
492492

493493
// MARK: - Build System Integration
@@ -505,26 +505,26 @@ extension ClangLanguageService {
505505
if let compileCommand = clangBuildSettings?.compileCommand,
506506
let pathString = (try? AbsolutePath(validating: url.path))?.pathString
507507
{
508-
let note = DidChangeConfigurationNotification(
508+
let notification = DidChangeConfigurationNotification(
509509
settings: .clangd(
510510
ClangWorkspaceSettings(
511511
compilationDatabaseChanges: [pathString: compileCommand])
512512
)
513513
)
514-
clangd.send(note)
514+
clangd.send(notification)
515515
}
516516
}
517517

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

530530
// MARK: - Text Document

Sources/SourceKitLSP/DocumentManager.swift

+8-8
Original file line numberDiff line numberDiff line change
@@ -210,31 +210,31 @@ extension DocumentManager {
210210

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

220220
/// Convenience wrapper for `close(_:)` that logs on failure.
221-
func close(_ note: DidCloseTextDocumentNotification) {
221+
func close(_ notification: DidCloseTextDocumentNotification) {
222222
orLog("failed to close document", level: .error) {
223-
try close(note.textDocument.uri)
223+
try close(notification.textDocument.uri)
224224
}
225225
}
226226

227227
/// Convenience wrapper for `edit(_:newVersion:edits:updateDocumentTokens:)`
228228
/// that logs on failure.
229229
@discardableResult
230230
func edit(
231-
_ note: DidChangeTextDocumentNotification
231+
_ notification: DidChangeTextDocumentNotification
232232
) -> (preEditSnapshot: DocumentSnapshot, postEditSnapshot: DocumentSnapshot, edits: [SourceEdit])? {
233233
return orLog("failed to edit document", level: .error) {
234234
return try edit(
235-
note.textDocument.uri,
236-
newVersion: note.textDocument.version,
237-
edits: note.contentChanges
235+
notification.textDocument.uri,
236+
newVersion: notification.textDocument.version,
237+
edits: notification.contentChanges
238238
)
239239
}
240240
}

Sources/SourceKitLSP/LanguageService.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public protocol LanguageService: AnyObject, Sendable {
9898
/// Sent to open up a document on the Language Server.
9999
/// This may be called before or after a corresponding
100100
/// `documentUpdatedBuildSettings` call for the same document.
101-
func openDocument(_ note: DidOpenTextDocumentNotification) async
101+
func openDocument(_ notification: DidOpenTextDocumentNotification) async
102102

103103
/// Sent to close a document on the Language Server.
104-
func closeDocument(_ note: DidCloseTextDocumentNotification) async
105-
func changeDocument(_ note: DidChangeTextDocumentNotification) async
106-
func willSaveDocument(_ note: WillSaveTextDocumentNotification) async
107-
func didSaveDocument(_ note: DidSaveTextDocumentNotification) async
104+
func closeDocument(_ notification: DidCloseTextDocumentNotification) async
105+
func changeDocument(_ notification: DidChangeTextDocumentNotification) async
106+
func willSaveDocument(_ notification: WillSaveTextDocumentNotification) async
107+
func didSaveDocument(_ notification: DidSaveTextDocumentNotification) async
108108

109109
// MARK: - Build System Integration
110110

Sources/SourceKitLSP/SourceKitLSPServer.swift

+10-10
Original file line numberDiff line numberDiff line change
@@ -1269,12 +1269,12 @@ extension SourceKitLSPServer {
12691269
await openDocument(notification, workspace: workspace)
12701270
}
12711271

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

1277-
let textDocument = note.textDocument
1277+
let textDocument = notification.textDocument
12781278
let uri = textDocument.uri
12791279
let language = textDocument.language
12801280

@@ -1286,7 +1286,7 @@ extension SourceKitLSPServer {
12861286
await workspace.buildSystemManager.registerForChangeNotifications(for: uri, language: language)
12871287

12881288
// If the document is ready, we can immediately send the notification.
1289-
await service.openDocument(note)
1289+
await service.openDocument(notification)
12901290
}
12911291

12921292
func closeDocument(_ notification: DidCloseTextDocumentNotification) async {
@@ -1300,16 +1300,16 @@ extension SourceKitLSPServer {
13001300
await self.closeDocument(notification, workspace: workspace)
13011301
}
13021302

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

1308-
let uri = note.textDocument.uri
1308+
let uri = notification.textDocument.uri
13091309

13101310
await workspace.buildSystemManager.unregisterForChangeNotifications(for: uri)
13111311

1312-
await workspace.documentService.value[uri]?.closeDocument(note)
1312+
await workspace.documentService.value[uri]?.closeDocument(notification)
13131313
}
13141314

13151315
func changeDocument(_ notification: DidChangeTextDocumentNotification) async {
@@ -1336,10 +1336,10 @@ extension SourceKitLSPServer {
13361336
}
13371337

13381338
func didSaveDocument(
1339-
_ note: DidSaveTextDocumentNotification,
1339+
_ notification: DidSaveTextDocumentNotification,
13401340
languageService: LanguageService
13411341
) async {
1342-
await languageService.didSaveDocument(note)
1342+
await languageService.didSaveDocument(notification)
13431343
}
13441344

13451345
func didChangeWorkspaceFolders(_ notification: DidChangeWorkspaceFoldersNotification) async {

Sources/SourceKitLSP/Swift/SwiftLanguageService.swift

+19-19
Original file line numberDiff line numberDiff line change
@@ -392,17 +392,17 @@ extension SwiftLanguageService {
392392
])
393393
}
394394

395-
public func openDocument(_ note: DidOpenTextDocumentNotification) async {
396-
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
397-
await diagnosticReportManager.removeItemsFromCache(with: note.textDocument.uri)
395+
public func openDocument(_ notification: DidOpenTextDocumentNotification) async {
396+
cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri)
397+
await diagnosticReportManager.removeItemsFromCache(with: notification.textDocument.uri)
398398

399-
guard let snapshot = self.documentManager.open(note) else {
399+
guard let snapshot = self.documentManager.open(notification) else {
400400
// Already logged failure.
401401
return
402402
}
403403

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

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

425-
public func closeDocument(_ note: DidCloseTextDocumentNotification) async {
426-
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
427-
inFlightPublishDiagnosticsTasks[note.textDocument.uri] = nil
428-
await diagnosticReportManager.removeItemsFromCache(with: note.textDocument.uri)
425+
public func closeDocument(_ notification: DidCloseTextDocumentNotification) async {
426+
cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri)
427+
inFlightPublishDiagnosticsTasks[notification.textDocument.uri] = nil
428+
await diagnosticReportManager.removeItemsFromCache(with: notification.textDocument.uri)
429429

430-
self.documentManager.close(note)
430+
self.documentManager.close(notification)
431431

432-
let req = closeDocumentSourcekitdRequest(uri: note.textDocument.uri)
432+
let req = closeDocumentSourcekitdRequest(uri: notification.textDocument.uri)
433433
_ = try? await self.sourcekitd.send(req, fileContents: nil)
434434
}
435435

@@ -511,8 +511,8 @@ extension SwiftLanguageService {
511511
}
512512
}
513513

514-
public func changeDocument(_ note: DidChangeTextDocumentNotification) async {
515-
cancelInFlightPublishDiagnosticsTask(for: note.textDocument.uri)
514+
public func changeDocument(_ notification: DidChangeTextDocumentNotification) async {
515+
cancelInFlightPublishDiagnosticsTask(for: notification.textDocument.uri)
516516

517517
let keys = self.keys
518518
struct Edit {
@@ -521,14 +521,14 @@ extension SwiftLanguageService {
521521
let replacement: String
522522
}
523523

524-
guard let (preEditSnapshot, postEditSnapshot, edits) = self.documentManager.edit(note) else {
524+
guard let (preEditSnapshot, postEditSnapshot, edits) = self.documentManager.edit(notification) else {
525525
return
526526
}
527527

528528
for edit in edits {
529529
let req = sourcekitd.dictionary([
530530
keys.request: self.requests.editorReplaceText,
531-
keys.name: note.textDocument.uri.pseudoPath,
531+
keys.name: notification.textDocument.uri.pseudoPath,
532532
keys.enableSyntaxMap: 0,
533533
keys.enableStructure: 0,
534534
keys.enableDiagnostics: 0,
@@ -558,14 +558,14 @@ extension SwiftLanguageService {
558558
edits: concurrentEdits
559559
)
560560

561-
await publishDiagnosticsIfNeeded(for: note.textDocument.uri)
561+
await publishDiagnosticsIfNeeded(for: notification.textDocument.uri)
562562
}
563563

564-
public func willSaveDocument(_ note: WillSaveTextDocumentNotification) {
564+
public func willSaveDocument(_ notification: WillSaveTextDocumentNotification) {
565565

566566
}
567567

568-
public func didSaveDocument(_ note: DidSaveTextDocumentNotification) {
568+
public func didSaveDocument(_ notification: DidSaveTextDocumentNotification) {
569569

570570
}
571571

0 commit comments

Comments
 (0)