-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3812 from Hannah-Sten/input-alias
Add support for automatic detection of custom command aliases for include commands
- Loading branch information
Showing
20 changed files
with
122 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package nl.hannahsten.texifyidea.util | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.Project | ||
import nl.hannahsten.texifyidea.lang.alias.CommandManager | ||
import nl.hannahsten.texifyidea.lang.commands.LatexCommand | ||
import java.util.concurrent.atomic.AtomicBoolean | ||
|
||
// Due to the update method being called many times, we need to limit the number of updates requested | ||
var isUpdatingIncludeAliases = AtomicBoolean(false) | ||
|
||
fun updateAndGetIncludeCommands(project: Project): Set<String> { | ||
// For performance reasons, do not wait until the update (which requires index access) is done | ||
updateIncludeCommandsAliasesAsync(project) | ||
return defaultIncludeCommands.map { CommandManager.getAliases(it) }.flatten().toSet() | ||
} | ||
|
||
fun updateIncludeCommandsAliasesAsync(project: Project) { | ||
if (!isUpdatingIncludeAliases.getAndSet(true)) { | ||
// Don't run with progress indicator, because this takes a short time (a few tenths) and runs in practice on every letter typed | ||
ApplicationManager.getApplication().invokeLater { | ||
try { | ||
// Because every command has different parameters and behaviour (e.g. allowed file types), we keep track of them separately | ||
for (command in defaultIncludeCommands) { | ||
runReadAction { | ||
CommandManager.updateAliases(setOf(command), project) | ||
} | ||
} | ||
} | ||
finally { | ||
isUpdatingIncludeAliases.set(false) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Given a possible alias of an include command, find a random original command it is an alias of | ||
*/ | ||
fun getOriginalCommandFromAlias(commandName: String, project: Project): LatexCommand? { | ||
val aliasSet = CommandManager.getAliases(commandName) | ||
if (aliasSet.isEmpty()) { | ||
// If we can't find anything, trigger an update so that maybe we have the information next time | ||
updateIncludeCommandsAliasesAsync(project) | ||
} | ||
return LatexCommand.lookup(aliasSet.firstOrNull { it in defaultIncludeCommands })?.first() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.