latex-lsp / texlab

An implementation of the Language Server Protocol for LaTeX
GNU General Public License v3.0
1.55k stars 53 forks source link

wrong diagnostics with braces in lstlisting #518

Closed symphorien closed 2 years ago

symphorien commented 2 years ago

With this latex file:

\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}
}
\end{lstlisting}
\end{document}

I get an error diagnostic about unexpected } inside the lstlisting. This brace should be ignored.

texlab 3.3.1, neovim, linux x86_64, nixos 21.05.

clason commented 2 years ago

Duplicate of #490

pfoerster commented 2 years ago

As @clason has already said, the issue is basically equivalent to #490. The next version of texlab will handle this case correctly and treat the text inside lstlisting as a comment. Here is the parse tree of the updated tree-sitter-latex grammar (which is not yet live):

(source_file [0, 0] - [6, 14]
  (class_include [0, 0] - [0, 23]
    (command_name [0, 0] - [0, 14])
    (curly_group_path [0, 14] - [0, 23]    
      (path [0, 15] - [0, 22])))
  (package_include [1, 0] - [1, 21]
    (command_name [1, 0] - [1, 11])
    (curly_group_path_list [1, 11] - [1, 21]
      (path [1, 12] - [1, 20])))
  (environment [2, 0] - [6, 14]
    (begin [2, 0] - [2, 16]
      (command_name [2, 0] - [2, 6])
      (curly_group_key [2, 6] - [2, 16]
        (key [2, 7] - [2, 15]
          (word [2, 7] - [2, 15]))))
    (environment [3, 0] - [5, 16]
      (begin [3, 0] - [3, 18]
        (command_name [3, 0] - [3, 6])
        (curly_group_key [3, 6] - [3, 18]
          (key [3, 7] - [3, 17]
            (word [3, 7] - [3, 17]))))
      (comment [3, 18] - [5, 0])
      (end [5, 0] - [5, 16]
        (command_name [5, 0] - [5, 4])
        (curly_group_key [5, 4] - [5, 16]
          (key [5, 5] - [5, 15]
            (word [5, 5] - [5, 15])))))
    (end [6, 0] - [6, 14]
      (command_name [6, 0] - [6, 4])
      (curly_group_key [6, 4] - [6, 14]
        (key [6, 5] - [6, 13]
          (word [6, 5] - [6, 13]))))))
pfoerster commented 2 years ago

Closing this issue in favor of #490.