Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too greedy errorformat match with textidote compiler when test contains pattern :\d+ #2736

Closed
noctux opened this issue Jun 19, 2023 · 5 comments
Labels

Comments

@noctux
Copy link

noctux commented Jun 19, 2023

Description

I want to use the textidote compiler/grammar checker with my tex files, however, the location list is populated with bogus, too long entries as the pattern :\d+ within a line is matched as a location<->message separator (I guess).

Here is a minimal working (or more precisely non-working) example:

foo.tex

\documentclass{article}
\begin{document}
Hellor Worlsd!~\cite{peterpan:2022:fictional}
\end{document}

minimal.vimrc (make sure to adapt the jar path as required)

set nocompatible
let &runtimepath  = '~/.local/share/vim/bundle/vimtex,' . &runtimepath
filetype plugin indent on
syntax enable

let textidote_jar_path = '/usr/share/java/textidote.jar'
if filereadable(textidote_jar_path)
	let g:vimtex_grammar_textidote = {
		\ 'jar': textidote_jar_path,
		\}
endif

Please note: I'm not 100% sure whether this is a vimtex bug per se, as vimtex does no real processing in this particular case and it's more a thing between textidote and vim's errorfmt parsing. But maybe replacing/escaping semicolons in the message part of the violations can be done in a wrapper or something...

(sorry if this issue is a confusing read, I'm not really sure how this issue form will end up in the actual issue text. Thank you for vimtex as such and your patience in this case)

Steps to reproduce

  1. vim -u minimal.vimrc foo.tex
  2. In vim, type: :compiler textidote | lmake

Expected behavior

I stay within my document, the location list opens, and focus is moved to the first issue in my document as reported by textidote.

Actual behavior

I am moved to a buffer titled foo.tex(L3C1-L3C7): Possible spelling mistake found.. Suggestions: [Hello, Heller, Hellos, Hel l or, Mellor] (0) "Hellor Worlsd!~\cite{peterpan, I do not see a location list.

Additional Information:

:buffers
  1 #    "foo.tex"                      line 1
  2 %a   "foo.tex(L3C1-L3C7): Possible spelling mistake found.. Suggestions: [Hello, Heller, Hellos, Hel
l or, Mellor] (0) "Hellor Worlsd!~\cite{peterpan" line 1

Location list after manual :lopen in buffer foo.tex (Please note the |2022| that indicate that vim seems to (probably) assume that this is the linenumber and everything left of it potentially the filename):

foo.tex(L3C1-L3C7): Possible spelling mistake found.. Suggestions: [Hello, Heller, Hellos, Hell or, Mellor] (0) "Hellor Worlsd!~\cite{peterpan|2022| fictional}"                                                                                                                                                              
foo.tex(L3C8-L3C14): Possible spelling mistake found.. Suggestions: [World, Worlds] (7) "Hellor Worlsd!~\cite{peterpan|2022| fictional}"

Output of a manual run of texidote with vimtex's usual parameters:

java -jar '/usr/share/java/textidote.jar' --no-color --output singleline --check en foo.tex             
Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=setting
TeXtidote v0.8.3 - A linter for LaTeX documents and others
(C) 2018-2021 Sylvain Hallé - All rights reserved

Found 2 warning(s)
Total analysis time: 4 second(s)

foo.tex(L3C1-L3C7): Possible spelling mistake found.. Suggestions: [Hello, Heller, Hellos, Hell or, Mellor] (0) "Hellor Worlsd!~\cite{peterpan:2022:fictional}"
foo.tex(L3C8-L3C14): Possible spelling mistake found.. Suggestions: [World, Worlds] (7) "Hellor Worlsd!~\cite{peterpan:2022:fictional}"

I guess that vim misinterprets the linter output around peterpan:2022 when splitting it to obtain filenames.

Do you use a latexmkrc file?

Yes, but happens without it as well

VimtexInfo

System info:
  OS: Arch Linux
  Vim version: VIM 9.0 (1-1572)
  Has clientserver: true
  Servername: undefined (vim started without --servername)

VimTeX project: foo
  base: foo.tex
  root: /tmp
  tex: /tmp/foo.tex
  main parser: current file verified
  document class: article
  compiler: latexmk
    engine: -pdf
    options:
      -verbose
      -file-line-error
      -synctex=1
      -interaction=nonstopmode
    callback: 1
    continuous: 1
    executable: latexmk
  viewer: General
  qf method: LaTeX logfile
@noctux noctux added the bug label Jun 19, 2023
@noctux
Copy link
Author

noctux commented Jun 20, 2023

Here is an examplatory fix for the issue, but not sure whether this is the way to go:

diff --git a/compiler/textidote.vim b/compiler/textidote.vim
index 8ddd8feb..ba8ea1ba 100644
--- a/compiler/textidote.vim
+++ b/compiler/textidote.vim
@@ -39,6 +39,7 @@ let &l:makeprg = 'java -jar ' . shellescape(fnamemodify(s:cfg.jar, ':p'))
       \ . (has_key(s:cfg, 'args') ? ' ' . s:cfg.args : '')
       \ . ' --no-color --output singleline --check '
       \ . s:get_textidote_lang(s:language) . ' %:S'
+      \ . ' \| sed -E "s/:([[:digit:]]+)/:\xE2\x80\x8C\1/"'
 
 setlocal errorformat=
 setlocal errorformat+=%f(L%lC%c-L%\\d%\\+C%\\d%\\+):\ %m

It introduces a zero-space whitespace into the output. Unfortunately, vim is too clever to hide it, so it shows in the location list as <200c>, but you get the idea:

foo.tex|3 col 1| Possible spelling mistake found.. Suggestions: [Hello, Heller, Hellos, Hell or, Mellor] (0) "Hellor Worlsd!~\cite{peterpan:<200c>2022:fictional}"
foo.tex|3 col 8| Possible spelling mistake found.. Suggestions: [World, Worlds] (7) "Hellor Worlsd!~\cite{peterpan:<200c>2022:fictional}"

I don't know whether something similar can be achieved with vim itself so that there is no external tool dependency...

@lervag
Copy link
Owner

lervag commented Jun 20, 2023

Thanks, I can reproduce this problem. I will see if I can improve the errorformat here. If possible, that will be a better solution, I think.

lervag added a commit that referenced this issue Jun 20, 2023
@lervag
Copy link
Owner

lervag commented Jun 20, 2023

I pushed a possible fix; please test.

@noctux
Copy link
Author

noctux commented Jun 21, 2023

Seems to work for me, both in the minified test case as well as in the larger document I originally encountered it in, and so far, I've not encountered any adverse effects.

Thank you for the fix, can be closed from my side for now :)

@lervag
Copy link
Owner

lervag commented Jun 21, 2023

Great, glad to hear it!

@lervag lervag closed this as completed Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants