yitzchak / tree-sitter-latex

LaTeX grammar for tree-sitter
MIT License
11 stars 5 forks source link

Language server update #59

Open Aerijo opened 5 years ago

Aerijo commented 5 years ago

Not an issue, just thought I'd stop by.

A while ago I mentioned I was working on a Latex language server, and the JSON communication was "almost complete".

That was an incorrect remark.

However, I've now got to a point where I can start linting Biber files like in my existing linter-biber. I aim to get it fully working, before starting on the Latex side of things. To keep the text synced, I strapped on the Superstring module Atom uses. I'm still considering just a vector of strings, but I'll see how it goes. It also uses Tree-sitter to parse the bib files (and eventually Latex). On the Latex side, I'm first aiming for static autocompletion, as well as label and citation autocomplete / resolution (basically what exists in my current packages). Later, I'll be investigating various Latex packages for editors like Sublime and VS code, TeXWorks, and trying to match features.

You can try it here. For Atom, I have a client package set up. Right now though, any generic client will work. I have no idea if it will compile on anything other than Ubuntu + GCC, that's an issue for another day (there's nothing in particular that should fail, I just got a bunch of errors when I tried on Windows).

(If you do try it, you'll need to set the .bcf file path here).

The project has also convinced me C++ is an awful language to develop in. The saving grace is that superstring and Tree-sitter are in C / C++, so it interacts relatively nicely and without the need for bindings (in particular, I can work with node symbols as ints directly, make switch tables, etc., instead of converting them to strings and testing string equality).

Regarding this package, it seems to have reached a stable version? It'll probably be a few days before I reach a satisfactory bib linter, but I'll be in the market for a stable Latex parser soon.

yitzchak commented 5 years ago

@Aerijo Thanks for keeping me in the loop on your ide-latex progress. I'll give it a try when I get a chance.

I've released v0.1.0 of this package as I noted in area/language-latex#204 so I think that it is stable enough to begin integration with other packages. I plan on working on some cleanup and optimization next. I'd like to hear some perspective from you after you try integrating it into language-latex or other packages before I make any major changes though.

Aerijo commented 5 years ago

@yitzchak Something I'm worried about is the sheer number of unique tokens you're making. When I'm analysing, I want to easily differentiate between reference, environment, other command, etc. If every environment token is called something different, then that's a lot more checking (both in terms of performance and maintaining over different parser versions).

When I looked closer, I did see stuff like ref as the root of all reference commands, so it might not be as bad as I'm thinking.

Also, I think you should commit to _ as part of text. As it is, it breaks a text node only to declare itself as text anyway and continue.

Another thing I'm worried about now is how well changes are propagated; if you have

\catcode`\%=12

... a lot of stuff ...

% line

Does the end go back to a comment if the catcode part is removed? I haven't tried yet.

yitzchak commented 5 years ago

@Aerijo I haven't implemented arbitrary catcode handling via \catcode yet.

I've tried to keep the number of tokens limited to the style of arguments, i.e. any tabular environment with the same style of arguments as tabular will be labeled as tabular_env whereas tabu is labeled tabu_env because it's arguments or contents are different.

yitzchak commented 5 years ago

@Aerijo I agree with your dislike of the current treatment of underscore as a single text node. It's on my list of stuff to fix.

yitzchak commented 5 years ago

@Aerijo PR #60 should address your issue regarding subscript in text mode.

Aerijo commented 5 years ago

The server now handles basic maps, detects the .bcf file from the same directory as the (first) bib file, and has a working Travis CI build. Which is nice. Clang support should be possible, but I wasn't able to get the filesystem library linked so I stopped trying.