File: IndexDelegate.swift

package info (click to toggle)
swiftlang 6.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,604 kB
  • sloc: cpp: 9,901,740; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (82 lines) | stat: -rw-r--r-- 3,017 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//===--- IndexStoreDB.swift -----------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//

@_implementationOnly import CIndexStoreDB

public struct StoreUnitInfo {
  public let mainFilePath: String
  public let unitName: String
}

/// Delegate for index events.
public protocol IndexDelegate: AnyObject {

  /// The index will process `count` unit files.
  func processingAddedPending(_ count: Int)

  /// The index finished processing `count` unit files.
  func processingCompleted(_ count: Int)

  /// Notification about out-of-date unit.
  /// - Parameters:
  ///   - outOfDateModTime: number of nanoseconds since clock's epoch.
  ///   - triggerHintFile: file path that was determined as out-of-date.
  ///   - triggerHintDescription: full description of the out-of-date trigger.
  ///   - synchronous: whether the event needs to be handled synchronously.
  func unitIsOutOfDate(
    _ unitInfo: StoreUnitInfo,
    outOfDateModTime: UInt64,
    triggerHintFile: String,
    triggerHintDescription: String,
    synchronous: Bool
  )
}

extension IndexDelegate {
  public func unitIsOutOfDate(
    _ unitInfo: StoreUnitInfo,
    outOfDateModTime: UInt64,
    triggerHintFile: String,
    triggerHintDescription: String,
    synchronous: Bool
  ) {
  }
}

extension IndexDelegate {
  internal func handleEvent(_ event: indexstoredb_delegate_event_t) {
    let kind = indexstoredb_delegate_event_get_kind(event)
    switch kind {
    case INDEXSTOREDB_EVENT_PROCESSING_ADDED_PENDING:
      let count = indexstoredb_delegate_event_get_count(event)
      self.processingAddedPending(Int(count))
    case INDEXSTOREDB_EVENT_PROCESSING_COMPLETED:
      let count = indexstoredb_delegate_event_get_count(event)
      self.processingCompleted(Int(count))
    case INDEXSTOREDB_EVENT_UNIT_OUT_OF_DATE:
      let c_unitInfo = indexstoredb_delegate_event_get_outofdate_unit_info(event)!
      let unitInfo = StoreUnitInfo(
        mainFilePath: String(cString: indexstoredb_unit_info_main_file_path(c_unitInfo)),
        unitName: String(cString: indexstoredb_unit_info_unit_name(c_unitInfo))
      )
      self.unitIsOutOfDate(
        unitInfo,
        outOfDateModTime: indexstoredb_delegate_event_get_outofdate_modtime(event),
        triggerHintFile: String(cString: indexstoredb_delegate_event_get_outofdate_trigger_original_file(event)!),
        triggerHintDescription: String(cString: indexstoredb_delegate_event_get_outofdate_trigger_description(event)!),
        synchronous: indexstoredb_delegate_event_get_outofdate_is_synchronous(event)
      )
    default:
      return
    }
  }
}