Skip to content

Commit

Permalink
Add File.clearCaches() (jpsim#749)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim committed Oct 12, 2022
1 parent dd90aa2 commit 8efb94c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ on:
jobs:
MacOS:
runs-on: macos-12
env:
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app
steps:
- uses: actions/checkout@v2
- run: bazelisk test //Tests:UnitTests --test_env=PROJECT_ROOT=$(bazelisk info workspace)
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,21 @@

##### Breaking

* None.

##### Enhancements

* Add a `File.clearCaches()` function to clear a file's cached data.
[JP Simard](https://github.com/jpsim)

##### Bug Fixes

* None.

## 0.33.0

##### Breaking

* SourceKitten now requires Swift 5.6 or higher to build, and macOS 12
or higher to run.
[JP Simard](https://github.com/jpsim)
Expand Down
12 changes: 10 additions & 2 deletions Source/SourceKittenFramework/File.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SourceKit
#endif
import SWXMLHash

// swiftlint:disable file_length
// swiftlint:disable file_length type_body_length
// This file could easily be split up

/// Represents a source file.
Expand All @@ -32,6 +32,15 @@ public final class File {
}
}

public func clearCaches() {
_contentsQueue.sync {
_contents = nil
_stringViewQueue.sync {
_stringView = nil
}
}
}

public var stringView: StringView {
_stringViewQueue.sync {
if _stringView == nil {
Expand All @@ -46,7 +55,6 @@ public final class File {
}

private var _contents: String?
private var _lines: [Line]?
private var _stringView: StringView?
private let _contentsQueue = DispatchQueue(label: "com.sourcekitten.sourcekitten.file.contents")
private let _stringViewQueue = DispatchQueue(label: "com.sourcekitten.sourcekitten.file.stringView")
Expand Down
2 changes: 1 addition & 1 deletion Source/SourceKittenFramework/Version.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
public struct Version {
public let value: String

public static let current = Version(value: "0.32.0")
public static let current = Version(value: "0.33.0")
}

0 comments on commit 8efb94c

Please sign in to comment.