Skip to content

Commit

Permalink
Formatting suggestions by ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates committed Jan 12, 2024
1 parent 3b565c1 commit d6ce9e9
Show file tree
Hide file tree
Showing 28 changed files with 82 additions and 75 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ ktlint_standard_keyword-spacing=disabled
ktlint_standard_trailing-comma-on-call-site=disabled
ktlint_standard_trailing-comma-on-declaration-site=disabled
ktlint_standard_multiline-if-else=disabled
ktlint_standard_function-naming=disabled
ktlint_standard_multiline-expression-wrapping=disabled
ktlint_standard_string-template-indent=disabled
ktlint_standard_function-signature=disabled
ktlint_standard_discouraged-comment-location=disabled

# [test/*.{kt,kts}]
ktlint_standard_function-naming=disabled

insert_final_newline = false
max_line_length = off

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,7 @@ open class InsertDummyTextAction : AnAction() {

// When itemize/enumerate/description is selected the level can be selected as well when larger than 1.
val type = data.blindtextType
if ((
type == DummyTextData.BlindtextType.ITEMIZE || type == DummyTextData.BlindtextType.ENUMERATE ||
type == DummyTextData.BlindtextType.DESCRIPTION
) && data.blindtextLevel > 1
) {
if ((type == DummyTextData.BlindtextType.ITEMIZE || type == DummyTextData.BlindtextType.ENUMERATE || type == DummyTextData.BlindtextType.DESCRIPTION) && data.blindtextLevel > 1) {
val command = "\\" + type.commandNoSlash.replace("list", "listlist[${data.blindtextLevel}]")
insertAtCaretAndMove(command)
return
Expand Down
3 changes: 2 additions & 1 deletion src/nl/hannahsten/texifyidea/algorithm/BFS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class BFS<N>(startNode: N, private val adjacencyFunction: (N) -> List<N>, endNod
*/
enum class BFSAction {

CONTINUE, ABORT;
CONTINUE,
ABORT
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import com.intellij.openapi.util.TextRange
import nl.hannahsten.texifyidea.lang.commands.Argument
import nl.hannahsten.texifyidea.lang.commands.RequiredArgument
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.util.parser.endOffset
import nl.hannahsten.texifyidea.util.files.psiFile
import nl.hannahsten.texifyidea.util.parser.endOffset
import nl.hannahsten.texifyidea.util.parser.parentOfType

/**
Expand All @@ -31,8 +31,8 @@ class LatexCommandArgumentInsertHandler(val arguments: List<Argument>? = null) :
val offset = caret.offset
// When not followed by { or [ (whichever the first parameter starts with) insert the parameters.
if (arguments != null && (
offset >= document.textLength - 1 || document.getText(TextRange.from(offset, 1)) !in setOf("{", "[")
)
offset >= document.textLength - 1 || document.getText(TextRange.from(offset, 1)) !in setOf("{", "[")
)
) {
insertParametersLiveTemplate(editor)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ fun rightTableSpaceAlign(latexCommonSettings: CommonCodeStyleSettings, parent: A
if (left.node?.text?.endsWith("&") == false) return null
if (left.node?.text?.endsWith("\\&") == true) return null

if (parent.node?.psi?.firstParentOfType(LatexEnvironmentContent::class)
?.firstParentOfType(LatexEnvironment::class)?.getEnvironmentName() !in EnvironmentMagic.getAllTableEnvironments(
parent.node?.psi?.project ?: ProjectManager.getInstance().defaultProject
)
if (
parent.node?.psi?.firstParentOfType(LatexEnvironmentContent::class)
?.firstParentOfType(LatexEnvironment::class)?.getEnvironmentName() !in EnvironmentMagic.getAllTableEnvironments(
parent.node?.psi?.project ?: ProjectManager.getInstance().defaultProject
)
) return null

return createSpacing(
Expand Down Expand Up @@ -255,9 +256,9 @@ private fun getSpacesForRightBlock(
?: 0
) > LINE_LENGTH
if ((
relativeIndices.getOrNull(i)?.getOrNull(level)
?: 0
) > LINE_LENGTH && (didPreviousCellGetNewline || level < absoluteIndices.size - 1)
relativeIndices.getOrNull(i)?.getOrNull(level)
?: 0
) > LINE_LENGTH && (didPreviousCellGetNewline || level < absoluteIndices.size - 1)
) return -1
return spacesPerCell.getOrNull(min(i, spacesPerCell.size - 1))?.getOrNull(level)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import nl.hannahsten.texifyidea.lang.commands.LatexColorDefinitionCommand
import nl.hannahsten.texifyidea.lang.commands.RequiredArgument
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexPsiHelper
import nl.hannahsten.texifyidea.util.*
import nl.hannahsten.texifyidea.util.magic.ColorMagic
import nl.hannahsten.texifyidea.util.parser.*
import nl.hannahsten.texifyidea.util.toHexString
import java.awt.Color
import java.util.*
import kotlin.math.max
Expand Down Expand Up @@ -101,8 +101,9 @@ class LatexElementColorProvider : ElementColorProvider {
// and we did not find it in the default colors (above), it should be in the
// first parameter of a color definition command. If not, we can not find the
// color (and return null in the end).
if (colorName.contains('!') || colorDefiningCommands.map { it.getRequiredArgumentValueByName("name") }
.contains(colorName)
if (
colorName.contains('!') ||
colorDefiningCommands.map { it.getRequiredArgumentValueByName("name") }.contains(colorName)
) {
val colorDefinitionCommand =
colorDefiningCommands.find { it.getRequiredArgumentValueByName("name") == colorName }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ object LatexExternalPackageInclusionCache {
FileBasedIndex.getInstance().getAllKeys(LatexExternalPackageInclusionIndex.Cache.id, project).forEach { indexKey ->
FileBasedIndex.getInstance().processValues(
LatexExternalPackageInclusionIndex.Cache.id, indexKey, null, { file, _ ->
val key = LatexPackage(file.name.removeFileExtension())
directChildren[key] = directChildren.getOrDefault(key, mutableSetOf()).also { it.add(LatexPackage((indexKey))) }
true
},
val key = LatexPackage(file.name.removeFileExtension())
directChildren[key] = directChildren.getOrDefault(key, mutableSetOf()).also { it.add(LatexPackage((indexKey))) }
true
},
GlobalSearchScope.everythingScope(project)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ open class LatexLabelConventionInspection : TexifyInspectionBase() {
}

if (label.inDirectEnvironmentMatching {
val conventionSettings = TexifyConventionsSettingsManager.getInstance(label.project).getSettings()
conventionSettings.getLabelConvention(
val conventionSettings = TexifyConventionsSettingsManager.getInstance(label.project).getSettings()
conventionSettings.getLabelConvention(
it.getEnvironmentName(),
LabelConventionType.ENVIRONMENT
) != null &&
!EnvironmentMagic.labelAsParameter.contains(it.getEnvironmentName())
}
!EnvironmentMagic.labelAsParameter.contains(it.getEnvironmentName())
}
) {
label.parentOfType(LatexEnvironment::class)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import nl.hannahsten.texifyidea.inspections.InsightGroup
import nl.hannahsten.texifyidea.inspections.TexifyInspectionBase
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.util.PackageUtils
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.magic.GeneralMagic
import nl.hannahsten.texifyidea.util.projectSearchScope
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.requiredParameter
import nl.hannahsten.texifyidea.util.projectSearchScope
import java.util.*

class LatexPackageCouldNotBeFound : TexifyInspectionBase() {
Expand All @@ -38,6 +38,7 @@ class LatexPackageCouldNotBeFound : TexifyInspectionBase() {
.filter { it.name == "\\usepackage" || it.name == "\\RequirePackage" }

for (command in commands) {
@Suppress("ktlint:standard:property-naming")
val `package` = command.getRequiredParameters().firstOrNull()?.lowercase(Locale.getDefault())
if (!packages.contains(`package`)) {
descriptors.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.reference.InputFileReference
import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil
import nl.hannahsten.texifyidea.util.TexLivePackages
import nl.hannahsten.texifyidea.util.projectSearchScope
import nl.hannahsten.texifyidea.util.parser.childrenOfType
import nl.hannahsten.texifyidea.util.parser.requiredParameter
import nl.hannahsten.texifyidea.util.projectSearchScope
import nl.hannahsten.texifyidea.util.runCommand
import java.util.*

Expand Down Expand Up @@ -64,6 +64,7 @@ class LatexPackageNotInstalledInspection : TexifyInspectionBase() {
.filter { it.name == "\\usepackage" || it.name == "\\RequirePackage" }

for (command in commands) {
@Suppress("ktlint:standard:property-naming")
val `package` = command.getRequiredParameters().firstOrNull()?.lowercase(Locale.getDefault()) ?: continue
if (`package` !in packages) {
// Use the cache or check if the file reference resolves (in the same way we resolve for the gutter icon).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ open class LatexDuplicateLabelInspection : TexifyInspectionBase() {
/**
* make the mapping from command etc. to ProblemDescriptor
*/
private fun createProblemDescriptor(desc: LabelDescriptor, isOntheFly: Boolean, manager: InspectionManager):
ProblemDescriptor {
private fun createProblemDescriptor(desc: LabelDescriptor, isOntheFly: Boolean, manager: InspectionManager): ProblemDescriptor {
return manager.createProblemDescriptor(
desc.element,
desc.textRange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,5 +139,5 @@ enum class BibtexDefaultEntryField(
SORTTITLE("sorttitle", "A field used to modify the sorting order of the bibliography.", BIBLATEX),
SORTYEAR("sortyear", "A field used to modify the sorting order of the bibliography.", BIBLATEX),
XDATA("xdata", "This field inherits data from one or more @xdata entries.", BIBLATEX),
XREF("xref", "This field is an alternative cross-referencing mechanism.", BIBLATEX);
XREF("xref", "This field is an alternative cross-referencing mechanism.", BIBLATEX)
}
26 changes: 13 additions & 13 deletions src/nl/hannahsten/texifyidea/lang/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ interface Environment : Dependend, Described {
val envs = mutableSetOf<Environment>()
FileBasedIndex.getInstance().processValues(
LatexExternalEnvironmentIndex.Cache.id, environmentName, null, { file, value ->
val dependency = file.name.removeFileExtension()
val env = object : Environment {
override val arguments = extractArgumentsFromDocs(value)
override val description = value
override val dependency =
if (dependency.isBlank()) LatexPackage.DEFAULT else LatexPackage.create(file)
override val context = Context.NORMAL
override val initialContents = ""
override val environmentName = environmentName
}
envs.add(env)
true
},
val dependency = file.name.removeFileExtension()
val env = object : Environment {
override val arguments = extractArgumentsFromDocs(value)
override val description = value
override val dependency =
if (dependency.isBlank()) LatexPackage.DEFAULT else LatexPackage.create(file)
override val context = Context.NORMAL
override val initialContents = ""
override val environmentName = environmentName
}
envs.add(env)
true
},
GlobalSearchScope.everythingScope(project)
)

Expand Down
Empty file.
6 changes: 3 additions & 3 deletions src/nl/hannahsten/texifyidea/lang/commands/LatexCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ interface LatexCommand : Described, Dependend {
runReadAction {
FileBasedIndex.getInstance().processValues(
LatexExternalCommandIndex.Cache.id, cmdWithSlash, null, { file, value ->
filesAndValues.add(Pair(file, value))
true
},
filesAndValues.add(Pair(file, value))
true
},
GlobalSearchScope.everythingScope(project)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ abstract class LatexParameterTextImplMixin(node: ASTNode) : LatexParameterText,
val command = this.firstParentOfType(LatexCommands::class)
val environment = this.firstParentOfType(LatexEnvironment::class)
// If we want to rename a label
if (CommandMagic.reference.contains(command?.name) || this.project.getLabelDefinitionCommands()
.contains(command?.name)
if (
CommandMagic.reference.contains(command?.name) ||
this.project.getLabelDefinitionCommands().contains(command?.name)
) {
// Get a new psi this for the complete label command (\label included),
// because if we replace the complete command instead of just the normal text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ interface ExtractExpressionUi {
}

// This allows us to run tests and mimic user input
@Suppress("ktlint:standard:property-naming")
var MOCK: ExtractExpressionUi? = null

@TestOnly
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,11 @@ object LatexLogMessageExtractor {
// Look for warnings that need special treatment.
specialWarningHandlersList.forEach { handler ->
// Check if the match starts in 'text', because if not then we will encounter it again the next time
if (handler.regex.any { r ->
r.containsMatchIn(text) &&
r.find(text)?.range?.start?.let { it <= text.removeSuffix(newText).length - 1 } == true
}
if (
handler.regex.any { r ->
r.containsMatchIn(text) &&
r.find(text)?.range?.start?.let { it <= text.removeSuffix(newText).length - 1 } == true
}
) {
return handler.findMessage(text, newText, currentFile)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object LatexPackageErrorProcessor : LatexErrorMessageProcessor("""^Package ${Lat

override fun process(message: String): String? {
regex.forEach {
@Suppress("ktlint:standard:property-naming")
val `package` = it.find(message)?.groups?.get("package")?.value ?: return@forEach
return "${`package`}: ${it.replace(message, "").trim()}"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ object LatexPackageWarningHandler : LatexMessageHandler(
override fun findMessage(text: String, newText: String, currentFile: String?): LatexLogMessage? {
regex.forEach {
it.find(text)?.apply {
@Suppress("ktlint:standard:property-naming")
val `package` = groups["package"]?.value
val unProcessedMessage = groups["message"]?.value ?: return@apply
// Remove the (package) occurrences in the rest of the warning message.
Expand Down
14 changes: 7 additions & 7 deletions src/nl/hannahsten/texifyidea/run/sumatra/SumatraConversation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ object SumatraConversation : ViewerConversation() {

private const val SERVER = "SUMATRA"
private const val TOPIC = "control"
private var CONVERSATION: DDEClientConversation? = null
private var conversation: DDEClientConversation? = null

private fun openConversation() {
if (SumatraAvailabilityChecker.isSumatraAvailable && CONVERSATION == null) {
if (SumatraAvailabilityChecker.isSumatraAvailable && conversation == null) {
try {
CONVERSATION = DDEClientConversation()
conversation = DDEClientConversation()
}
catch (e: NoClassDefFoundError) {
throw TeXception("Native library DLLs could not be found.", e)
Expand Down Expand Up @@ -74,14 +74,14 @@ object SumatraConversation : ViewerConversation() {
private fun execute(vararg commands: String) {
openConversation()
try {
CONVERSATION!!.connect(SERVER, TOPIC)
CONVERSATION!!.execute(commands.joinToString(separator = "") { "[$it]" })
conversation!!.connect(SERVER, TOPIC)
conversation!!.execute(commands.joinToString(separator = "") { "[$it]" })
}
catch (e: Exception) {
throw TeXception("Connection to SumatraPDF was disrupted.", e)
}
finally {
CONVERSATION?.disconnect()
conversation?.disconnect()
}
}

Expand All @@ -95,7 +95,7 @@ object SumatraConversation : ViewerConversation() {
BOOK_VIEW("book view"),
CONTINUOUS("continuous"),
CONTINUOUS_FACING("continuous facing"),
CONTINUOUS_BOOK_VIEW("continuous book view");
CONTINUOUS_BOOK_VIEW("continuous book view")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ open class SymbolToolWindowFactory : ToolWindowFactory, DumbAware {
val latex = symbol.generatedLatex
val caretLocationInGeneratedLatex = latex.indexOf("<caret>")

// When there is is a selection and a <caret> position is defined in the generated latex,
// When there is a selection and a <caret> position is defined in the generated latex,
// then the generated latex can be seen as 2 parts. If there is text selected, enclose the
// selected text by these two parts. When there is no caret, it is interpreted as ending at the end
// of the generated latex which means just appending
Expand All @@ -173,7 +173,7 @@ open class SymbolToolWindowFactory : ToolWindowFactory, DumbAware {
val parts = latex.split("<caret>")
editor.document.insertString(selection.selectionEnd, parts[1])
editor.document.insertString(selection.selectionStart, parts[0])
editor.caretModel.moveToOffset(selection.selectionEnd + latex.length - 7 /* <caret> */)
editor.caretModel.moveToOffset(selection.selectionEnd + latex.length - 7)
}
}
// Nothing needs to be enclosed: just append.
Expand Down
5 changes: 1 addition & 4 deletions src/nl/hannahsten/texifyidea/util/Packages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ object PackageUtils {
if (PackageMagic.conflictingPackages.any { it.contains(pack) }) {
for (conflicts in PackageMagic.conflictingPackages) {
// Assuming the package is not already included
if (conflicts.contains(pack) && file.includedPackages().toSet()
.intersect(conflicts)
.isNotEmpty()
) {
if (conflicts.contains(pack) && file.includedPackages().toSet().intersect(conflicts).isNotEmpty()) {
return false
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/nl/hannahsten/texifyidea/util/labels/Labels.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ import nl.hannahsten.texifyidea.util.files.psiFile
*
* @return A set containing all labels that are defined in the fileset of the given file.
*/
fun PsiFile.findLatexAndBibtexLabelStringsInFileSet(): Set<String> =
(findLatexLabelStringsInFileSetAsSequence() + findBibtexLabelsInFileSetAsSequence()).toSet()
fun PsiFile.findLatexAndBibtexLabelStringsInFileSet(): Set<String> = (findLatexLabelStringsInFileSetAsSequence() + findBibtexLabelsInFileSetAsSequence()).toSet()

/**
* Finds all the defined latex labels in the fileset of the file.
Expand Down
Loading

0 comments on commit d6ce9e9

Please sign in to comment.