Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Swift APIView] Convert Swift APIView to Tree Token structure #9506

Merged
merged 29 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
342f6cf
Initial work.
tjprescott Dec 6, 2024
025ef89
Convert internal methods.
tjprescott Dec 10, 2024
397f58e
Make APIViewModel compile.
tjprescott Dec 10, 2024
430ed73
Updates
tjprescott Dec 10, 2024
d6a463d
Progress.
tjprescott Dec 10, 2024
b40ed8c
Progress.
tjprescott Dec 10, 2024
497e520
Refactor and get children to display.
tjprescott Dec 12, 2024
eff6379
Fix issue with blankLines.
tjprescott Dec 12, 2024
9bf252d
Progress.
tjprescott Dec 13, 2024
92849b8
Progress.
tjprescott Dec 13, 2024
8c73275
Temporarily disable newlines
tjprescott Dec 13, 2024
4af4cc2
Make test text work correctly for children.
tjprescott Dec 13, 2024
c54a688
Progress on syntax
tjprescott Dec 16, 2024
c1db006
Progress on tests.
tjprescott Dec 18, 2024
a387df0
Syntax progress.
tjprescott Dec 18, 2024
8b00e8e
All syntax but one!
tjprescott Dec 18, 2024
202a5f9
Finally all tests pass syntactically!
tjprescott Dec 18, 2024
bc5264e
Add lineId and relatedLineId checking to tests.
tjprescott Dec 19, 2024
d853825
Rename APIViewModel to CodeModel
tjprescott Dec 19, 2024
3a053d9
Add auto-navigation.
tjprescott Dec 19, 2024
e410cac
Wire up navigation.
tjprescott Dec 19, 2024
758063a
Get line ID and review line metadata tests to pass for one test.
tjprescott Dec 27, 2024
d41ff4f
Update all tests to check relatedTo and contextEnd.
tjprescott Dec 27, 2024
009cc92
All tests passing!
tjprescott Dec 30, 2024
84b05f4
Clean up.
tjprescott Dec 30, 2024
114d42f
Fix display anomalies.
tjprescott Dec 31, 2024
82db43b
Code review feedback.
tjprescott Jan 8, 2025
9d3c4d3
Bump version. Add CHANGELOG.
tjprescott Jan 8, 2025
7f9f2c6
Code review feedback.
tjprescott Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

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
Loading