Skip to content

Commit

Permalink
[Swift APIView] Convert Swift APIView to Tree Token structure (#9506)
Browse files Browse the repository at this point in the history
* Initial work.

* Convert internal methods.

* Make APIViewModel compile.

* Updates

* Progress.

* Progress.

* Refactor and get children to display.

* Fix issue with blankLines.

* Progress.

* Progress.

* Temporarily disable newlines

* Make test text work correctly for children.

* Progress on syntax

* Progress on tests.

* Syntax progress.

* All syntax but one!

* Finally all tests pass syntactically!

* Add lineId and relatedLineId checking to tests.

* Rename APIViewModel to CodeModel

* Add auto-navigation.

* Wire up navigation.

* Get line ID and review line metadata tests to pass for one test.

* Update all tests to check relatedTo and contextEnd.

* All tests passing!

* Clean up.

* Fix display anomalies.

* Code review feedback.

* Bump version. Add CHANGELOG.

* Code review feedback.
  • Loading branch information
tjprescott authored Jan 9, 2025
1 parent 46b5bef commit 9708104
Show file tree
Hide file tree
Showing 38 changed files with 1,520 additions and 730 deletions.
24 changes: 24 additions & 0 deletions src/SwiftAPIViewCore.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"configurations" : [
{
"id" : "48782905-B2E9-45DE-B537-392AF13BD2AC",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {

},
"testTargets" : [
{
"target" : {
"containerPath" : "container:SwiftAPIViewCore.xcodeproj",
"identifier" : "0A8469E827879AE200C967A8",
"name" : "SwiftAPIViewCoreTests"
}
}
],
"version" : 1
}
3 changes: 3 additions & 0 deletions src/swift/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Release History

## Version 0.3.0 (Unreleased)
- Convert Swift APIView to use the new tree-token syntax.

## Version 0.2.2 (Unreleased)
- Fix issue where extension members were duplicated.

Expand Down
3 changes: 3 additions & 0 deletions src/swift/SwiftAPIView.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/swift/SwiftAPIView/SwiftAPIView.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.2.2;
MARKETING_VERSION = 0.3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIView;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 5.0;
Expand All @@ -307,7 +307,7 @@
ENABLE_HARDENED_RUNTIME = YES;
INFOPLIST_FILE = "$(SRCROOT)/Info.plist";
MACOSX_DEPLOYMENT_TARGET = 12.0;
MARKETING_VERSION = 0.2.2;
MARKETING_VERSION = 0.3.0;
PRODUCT_BUNDLE_IDENTIFIER = com.microsoft.SwiftAPIView;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
17 changes: 9 additions & 8 deletions src/swift/SwiftAPIViewCore/Sources/APIViewManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,15 @@ public class APIViewManager: SyntaxVisitor {

var mode: APIViewManagerMode

var model: CodeModel?

var statements = OrderedDictionary<Int, CodeBlockItemSyntax.Item>()

// MARK: Initializer

public init(mode: APIViewManagerMode = .commandLine) {
self.mode = mode
self.model = nil
super.init(viewMode: .all)
}

Expand All @@ -84,19 +87,18 @@ public class APIViewManager: SyntaxVisitor {
guard let sourceUrl = URL(string: config.sourcePath) else {
SharedLogger.fail("usage error: source path was invalid.")
}
let apiView = try createApiView(from: sourceUrl)

model = try createApiView(from: sourceUrl)
switch mode {
case .commandLine:
save(apiView: apiView)
save(apiView: model!)
return ""
case .testing:
return apiView.text
return model!.text
}
}

/// Persist the token file to disk
func save(apiView: APIViewModel) {
func save(apiView: CodeModel) {
let destUrl: URL
if let destPath = config.destPath {
destUrl = URL(fileURLWithPath: destPath)
Expand Down Expand Up @@ -189,7 +191,7 @@ public class APIViewManager: SyntaxVisitor {
return filePaths
}

func createApiView(from sourceUrl: URL) throws -> APIViewModel {
func createApiView(from sourceUrl: URL) throws -> CodeModel {
SharedLogger.debug("URL: \(sourceUrl.absoluteString)")
var packageName: String?
var packageVersion: String?
Expand Down Expand Up @@ -232,8 +234,7 @@ public class APIViewManager: SyntaxVisitor {
}
config.packageName = packageName!
config.packageVersion = packageVersion!
let apiViewName = "\(packageName!) (version \(packageVersion!))"
let apiView = APIViewModel(name: apiViewName, packageName: packageName!, versionString: packageVersion!, statements: Array(statements.values))
let apiView = CodeModel(packageName: packageName!, packageVersion: packageVersion!, statements: Array(statements.values))
return apiView
}

Expand Down
Loading

0 comments on commit 9708104

Please sign in to comment.