Skip to content

Commit

Permalink
Merge pull request #3808 from Hannah-Sten/minted-env
Browse files Browse the repository at this point in the history
Add support for automatic language injection on the minted environment
  • Loading branch information
PHPirates authored Dec 16, 2024
2 parents e536848 + 3cf4dd7 commit 388a9f3
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 10 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,26 @@
## [Unreleased]

### Added

### 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 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 @@ -459,7 +473,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 gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
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.*
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
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

0 comments on commit 388a9f3

Please sign in to comment.