Skip to content

Commit

Permalink
fix: don't check for process cancellation if template completion
Browse files Browse the repository at this point in the history
In fact there is no ProgressIndicator running in the background,
so it would always throw an exception.
  • Loading branch information
lppedd committed Apr 9, 2020
1 parent 918fc67 commit 6919b4d
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 19 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/com/github/lppedd/cc/CCExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ internal inline fun <T> emptyCollection(): Collection<T> =
internal inline fun <T> runWithCheckCanceled(noinline callable: () -> T): T =
ApplicationUtil.runWithCheckCanceled(callable, ProgressManager.getInstance().progressIndicator)

@InlineOnly
internal inline fun <T> runWithCheckCanceled(doCheckCanceled: Boolean, noinline callable: () -> T): T =
if (doCheckCanceled) {
ApplicationUtil.runWithCheckCanceled(callable, ProgressManager.getInstance().progressIndicator)
} else {
callable()
}

@InlineOnly
internal inline fun invokeLaterOnEdt(noinline block: () -> Unit) {
ApplicationManager.getApplication().invokeLater(block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ internal class BodyCompletionProvider(
override val providers: List<CommitBodyProvider> = BODY_EP.getExtensions(project)
override val stopHere = false

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val rs = resultSet.withPrefixMatcher(context.type)
providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = BodyProviderWrapper(project, provider)
provider.getCommitBodies(
(commitTokens.type as? ValidToken)?.value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ internal interface CompletionProvider<out T : CommitTokenProvider> {
val providers: Collection<T>
val stopHere: Boolean

fun complete(resultSet: ResultSet)
fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal class FooterTypeCompletionProvider(
override val providers: List<CommitFooterTypeProvider> = FOOTER_TYPE_EP.getExtensions(project)
override val stopHere = false

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val rs = resultSet.withPrefixMatcher(context.type)
providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = FooterTypeProviderWrapper(project, provider)
provider.getCommitFooterTypes()
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ internal class FooterValueCompletionProvider(
override val providers: List<CommitFooterValueProvider> = FOOTER_VALUE_EP.getExtensions(project)
override val stopHere = true

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val prefix = context.value.trimStart()
val rs = resultSet.withPrefixMatcher(prefix)

providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = FooterValueProviderWrapper(project, provider)
provider.getCommitFooterValues(
context.type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal class ScopeCompletionProvider(
override val providers: List<CommitScopeProvider> = SCOPE_EP.getExtensions(project)
override val stopHere = false

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val rs = resultSet.withPrefixMatcher(context.scope.trim())
providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = ScopeProviderWrapper(project, provider)
provider.getCommitScopes(context.type)
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal class SubjectCompletionProvider(
override val providers: List<CommitSubjectProvider> = SUBJECT_EP.getExtensions(project)
override val stopHere = false

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val rs = resultSet.withPrefixMatcher(context.subject.trimStart())
providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = SubjectProviderWrapper(project, provider)
provider.getCommitSubjects(context.type, context.scope)
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal class TemplateTypeCompletionProvider(
override val providers: List<CommitTypeProvider> = TYPE_EP.getExtensions(project)
override val stopHere = false

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val rs = resultSet.withPrefixMatcher(context.type)
providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = TypeProviderWrapper(project, provider)
provider.getCommitTypes("")
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ internal class TypeCompletionProvider(
override val providers: List<CommitTypeProvider> = TYPE_EP.getExtensions(project)
override val stopHere = false

override fun complete(resultSet: ResultSet) {
override fun complete(resultSet: ResultSet, shouldCheckCanceled: Boolean) {
val rs = resultSet.withPrefixMatcher(context.type)
providers.asSequence()
.flatMap { provider ->
runWithCheckCanceled {
runWithCheckCanceled(shouldCheckCanceled) {
val wrapper = TypeProviderWrapper(project, provider)
provider.getCommitTypes(context.type)
.asSequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ private class CommitScopeMacro : CommitMacro() {
}
})
lookup.doWhileCalculating {
val provider = ScopeCompletionProvider(project, ScopeCommitContext(commitType, ""))
provider.complete(LookupResultSet(lookup))
val commitContext = ScopeCommitContext(commitType, "")
val provider = ScopeCompletionProvider(project, commitContext)
provider.complete(LookupResultSet(lookup), false)
}
lookup.showLookup()
lookup.refreshUi(true, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private class CommitSubjectMacro : CommitMacro() {
"commitSubject"

override fun queryProviders(project: Project, lookup: LookupImpl) {
SubjectCompletionProvider(project, SubjectCommitContext("", "", "")).complete(LookupResultSet(lookup))
val commitContext = SubjectCommitContext("", "", "")
SubjectCompletionProvider(project, commitContext).complete(LookupResultSet(lookup), false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ private class CommitTypeMacro : CommitMacro() {
"commitType"

override fun queryProviders(project: Project, lookup: LookupImpl) {
TypeCompletionProvider(project, TypeCommitContext("")).complete(LookupResultSet(lookup))
val commitContext = TypeCommitContext("")
TypeCompletionProvider(project, commitContext).complete(LookupResultSet(lookup), false)
}
}

0 comments on commit 6919b4d

Please sign in to comment.