SWI-Prolog on Helix needing a tree-sitter?

As more and more people seem to be talking about Rust, including Linux for some parts … i was having a look at Helix (a VI/VIM the Kakoune way written in Rust).

… and as SWI-Prolog is not among the supported language into Helix, I asked why and got the following reply on GitHub saying:

It doesn’t look like there’s an actively maintained (reputable) tree-sitter grammar for it.

Does anybody know about a tree-sitter solution for SWI-Prolog ?

I started making one, but kind of gave up on it (in favour of my LSP implementation), since SWI’s syntax is flexible enough that it’s really hard to have a useful tree-sitter grammar that doesn’t explode in the face of custom operators.

They are part of any Prolog system I know as well as the ISO standard. They are useful as it allows creating good looking DSLs. They are a serious hurdle for tools though :frowning:

There are so many different editors these days that all come with their own way to define syntax highlighting that it is practically impossible to support a good subset of them. Paulo Moura did a lot of work on that for Logtalk. I guess the highlighting can easily be tricked using operators and meta-programming.

I think LSP is our only hope :slight_smile:

1 Like

Good news on GitHub from Kirawi about Helix = they already support the LSP protocol on Helix and Kirawi says that

it’s straightforward to add a new LSP for a language (see languages.toml ).

Anybody having done something with LSP that could be used to make SWI-Prolog be on Helix too ?

@jamesnvc wrote a nice LSP server which you can use. It is here: "lsp_server" pack for SWI-Prolog.

Just run:

?- pack_install(lsp_server).

to install it.

You then have to configure the editor to use it. You can find some sample configurations here: GitHub - jamesnvc/lsp_server: Language Server Protocol server for SWI-Prolog

3 Likes

Thx. Good move from @jamesnvc to make concrete things happen on Helix …

UPDATE: Good news … @jamesnvc commit added to Helix :slight_smile: let’s see what will be resulting from it on the SWI-Prolog integration …

@swi

It would be great if you had a bit time to write a blog post explaining what an lsp server is, what features can be had (e.g. is visual debugging included?), and what editors or “clients” support LSPs …

Dan

Hi! You can read up on LSPs here: Official page for Language Server Protocol

Almost all major text editors support it or are working to support it. Many also have plugins to fill the void. Visual Studio, VSCode, Vim/Neovim, Emacs, Kakoune, Helix, IntelliJ’s suite, etc. It is also complemented by the Debug Adapter Protocol (DAP): Official page for Debug Adapter Protocol

1 Like

Hello Kirawi, nice to have you on the forum and thanks for the link. You can also download SWI-Prolog language and have a look at the Emacs integration, knowing that the graphical debugging part is done through a dedicated interface named XPCE as Prolog is an AI language based on rules and inference better rendered (till now and as far as i know) on such a tool, but @jan could better talk about it than me.

EDIT Another interesting part about Prolog is that Japan has a great community of users and has been largely investing into AI hardware for research.

Hi grossdan, I don’t have enough time to branch into this. Hopefully kirawi’s resources will help you. Keep up the learning! It never stops for all of us!

Do you happen to personally know users in Japan who are also looking into hardware … i would love to get to know people working on that.

Have a look at FGCS and what derived from it into Japanese AI. You can also have a look at their latest super computers. Anyway the AI part on hardware developments being supported by investments in Japanese universities, the best should be to have contacts with research teams there. As i am no more into hardware, I have no more interesting personal contacts.

Soo, sorry, what’s the recommended method of doing this? I’m looking at the instructions here. Is this the language server to use? Do you add the config to the global config file at ~/helix/languages.toml or the local config which overrides that one by running :config-open?

Would anyone mind sharing what exactly they added and where?