astoff / digestif

A language server for TeX and friends
Other
255 stars 6 forks source link

Status of ConTeXt support? #12

Closed flying-sheep closed 3 years ago

flying-sheep commented 4 years ago

Hi! Someone just pointed this one out to me.

I’m using the project structure system. I saw the bit about “TeXShop-style magic comments”, but supporting \project and so on could be a better alternative for ConTeXt.

I also wonder if command completion and bib support works for ConTeXt (completion of \cite[<tab>), because this is my biggest pain point at the moment. If so, I’ll throw together a quick VS Code extension. If not, maybe I’ll find time to help here (but I’m writing my PhD thesis right now so no promises)

Command and signature completion as well as hover docs can be done by checking the interface files: https://source.contextgarden.net/tex/context/interface/mkiv/i-accent.xml

astoff commented 4 years ago

Currently, Digestif knows about ConTeXt command names and signatures, but it doesn't know what they do. That's why you don't get completions for citations and so on.

Fixing this involves two things: adding an "action" field to the relevant commands in the data file, and expanding the ManuscriptConTeXt class to do the right things (see ManuscriptLaTeX for comparison).

This involves some work but shouldn't be too difficult, since the parsing mechanism is pretty generic.

flying-sheep commented 4 years ago

By the way: I also saw a pgf data file. How does it combine with the TeX flavors? In ConTeXt, TikZ also uses ConTeXt-style environments (e.g. \startscope instead of \begin{scope})

flying-sheep commented 4 years ago

Another question: how do you make digestif aware of files? i.e. how does it figure out which .bib file is used for the bib index?

I assume the defined macros are discovered via % !TeX root = somefile.tex and \include?

astoff commented 4 years ago

By the way: I also saw a pgf data file. How does it combine with the TeX flavors?

The only reason this doesn't work yet is because Digestif doesn't understand ConTeXt's \usemodule command. PGF is pretty much format-independent and so is Digestif's "emulation" of that package.

Another question: how do you make digestif aware of files?

I'll explain this for module files. We need to change the commands.usemodule entry of the file context.tags to look something like this:

   {
      action = "input",
      filename = "t-?.tex"
      arguments = {
         {
            meta = "module",
            delimiters = {"[", "]"}
         }
      },
   }

If you look how it is right now, the arguments fields is correct (it was extracted from the ConTeXt source), but the action and filename fields are missing.

Similar changes are required for external bibliography files, projects, etc. This is fairly simple to do, and the only reason I didn't do it is because I don't use ConTeXt often and I don't know very well how it works.

The only caveat is that, instead of changing the data files directly, the right way to do this is to extend the extract-context.lua script. It doesn't need to be a Lua script, it just needs to generate a tags file following the same scheme of the existing ones (the format is not documented yet, but should be easy to understand). If anyone wants to contribute something better, it's a very welcome contribution.

flying-sheep commented 4 years ago

Thanks for the guidance! The filename could also be with other context endings (mkiv, mkvi, mkxl, mklx). Does filename accept a table?

flying-sheep commented 4 years ago

One more question:

Why does the Lua code call it “heading” (heading_level) while latex.tags calls it “section”? Where is this converted?

astoff commented 4 years ago

That's just because I haven't been entirely consistent with the nomenclature. It can be uniformized or changed if there's a better proposal.

The heading level information from the tags file isn't used anywhere yet, but it's there for future applications.

flying-sheep commented 4 years ago

No I mean code-wise. What triggers init_callbacks.heading if not action = "heading"?

astoff commented 4 years ago

Yes, you are right. The only things to trigger init_callbacks.heading are commands that have action = "heading".

flying-sheep commented 4 years ago

But there are no commands with action = "heading" in latex.tags! That’s where my confusion comes from.

astoff commented 4 years ago

You are right, I'll fix this. But at this point it will not make any difference, since nothing reacts to sectioning commands.

flying-sheep commented 4 years ago

Ah, so that’s why haha I just assumed it works in LaTeX and didn’t check

astoff commented 4 years ago

The master branch now has cross-reference and bibliography support.

astoff commented 4 years ago

... and now also support for document outlines. The way this maps to LSP is a little weird, since the hierarquical "documentSymbol" request is for a single file, not project-wide.

flying-sheep commented 4 years ago

amazing! thank you!

gour commented 3 years ago

... and now also support for document outlines. The way this maps to LSP is a little weird, since the hierarquical "documentSymbol" request is for a single file, not project-wide.

I am trying to make digestif work with ST(4) editor using their LSP package, but struggling even with the most basic completions within the single file.

Besides, SublimeText editor does only offer to select different LaTeX types: {BibTeX, LaTeX, LaTeX, LaTeX log & TeX}, so wonder what would be required to get ConTeXt type as well?

I put the following snippet in my LSP-settings file:


    "clients": {
        "digestif": {
            "command": [
                "/home/gour/.local/bin/digestif"
            ],
            "languages": [
                {
                    "languageId": "tex",
                    "document_selector": "text.tex"
                }
            ],
            "enabled": true
        },
    }
}

