williamboman / mason.nvim

Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters.
Apache License 2.0
7.89k stars 278 forks source link

[New package]: prolog #131

Open ignamartinoli opened 2 years ago

ignamartinoli commented 2 years ago

Package name

lsp_server

Package homepage

https://github.com/jamesnvc/lsp_server

Languages

prolog

How is this package distributed?

swipl via pack_install(lsp_server) command

williambotman commented 2 years ago

Hello! Cool! Pull requests are always very welcomed to add new packages. If the distribution of the package is simple, the installation will most likely be so as well (existing package installers may be used for reference!). Otherwise, @williamboman will get around to looking into this ASAP!

Spaceface16518 commented 1 year ago

Has this been worked on yet? I need to use Prolog for a College class and I want to use my neovim setup. Can I take this on? @williamboman

ignamartinoli commented 1 year ago

@Spaceface16518 I don't know exactly how to tackle this issue.

The way I use to get linting is running

:lua vim.lsp.start { name = 'prolog_lsp', cmd = { 'swipl', '-g', 'use_module(library(lsp_server))', '-g', 'lsp_server:main', '-t', 'halt', '--', 'stdio' } }

Currently I'm not sure of the existence of some autocompletion engine for Prolog

Spaceface16518 commented 1 year ago

I'd be fine with just linting, maybe with snippets from luasnip or something. Do we discourage adding an lsp server to Mason if it doesn't include proper autocomplete yet?

williamboman commented 1 year ago

Has this been worked on yet? I need to use Prolog for a College class and I want to use my neovim setup. Can I take this on? @williamboman

Sure! I see that it's distributed as a SWI-Prolog package, for which there is no manager yet in Mason, so adding this would require some extra additional work (see for example lua/mason-core/managers/npm/init.lua). A requirement for a "manager" to be supported is that it can ensure that installations can be done entirely locally in a directory managed by Mason - a quick look into pack_install/2 suggests that this is possible.

I'm currently working on migrating things to https://github.com/mason-org/mason-registry, so any new managers and whatnot will need to be ported to a completely new implementation, but that's fine and I'd be happy to do that should it be needed.

ignamartinoli commented 1 year ago

@williamboman @Spaceface16518

This module implements code completion, based on defined predicates in the file & imports.

I just checked and we get auto-completion only for rules defined in the document with the following snippet

require 'lspconfig.configs'['prolog_lsp'] = {
    default_config = {
        cmd = {
            'swipl',
            '-g', 'use_module(library(lsp_server)).',
            '-g', 'lsp_server:main',
            '-t', 'halt',
            '--', 'stdio'
        },
        filetypes = { 'prolog' },
        root_dir = require 'lspconfig.util'.root_pattern('pack.pl')
    },
    docs = {
        description = [[
            https://github.com/jamesnvc/prolog_lsp

            Prolog Language Server
        ]]
    }
}

require 'lspconfig'['prolog_lsp'].setup {}

The tricky part

I'm not sure how could I import the built-in predicated into the LSP scope so that one would get auto-completion when typing, for example, findall. It would be nice to have mainly for mason-lspconfig. Any idea is appreciated.