Skip to content

Commit

Permalink
Merge pull request #2 from lukepistrol/improve-docs
Browse files Browse the repository at this point in the history
Improve docs
  • Loading branch information
lukepistrol authored Oct 29, 2022
2 parents 835c408 + d9ded70 commit 1911c6c
Show file tree
Hide file tree
Showing 12 changed files with 438 additions and 224 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/Packages
xcuserdata/
DerivedData/
.swiftpm
.swiftpm/config/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
docs/
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
105 changes: 105 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/CodeEditLanguages.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CodeEditLanguages_CodeEditLanguages"
BuildableName = "CodeEditLanguages_CodeEditLanguages"
BlueprintName = "CodeEditLanguages_CodeEditLanguages"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CodeEditLanguages"
BuildableName = "CodeEditLanguages"
BlueprintName = "CodeEditLanguages"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CodeEditLanguagesTests"
BuildableName = "CodeEditLanguagesTests"
BlueprintName = "CodeEditLanguagesTests"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CodeEditLanguagesTests"
BuildableName = "CodeEditLanguagesTests"
BlueprintName = "CodeEditLanguagesTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "CodeEditLanguages_CodeEditLanguages"
BuildableName = "CodeEditLanguages_CodeEditLanguages"
BlueprintName = "CodeEditLanguages_CodeEditLanguages"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "swift-docc-plugin",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-docc-plugin.git",
"state" : {
"revision" : "3303b164430d9a7055ba484c8ead67a52f7b74f6",
"version" : "1.0.0"
}
},
{
"identity" : "swifttreesitter",
"kind" : "remoteSourceControl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ typedef struct TSLanguage TSLanguage;
extern "C" {
#endif

// A collection of pointers to supported tree-sitter languages
// Add new ones below (please keep an alphabetical order)

extern TSLanguage *tree_sitter_bash();
extern TSLanguage *tree_sitter_c();
extern TSLanguage *tree_sitter_cpp();
Expand All @@ -43,6 +46,3 @@ extern TSLanguage *tree_sitter_zig();
#ifdef __cplusplus
}
#endif
// In this header, you should import all the public headers of your framework using statements like #import <CodeLanguages_Container/PublicHeader.h>


Binary file modified CodeLanguagesContainer.xcframework.zip
Binary file not shown.
1 change: 0 additions & 1 deletion Sources/CodeEditLanguages/CodeLanguage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import Foundation
import tree_sitter
import SwiftTreeSitter

import CodeLanguages_Container

/// A structure holding metadata for code languages
Expand Down
51 changes: 37 additions & 14 deletions Sources/CodeEditLanguages/Documentation.docc/Add-Languages.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,23 @@ extern TSLanguage *tree_sitter_{lang}();
In order to add a language to ``CodeEditLanguages`` you need to open the `.xcodeproj` file located inside `CodeLanguage-Container`.
Add the `tree-sitter` package you created earlier as a dependency like you would in a regular Xcode project.
1. Add the `tree-sitter` package you created earlier as a dependency like you would in a regular Xcode project.
Then make sure the framework target loads the package module.
2. Then make sure the framework target loads the package module.
Now open the `CodeLanguages_Container.h` header file and add:
3. Now open the `CodeLanguages_Container.h` header file and add:
```cpp
extern TSLanguage *tree_sitter_{lang}();
```
```cpp
extern TSLanguage *tree_sitter_{lang}();
```
> Please keep an alphabetical order
> Please keep an alphabetical order
Now create the `xcframework` by running the `build_framework.sh` script from the Package's root directory.
4. Now create the `xcframework` by running the `build_framework.sh` script from the Package's root directory.
After that also run the `copy_resources.sh` script to copy the `*.scm` files into the Package's Resource folder.
5. Check the output of the script. It should say `Done!` at the end.
You are now done in the Xcode Project and may close it now. Open the Package and continue.
6. You are now done in the Xcode Project and may close it now. Open the Package and continue.
## Add it to CodeLanguage
Expand Down Expand Up @@ -196,11 +196,34 @@ When everything is working correctly push your `tree-sitter-{lang}` changes to `
Now you can remove the local dependencies and replace it with the actual package URLs and submit a Pull Request for `CodeEditTextView`.

## Documentation

Please make sure to add the newly created properties to the documentation `*.md` files.

## Unit Tests

Also make sure to add test cases for your new language in `Tests/CodeEditLanguagesTests`.

### Example

```swift
// MARK: - Swift

// create as many test cases as there are file extensions
func test_CodeLanguageSwift() throws {
let url = URL(fileURLWithPath: "~/path/to/file.swift")
let language = CodeLanguage.detectLanguageFrom(url: url)

XCTAssertEqual(language.id, .swift)
}

func test_FetchQuerySwift() throws {
var language = CodeLanguage.swift
language.resourceURL = bundleURL

let data = try Data(contentsOf: language.queryURL!)
let query = try? Query(language: language.language!, data: data)
XCTAssertNotNil(query)
XCTAssertNotEqual(query?.patternCount, 0)
}
```

## Documentation

Please make sure to add the newly created properties to the documentation `*.md` files.
12 changes: 12 additions & 0 deletions Sources/CodeEditLanguages/Documentation.docc/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,15 @@ The languages are then served as a ``CodeLanguage``.
### Guides

- <doc:Add-Languages>

### Structs

- ``CodeEditLanguages/CodeLanguage``

### Classes

- ``CodeEditLanguages/TreeSitterModel``

### Enums

- ``CodeEditLanguages/TreeSitterLanguage``
Loading

0 comments on commit 1911c6c

Please sign in to comment.