Any hint?

astoff commented 3 years ago

@gour I can't really say anything specific about SublimeText, but note that for ConTeXt the right languageId is "context". If you have success with this and would like to share your configuration, feel free to edit the wiki!

gour commented 3 years ago

@astoff I've decided to use Emacs...This is what I 've in my init.el:

(use-package lsp-mode
  :ensure t
    :hook (
           (tex . lsp)

            ;; if you want which-key integration
           (lsp-mode . lsp-enable-which-key-integration))
    :commands lsp
    :config
    (add-to-list 'lsp-language-id-configuration '(context-mode . "context"))
    )

What can you suggest for digestif+lsp-mode?

bateni commented 3 years ago

I'm trying to use this for ConTeXt with Emacs and eglot,with little luck. I have a very basic context source:

\starttext
\start
\stoptext

When I do completion on the second line, I only get a list with six commands: startline, startlinenote, startregister, startstop (two different versions) and startstructurepageregister. In particular, startitemize is missing. So if I add an "i" to the end of the line, auto-completion returns nothing.

Am I missing something? I'm using context standalone. Does that matter? Things work more or less or LaTeX, though I have not tested it much.

astoff commented 3 years ago

@bateni Ok, so the way this works is: First, you need yasnippet mode active if you want to have the matching start/stop pairs to be inserted. Second, to insert \startabc ... \stopabc (or \begin{abc} ... \end{abc} in LaTeX) you should start typing \abc and the select the environment from the list. So, selecting the first item in

image

will give you

image

Now, that said, I'm not getting itemize environment either, I would have to investigate this.

bateni commented 3 years ago

Thanks, I get it now. It is very helpful.

As you said, it does not work for startitemize. When I type itemize, it gives me an \itemize[name][keywords][keywords][assignments] command with a signature similar to that of \startitemize.

Another question: I see that this works with references, which is awesome! But would it be possible to help filling in the keywords and assignments of ConTeXt commands. The context xml files include the list of all keys and values, so it would be really helpful to make that available as one is typing.

gour commented 3 years ago

Ok, so the way this works is: First, you need yasnippet mode active if you want to have the matching start/stop pairs to be inserted.

How is it supposed to work with Vim/Coc?

I've %&context as the first line in my file and Vim recognizes file's type as context, but I do not get pairs inserted?

astoff commented 3 years ago

With the recent changes, we can reliably find context-en.xml, and in fact the interface xml file of any installed ConTeXt modules, at runtime.

So it makes sense to clean up the extract script and make it part of ManuscriptContext, so that the XML files are read every time Digestif is started. The best XML parser I found for Lua is still this one by Roberto Ierusalimschy.

astoff commented 3 years ago

Commit https://github.com/astoff/digestif/commit/c71ed3144b9ab0839c0492451d9a93eb1f229037 adds the parsing of ConTeXt interface files during runtime. This works for the core commands as well as third-party ConTeXt modules. @flying-sheep: Thanks for you contribution, I just had to refactor the script a bit for it to be usable in the main program.

Since the original topic of this issue is solved now, I'll close it.