Skip to content

jamesnvc/lsp_server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prolog Language server

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).

Emacs

(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))

Vim/Neovim

let g:LanguageClient_serverCommands = {
\ 'prolog': ['swipl',
\            '-g', 'use_module(library(lsp_server)).',
\            '-g', 'lsp_server:main',
\            '-t', 'halt',
\            '--', 'stdio']
\ }

Neovim

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"]
  }}
}

Native LSP (for Neovim >= 0.5)

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

VSCode

  • 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:
    1. install vsce (npm install -g vsce)
    2. run vsce publish from the vscode/ directory
    3. add the resulting .vsix to VSCode.