Skip to content

Commit

Permalink
Merge branch 'master' into structure-view
Browse files Browse the repository at this point in the history
  • Loading branch information
PHPirates authored Dec 17, 2024
2 parents dd0377b + ca10d91 commit 01f3bbe
Show file tree
Hide file tree
Showing 17 changed files with 216 additions and 99 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,26 @@
### Added
* Change order in structure view to match source file and sectioning level
* Add command redefinitions to command definition filter in structure view

### Fixed

## [0.9.10-alpha.3] - 2024-12-15

### Added

* Add support for automatic language injection on the minted environment
* Add support for DeclareGraphicsExtensions
* Add inspection to warn about a missing reference for a glossary occurrence
* Do not fold sections in a command definition
* Include optional parameters in spellcheck, if it contains text
* Improve performance of finding files to be indexed
* Show formatted file path in file not found inspection quickfix name
* Automatically index bibliography files outside the project that are included by an absolute path
* Disable quotes inspection when TeX ligatures are disabled by fontspec
* Inspections can now be suppressed for any single line, or block of text

### Fixed
* Fix false positive for duplicate command definition inspection in if/else
* Fix LaTeX files not showing up when choosing main file in run configuration
* Fix various issues with the Grazie implementation, in particular default rules for Grazie Pro

Expand Down Expand Up @@ -461,7 +475,8 @@ Thanks to @jojo2357 and @MisterDeenis for contributing to this release!
* Fix some intention previews. ([#2796](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2796))
* Other small bug fixes and improvements. ([#2776](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2776), [#2774](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2774), [#2765](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2765)-[#2773](https://github.com/Hannah-Sten/TeXiFy-IDEA/issues/2773))

[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.2...HEAD
[Unreleased]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.3...HEAD
[0.9.10-alpha.3]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.10-alpha.2...v0.9.10-alpha.3
[0.9.10-alpha.2]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.9...v0.9.10-alpha.2
[0.9.9]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.8...v0.9.9
[0.9.8]: https://github.com/Hannah-Sten/TeXiFy-IDEA/compare/v0.9.7...v0.9.8
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ dependencies {
testFramework(TestFrameworkType.Platform)
testFramework(TestFrameworkType.Plugin.Java)

intellijIdeaCommunity("2024.2.3")
intellijIdeaCommunity("2024.3.1")

// Docs: https://github.com/JetBrains/gradle-intellij-plugin#intellij-platform-properties
// All snapshot versions: https://www.jetbrains.com/intellij-repository/snapshots/
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pluginVersion = 0.9.10-alpha.2
pluginVersion = 0.9.10-alpha.3

# Info about build ranges: https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html
# Note that an xyz branch corresponds to version 20xy.z and a since build of xyz.*
# means that the first possible build is the next branch number after xyz, so e.g.
# a since build of 173.* is equal to 181
pluginSinceBuild = 242.0
pluginSinceBuild = 243.0

# Token for releasing to Jetbrains using the Gradle intellij/publishPlugin task, for more information see the Gradle build file.
intellijPublishToken=mytoken
Expand Down
24 changes: 18 additions & 6 deletions src/nl/hannahsten/texifyidea/grammar/LatexLexer.flex
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ import static nl.hannahsten.texifyidea.psi.LatexTypes.*;
private int newCommandBracesNesting = 0;

/**
* Also keep track of brackets of verbatim environment optional arguments.
* Also keep track of brackets of verbatim environment arguments.
*/
private int verbatimOptionalArgumentBracketsCount = 0;
private int verbatimRequiredArgumentBracketsCount = 0;

/**
* Keep track of braces in the PARTIAL_DEFINITION state.
Expand Down Expand Up @@ -144,8 +145,8 @@ END_IFS=\\fi
// States are exclusive to avoid matching expressions with an empty set of associated states, i.e. to avoid matching normal LaTeX expressions
%xstates INLINE_VERBATIM_PLAIN_START INLINE_VERBATIM INLINE_VERBATIM_NORMAL_START

%states POSSIBLE_VERBATIM_BEGIN VERBATIM_OPTIONAL_ARG VERBATIM_START VERBATIM_END INLINE_VERBATIM_OPTIONAL_ARG
%xstates VERBATIM POSSIBLE_VERBATIM_OPTIONAL_ARG POSSIBLE_VERBATIM_END
%states POSSIBLE_VERBATIM_BEGIN VERBATIM_OPTIONAL_ARG VERBATIM_REQUIRED_ARG VERBATIM_START VERBATIM_END INLINE_VERBATIM_OPTIONAL_ARG
%xstates VERBATIM POSSIBLE_VERBATIM_ARG POSSIBLE_VERBATIM_END

// algorithmic environment
%states PSEUDOCODE POSSIBLE_PSEUDOCODE_END
Expand Down Expand Up @@ -231,13 +232,14 @@ END_IFS=\\fi

// Jump over the closing } of the \begin{verbatim} before starting verbatim state
<VERBATIM_START> {
{CLOSE_BRACE} { yypopState(); yypushState(POSSIBLE_VERBATIM_OPTIONAL_ARG); return CLOSE_BRACE; }
{CLOSE_BRACE} { yypopState(); yypushState(POSSIBLE_VERBATIM_ARG); return CLOSE_BRACE; }
}

// Check if an optional argument is coming up
// If you start a verbatim with an open bracket and don't close it, this won't work
<POSSIBLE_VERBATIM_OPTIONAL_ARG> {
<POSSIBLE_VERBATIM_ARG> {
{OPEN_BRACKET} { verbatimOptionalArgumentBracketsCount = 1; yypopState(); yypushState(VERBATIM_OPTIONAL_ARG); return OPEN_BRACKET; }
{OPEN_BRACE} { verbatimRequiredArgumentBracketsCount = 1; yypopState(); yypushState(VERBATIM_REQUIRED_ARG); return OPEN_BRACE; }
{WHITE_SPACE} { yypopState(); yypushState(VERBATIM); return com.intellij.psi.TokenType.WHITE_SPACE; }
{ANY_CHAR} { yypopState(); yypushState(VERBATIM); return RAW_TEXT_TOKEN; }
}
Expand All @@ -248,11 +250,21 @@ END_IFS=\\fi
{OPEN_BRACKET} { verbatimOptionalArgumentBracketsCount++; return OPEN_BRACKET; }
{CLOSE_BRACKET} {
verbatimOptionalArgumentBracketsCount--;
if (verbatimOptionalArgumentBracketsCount == 0) { yypopState(); yypushState(VERBATIM); }
// There can be a required arg coming
if (verbatimOptionalArgumentBracketsCount == 0) { yypopState(); yypushState(POSSIBLE_VERBATIM_ARG); }
return CLOSE_BRACKET;
}
}

<VERBATIM_REQUIRED_ARG> {
{OPEN_BRACE} { verbatimRequiredArgumentBracketsCount++; return OPEN_BRACE; }
{CLOSE_BRACE} {
verbatimRequiredArgumentBracketsCount--;
if (verbatimRequiredArgumentBracketsCount == 0) { yypopState(); yypushState(VERBATIM); }
return CLOSE_BRACE;
}
}

<VERBATIM> {
// Also catch whitespace, see LatexParserUtil for more info
{WHITE_SPACE} { return com.intellij.psi.TokenType.WHITE_SPACE; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LatexParserDefinition : ParserDefinition {
val FILE: IStubFileElementType<*> = object : IStubFileElementType<LatexFileStub>(
"LatexStubFileElementType", Language.findInstance(LatexLanguage::class.java)
) {
override fun getStubVersion(): Int = 77
override fun getStubVersion(): Int = 78
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.psi.PsiFile
import nl.hannahsten.texifyidea.inspections.InsightGroup
import nl.hannahsten.texifyidea.inspections.TexifyInspectionBase
import nl.hannahsten.texifyidea.util.parser.definedCommandName
import nl.hannahsten.texifyidea.util.files.definitions
import nl.hannahsten.texifyidea.util.files.definitionsInFileSet
import nl.hannahsten.texifyidea.util.isInConditionalBranch
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.parser.definedCommandName

/**
* Warns for commands that are defined twice in the same fileset.
Expand All @@ -32,13 +33,15 @@ open class LatexDuplicateDefinitionInspection : TexifyInspectionBase() {
val defined = HashMultiset.create<String>()
val definitions = file.definitionsInFileSet().filter { it.name in CommandMagic.regularStrictCommandDefinitions }
for (command in definitions) {
if (isInConditionalBranch(command)) continue
val name = command.definedCommandName() ?: continue
defined.add(name)
}

// Go monkeys.
file.definitions()
.forEach {
if (isInConditionalBranch(it)) return@forEach
val definedCmd = it.definedCommandName() ?: return@forEach
if (defined.count(definedCmd) > 1) {
descriptors.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.psi.util.elementType
import com.intellij.psi.util.startOffset
import nl.hannahsten.texifyidea.inspections.InsightGroup
import nl.hannahsten.texifyidea.inspections.TexifyInspectionBase
import nl.hannahsten.texifyidea.lang.alias.CommandManager
import nl.hannahsten.texifyidea.lang.magic.MagicCommentScope
import nl.hannahsten.texifyidea.psi.*
import nl.hannahsten.texifyidea.psi.LatexCommands
import nl.hannahsten.texifyidea.psi.LatexEnvironment
import nl.hannahsten.texifyidea.psi.LatexParameter
import nl.hannahsten.texifyidea.psi.getEnvironmentName
import nl.hannahsten.texifyidea.util.isInConditionalBranch
import nl.hannahsten.texifyidea.util.labels.findBibitemCommands
import nl.hannahsten.texifyidea.util.labels.findLatexLabelingElementsInFileSet
import nl.hannahsten.texifyidea.util.magic.CommandMagic
import nl.hannahsten.texifyidea.util.magic.EnvironmentMagic
import nl.hannahsten.texifyidea.util.parser.*
import nl.hannahsten.texifyidea.util.parser.isDefinitionOrRedefinition
import nl.hannahsten.texifyidea.util.parser.parentOfType
import nl.hannahsten.texifyidea.util.parser.requiredParameter
import java.lang.Integer.max
import java.util.*

Expand Down Expand Up @@ -125,7 +130,7 @@ open class LatexDuplicateLabelInspection : TexifyInspectionBase() {
// When the label is defined in a command definition ignore it, because there could be more than one with #1 as parameter
if (command.parentOfType(LatexCommands::class).isDefinitionOrRedefinition()) return@mapNotNull null
// If the command is within an \if branch, ignore it because it will may appear in multiple branches of which only one will be present during compilation
if (isPreviousConditionalStart(command) && isNextConditionalEnd(command)) {
if (isInConditionalBranch(command)) {
return@mapNotNull null
}
command.getLabelDescriptor()
Expand All @@ -151,54 +156,4 @@ open class LatexDuplicateLabelInspection : TexifyInspectionBase() {
isOntheFly
)
}

/**
* If the next relevant command is a \fi
*/
private fun isNextConditionalEnd(current: PsiElement): Boolean {
return isEndConditional(nextConditionalCommand(current, searchBackwards = false) ?: return false)
}

/**
* If the previous relevant command is an \if
*/
private fun isPreviousConditionalStart(current: PsiElement): Boolean {
return isStartConditional(nextConditionalCommand(current, searchBackwards = true) ?: return false)
}

/**
* Next relevant command. There are many ways in which this does not work, but since this is just an inspection this is much safer than trying to parse user defined \if commands in the parser, which is impossiblee
*/
private fun nextConditionalCommand(element: PsiElement, searchBackwards: Boolean): PsiElement? {
var current = element.parentOfType(LatexNoMathContent::class)
while (current != null && !isConditional(current)) {
current = if (!searchBackwards) {
current.nextSibling?.nextSiblingOfType(LatexNoMathContent::class)
}
else {
current.prevSibling?.previousSiblingOfType(LatexNoMathContent::class)
}
}
return current
}

private fun isConditional(element: PsiElement): Boolean {
return isStartConditional(element) || isEndConditional(element)
}

private fun isStartConditional(rootElement: PsiElement): Boolean {
// To keep it simple, only look one level down
for (element in rootElement.children + listOf(rootElement)) {
if (element is LatexCommands && element.name?.startsWith("\\if") == true) return true
if (element.elementType == LatexTypes.START_IF) return true
}
return false
}

private fun isEndConditional(rootElement: PsiElement): Boolean {
for (element in rootElement.children + listOf(rootElement)) {
if (element.firstChild?.elementType in setOf(LatexTypes.ELSE, LatexTypes.END_IF)) return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ enum class LatexGenericRegularCommand(
HYPERREF("hyperref", "options".asOptional(), "label".asRequired(Argument.Type.TEXT), dependency = LatexPackage.HYPERREF),
HYPHENATION("hyphenation", "words".asRequired(Argument.Type.TEXT)),
I("i", display = "i (dotless)"),
IFTHENELSE("ifthenelse", "test".asRequired(), "then clause".asRequired(), "else clause".asRequired()),
IMPORT("import", RequiredFolderArgument("absolute path"), RequiredFileArgument("filename", false, false, "tex"), dependency = LatexPackage.IMPORT),
INCLUDE("include", RequiredFileArgument("sourcefile", false, false, "tex")),
INCLUDEFROM("includefrom", RequiredFolderArgument("absolute path"), RequiredFileArgument("filename", false, false, "tex"), dependency = LatexPackage.IMPORT),
Expand Down
6 changes: 5 additions & 1 deletion src/nl/hannahsten/texifyidea/psi/LatexLanguageInjector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.util.TextRange
import com.intellij.psi.InjectedLanguagePlaces
import com.intellij.psi.LanguageInjector
import com.intellij.psi.PsiLanguageInjectionHost
import nl.hannahsten.texifyidea.lang.DefaultEnvironment
import nl.hannahsten.texifyidea.lang.magic.DefaultMagicKeys
import nl.hannahsten.texifyidea.lang.magic.magicComment
import nl.hannahsten.texifyidea.util.camelCase
Expand All @@ -32,9 +33,12 @@ class LatexLanguageInjector : LanguageInjector {
hasMagicCommentKey -> {
magicComment.value(DefaultMagicKeys.INJECT_LANGUAGE)
}
host.getEnvironmentName() == "lstlisting" -> {
host.getEnvironmentName() == DefaultEnvironment.LISTINGS.environmentName -> {
host.beginCommand.getOptionalParameterMap().toStringMap().getOrDefault("language", null)
}
host.getEnvironmentName() == DefaultEnvironment.MINTED.environmentName -> {
host.beginCommand.getRequiredParameters().getOrNull(1)
}
host.getEnvironmentName() in EnvironmentMagic.languageInjections.keys -> {
EnvironmentMagic.languageInjections[host.getEnvironmentName()]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package nl.hannahsten.texifyidea.run.bibtex

import com.intellij.execution.configuration.EnvironmentVariablesComponent
import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
Expand Down Expand Up @@ -108,7 +108,9 @@ class BibtexSettingsEditor(private val project: Project) : SettingsEditor<Bibtex
val mainFileField = TextFieldWithBrowseButton().apply {
addBrowseFolderListener(
TextBrowseFolderListener(
FileTypeDescriptor("Choose the Main .tex File", "tex")
FileChooserDescriptorFactory.createSingleFileDescriptor()
.withTitle("Choose the Main .tex File")
.withExtensionFilter("tex")
.withRoots(*ProjectRootManager.getInstance(project).contentRootsFromAllModules.toSet().toTypedArray())
)
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nl.hannahsten.texifyidea.run.latex.externaltool

import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
Expand Down Expand Up @@ -53,7 +53,9 @@ class ExternalToolSettingsEditor(private val project: Project) : SettingsEditor<
val mainFileField = TextFieldWithBrowseButton().apply {
addBrowseFolderListener(
TextBrowseFolderListener(
FileTypeDescriptor("Choose Main LaTeX File", "tex")
FileChooserDescriptorFactory.createSingleFileDescriptor()
.withTitle("Choose Main LaTeX File")
.withExtensionFilter("tex")
.withRoots(*ProjectRootManager.getInstance(project).contentRootsFromAllModules.toSet().toTypedArray())
)
)
Expand Down
17 changes: 10 additions & 7 deletions src/nl/hannahsten/texifyidea/run/latex/ui/LatexSettingsEditor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package nl.hannahsten.texifyidea.run.latex.ui

import com.intellij.execution.configuration.EnvironmentVariablesComponent
import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.fileTypes.PlainTextFileType
import com.intellij.openapi.options.ConfigurationException
import com.intellij.openapi.options.SettingsEditor
Expand Down Expand Up @@ -33,7 +33,11 @@ import nl.hannahsten.texifyidea.run.sumatra.SumatraAvailabilityChecker
import nl.hannahsten.texifyidea.settings.sdk.LatexSdkUtil
import nl.hannahsten.texifyidea.util.runInBackground
import java.awt.event.ItemEvent
import javax.swing.*
import javax.swing.InputVerifier
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
import kotlin.Throws

/**
* @author Sten Wessel
Expand Down Expand Up @@ -302,11 +306,10 @@ class LatexSettingsEditor(private var project: Project?) : SettingsEditor<LatexR
val mainFileField = TextFieldWithBrowseButton()
mainFileField.addBrowseFolderListener(
TextBrowseFolderListener(
FileTypeDescriptor("Choose a File to Compile", "tex")
.withRoots(
*ProjectRootManager.getInstance(project!!)
.contentRootsFromAllModules.toSet().toTypedArray()
)
FileChooserDescriptorFactory.createSingleFileDescriptor()
.withTitle("Choose a File to Compile")
.withExtensionFilter("tex")
.withRoots(*ProjectRootManager.getInstance(project!!).contentRootsFromAllModules.toSet().toTypedArray())
)
)
mainFile = LabeledComponent.create(mainFileField, "Main file to compile")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nl.hannahsten.texifyidea.run.makeindex

import com.intellij.openapi.fileChooser.FileChooserDescriptor
import com.intellij.openapi.fileChooser.FileTypeDescriptor
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
import com.intellij.openapi.options.SettingsEditor
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
Expand Down Expand Up @@ -57,7 +57,9 @@ class MakeindexSettingsEditor(private val project: Project) : SettingsEditor<Mak
val mainFileField = TextFieldWithBrowseButton().apply {
addBrowseFolderListener(
TextBrowseFolderListener(
FileTypeDescriptor("Choose the Main .tex File", "tex")
FileChooserDescriptorFactory.createSingleFileDescriptor()
.withTitle("Choose the Main .tex File")
.withExtensionFilter("tex")
.withRoots(*ProjectRootManager.getInstance(project).contentRootsFromAllModules.toSet().toTypedArray())
)
)
Expand Down
Loading

0 comments on commit 01f3bbe

Please sign in to comment.