From 8efb94c0a1937f1cb8e27891f44f59d073b90886 Mon Sep 17 00:00:00 2001 From: JP Simard Date: Wed, 12 Oct 2022 09:23:20 -0400 Subject: [PATCH] Add `File.clearCaches()` (#749) --- .github/workflows/bazel.yml | 2 ++ CHANGELOG.md | 15 +++++++++++++++ Source/SourceKittenFramework/File.swift | 12 ++++++++++-- Source/SourceKittenFramework/Version.swift | 2 +- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.github/workflows/bazel.yml b/.github/workflows/bazel.yml index 37516dfd..1f5b340c 100644 --- a/.github/workflows/bazel.yml +++ b/.github/workflows/bazel.yml @@ -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) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12aea59e..afc0aa2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/Source/SourceKittenFramework/File.swift b/Source/SourceKittenFramework/File.swift index 29ace76e..e7c417af 100644 --- a/Source/SourceKittenFramework/File.swift +++ b/Source/SourceKittenFramework/File.swift @@ -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. @@ -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 { @@ -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") diff --git a/Source/SourceKittenFramework/Version.swift b/Source/SourceKittenFramework/Version.swift index c66e62f0..c7344653 100644 --- a/Source/SourceKittenFramework/Version.swift +++ b/Source/SourceKittenFramework/Version.swift @@ -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") }