valentjn / ltex-ls

LTeX Language Server: LSP language server for LanguageTool :mag::heavy_check_mark: with support for LaTeX :mortar_board:, Markdown :pencil:, and others
https://valentjn.github.io/ltex
Mozilla Public License 2.0
717 stars 33 forks source link

ltex-cli: out of bounds exception for errors than span multiple lines #277

Open Cryptosaurus opened 8 months ago

Cryptosaurus commented 8 months ago

The command line interface (ltex-cli) raises an StringIndexOutOfBoundsException when it finds an error spanning multiple lines. The problem looks like a mistake when computing the line/column positions in the source file and extracting the tex of the error.

Here is a simple example triggering the bug: ``` \documentclass{article} \usepackage[french]{babel} \begin{document} Ceci est un erreur. \end{document} ``` I get an exception as follows (LTex-ls 16.0.0.0 binary release on linux x64): ``` $ ltex-ls-16.0.0/bin/ltex-cli ecm-fr.tex ecm-fr.tex:6:10: info: Le déterminant s'accorde avec le nom 'erreur'. [D_N] java.lang.StringIndexOutOfBoundsException: begin 9, end 18, length 12 at java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source) at java.base/java.lang.String.substring(Unknown Source) at org.bsplines.lspcli.client.Checker$Companion.printDiagnostic(Checker.kt:185) at org.bsplines.lspcli.client.Checker$Companion.access$printDiagnostic(Checker.kt:135) at org.bsplines.lspcli.client.Checker.checkFile(Checker.kt:129) at org.bsplines.lspcli.client.Checker.check(Checker.kt:66) at org.bsplines.lspcli.client.Checker.check(Checker.kt:39) at org.bsplines.lspcli.LspCliLauncher.call(LspCliLauncher.kt:174) at org.bsplines.lspcli.LspCliLauncher$Companion.main(LspCliLauncher.kt:212) at org.bsplines.lspcli.LspCliLauncher.main(LspCliLauncher.kt) ``` The problem seems a bit harder to trigger with English text for some reason, but here is a (contrived) example triggering the bug: ``` \documentclass{article} \begin{document} This is a% n mistake. \end{document} ``` I get the following exception: ``` $ ltex-ls-16.0.0/bin/ltex-cli ecm.tex ecm.tex:5:9: info: Use 'a' instead of 'an' if the following word doesn't start with a vowel sound, e.g. 'a sentence', 'a university'. [EN_A_VS_AN] java.lang.StringIndexOutOfBoundsException: begin 8, end 12, length 11 at java.base/java.lang.String.checkBoundsBeginEnd(Unknown Source) at java.base/java.lang.String.substring(Unknown Source) at org.bsplines.lspcli.client.Checker$Companion.printDiagnostic(Checker.kt:185) at org.bsplines.lspcli.client.Checker$Companion.access$printDiagnostic(Checker.kt:135) at org.bsplines.lspcli.client.Checker.checkFile(Checker.kt:129) at org.bsplines.lspcli.client.Checker.check(Checker.kt:66) at org.bsplines.lspcli.client.Checker.check(Checker.kt:39) at org.bsplines.lspcli.LspCliLauncher.call(LspCliLauncher.kt:174) at org.bsplines.lspcli.LspCliLauncher$Companion.main(LspCliLauncher.kt:212) at org.bsplines.lspcli.LspCliLauncher.main(LspCliLauncher.kt) ```

LTeX configuration Please paste all configuration settings starting with ltex. from your settings.json. You can help us by temporarily removing some irrelevant settings from your settings.json and see if the bug still occurs.

``` { "programName": "ltex-cli", "helpMessage": { "description": "LTeX CLI - Command-line interface for LTeX LS", "visibleArguments": [ "--client-configuration", "--verbose" ] }, "defaultValues": { "--hide-commands": true, "--server-command-line": "./ltex-ls" } } ``` **Version information** List here the version information of the relevant software. - Operating system: Linux (Fedora 38) - ltex-ls: 16.0.0.0 (binary release for linux x64 downlaoded from github) - Java: included in release