mason.nvim icon indicating copy to clipboard operation
mason.nvim copied to clipboard

[New package]: prolog

Open ignamartinoli opened this issue 3 years ago • 6 comments
trafficstars

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

ignamartinoli avatar Jul 25 '22 07:07 ignamartinoli

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!

williambotman avatar Jul 25 '22 07:07 williambotman

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

Spaceface16518 avatar Jan 19 '23 18:01 Spaceface16518

@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

ignamartinoli avatar Jan 19 '23 18:01 ignamartinoli

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?

Spaceface16518 avatar Jan 20 '23 01:01 Spaceface16518

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.

williamboman avatar Jan 23 '23 19:01 williamboman

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

ignamartinoli avatar Jan 24 '23 00:01 ignamartinoli