Still a work-in-progress – please open an issue if you have any issues or feature requests!.
Currently supports showing documentation on hover, go to definition, go to callers, listing defined symbols in the file, and showing a limited number of diagnostics.
Only tested with SWI-Prolog, as it heavily uses its introspection facilities to do its stuff.
It should work with any relatively-recent version of SWI-Prolog, but for best results (for “find references” in particular), use a version with xref_called/5
(8.1.5 or newer; past commit 303f6430de5c).
Installable as a pack like ?- pack_install(lsp_server).
(lsp-register-client
(make-lsp-client
:new-connection
(lsp-stdio-connection (list "swipl"
"-g" "use_module(library(lsp_server))."
"-g" "lsp_server:main"
"-t" "halt"
"--" "stdio"))
:major-modes '(prolog-mode)
:priority 1
:multi-root t
:server-id 'prolog-ls))
(setopt eglot-server-programs (cons
(cons 'prolog-mode
(list "swipl"
"-O"
"-g" "use_module(library(lsp_server))."
"-g" "lsp_server:main"
"-t" "halt"
"--" "stdio"))
eglot-server-programs))
let g:LanguageClient_serverCommands = {
\ 'prolog': ['swipl',
\ '-g', 'use_module(library(lsp_server)).',
\ '-g', 'lsp_server:main',
\ '-t', 'halt',
\ '--', 'stdio']
\ }
Put the following in coc-settings.json
(which you can access by using the command :CocConfig
).
{"languageserver": {
"prolog-lsp": {
"command": "swipl",
"args": ["-g", "use_module(library(lsp_server)).",
"-g", "lsp_server:main",
"-t", "halt",
"--", "stdio"
],
"filetypes": ["prolog"]
}}
}
Install the neovim/nvim-lspconfig package
Put the following in $XDG_CONFIG_DIR/nvim/lua/lspconfig/prolog_lsp.lua
:
local configs = require 'lspconfig/configs'
local util = require 'lspconfig/util'
configs.prolog_lsp = {
default_config = {
cmd = {"swipl",
"-g", "use_module(library(lsp_server)).",
"-g", "lsp_server:main",
"-t", "halt",
"--", "stdio"};
filetypes = {"prolog"};
root_dir = util.root_pattern("pack.pl");
};
docs = {
description = [[
https://github.com/jamesnvc/prolog_lsp
Prolog Language Server
]];
}
}
-- vim:et ts=2 sw=2
Then add the following to init.vim
:
lua << EOF
require('lspconfig/prolog_lsp')
require('lspconfig').prolog_lsp.setup{}
EOF
- download the latest
.vsix
file from the releases page - clone this repo and copy/symlink the
vscode/
directory to ~~/.vscode/extensions/~ - clone and build the
.vsix
file yourself by the follwing steps:- install
vsce
(npm install -g vsce
) - run
vsce publish
from thevscode/
directory - add the resulting
.vsix
to VSCode.
- install