Skip to content

Commit

Permalink
document ExternalUsage endpoints in README.md #354
Browse files Browse the repository at this point in the history
  • Loading branch information
breandan committed Apr 4, 2021
1 parent d2b1fb9 commit 59e0082
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,43 @@ The build artifact will be placed in `build/distributions/`.

*Miscellaneous: AceJump is built using [Gradle](https://gradle.com/) with the [Gradle Kotlin DSL](https://docs.gradle.org/5.1/userguide/kotlin_dsl.html) and the [gradle-intellij-plugin](https://github.com/JetBrains/gradle-intellij-plugin).*

## Extending

AceJump can be used by other [IntelliJ Platform](https://plugins.jetbrains.com/docs/intellij/welcome.html) plugins. To do so, add the following snippet to your `build.gradle.kts` file:

```kotlin
intellij {
setPlugins("AceJump:<VERSION>")
}
```

Callers who pass an instance of [`Editor`](https://github.com/JetBrains/intellij-community/blob/master/platform/editor-ui-api/src/com/intellij/openapi/editor/Editor.java) into `SessionManager.start(editor)` will receive a [`Session`](src/main/kotlin/org/acejump/session/Session.kt) instance in return. Sessions are disposed after use.

To use AceJump externally, please see the following example:

```kotlin
import org.acejump.session.SessionManager
import org.acejump.session.AceJumpListener
import org.acejump.boundaries.StandardBoundaries.*
import org.acejump.search.Pattern.*

val aceJumpSession = SessionManager.start(editorInstance)

aceJumpSession.addAceJumpListener(object: AceJumpListener {
override fun finished() {
// ...
}
})

// Sessions provide these endpoints for external consumers:

/*1.*/ aceJumpSession.markResults(sortedSetOf(/*...*/)) // Pass a set of offsets
/*2.*/ aceJumpSession.startRegexSearch("[aeiou]+", WHOLE_FILE) // Search for regex
/*3.*/ aceJumpSession.startRegexSearch(ALL_WORDS, VISIBLE_ON_SCREEN) // Search for Pattern
```

Custom boundaries for search (i.e. current line before caret etc.) can also be defined using the [Boundaries](src/main/kotlin/org/acejump/boundaries/Boundaries.kt) interface.

## Contributing

AceJump is supported by community members like you. Contributions are highly welcome!
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ intellij {
pluginName = "AceJump"
updateSinceUntilBuild = false
setPlugins("java")

}

group = "org.acejump"
Expand Down
9 changes: 4 additions & 5 deletions src/test/kotlin/ExternalUsageTest.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import junit.framework.TestCase
import org.acejump.boundaries.StandardBoundaries
import org.acejump.search.Pattern
import org.acejump.boundaries.StandardBoundaries.*
import org.acejump.search.Pattern.*
import org.acejump.session.*
import org.acejump.test.util.BaseTest


/**
* Test [org.acejump.ExternalUsage] endpoints.
*/
Expand Down Expand Up @@ -34,7 +33,7 @@ class ExternalUsageTest: BaseTest() {
makeEditor("test external pattern usage")

SessionManager.start(myFixture.editor)
.startRegexSearch(Pattern.ALL_WORDS, StandardBoundaries.WHOLE_FILE)
.startRegexSearch(ALL_WORDS, WHOLE_FILE)

TestCase.assertEquals(4, session.tags.size)
}
Expand All @@ -43,7 +42,7 @@ class ExternalUsageTest: BaseTest() {
makeEditor("test external regex usage")

SessionManager.start(myFixture.editor)
.startRegexSearch("[aeiou]+", StandardBoundaries.WHOLE_FILE)
.startRegexSearch("[aeiou]+", WHOLE_FILE)

TestCase.assertEquals(8, session.tags.size)
}
Expand Down

0 comments on commit 59e0082

Please sign in to comment.