# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           github 1.0
PortGroup           legacysupport 1.1

github.setup        LuaLS lua-language-server 3.7.4
github.tarball_from releases
revision            0

categories          lua devel
license             MIT
maintainers         {judaew @judaew} openmaintainer

description         A language server that offers Lua language support
long_description    {*}${description}

use_zip             yes
extract.mkdir       yes
distname            ${name}-${version}-submodules

checksums           rmd160  dd1b98bdcf9a76e5850d98485065466b27109666 \
                    sha256  4993365d2fd34ea460d5614927c752f27294181a6304901c3198a9defced673b \
                    size    31527026

depends_build       port:luamake
compiler.c_standard 2011
compiler.cxx_standard 2017

configure {
    # see https://trac.macports.org/wiki/UsingTheRightCompiler
    set makefile    [open "${worksrcpath}/make.lua" "a"]
    puts $makefile  ""
    puts $makefile  "lm.cc = '${configure.cc}'"
    close $makefile
}

pre-build {
    copy ${filespath}/wrapper ${worksrcpath}
    reinplace "s,@@PREFIX@@,${prefix},g" ${worksrcpath}/wrapper
}

build.cmd ${prefix}/bin/luamake rebuild

destroot {
    xinstall -m 0755 ${worksrcpath}/wrapper ${destroot}${prefix}/bin/${name}

    xinstall -d ${destroot}${prefix}/lib/${name}
    move ${worksrcpath}/bin ${destroot}${prefix}/lib/${name}

    move \
        ${worksrcpath}/debugger.lua \
        ${worksrcpath}/main.lua \
        ${worksrcpath}/locale \
        ${worksrcpath}/meta \
        ${worksrcpath}/script \
        ${destroot}${prefix}/lib/${name}
}

notes "
    To use in Neovim, it is sufficient to specify cmd in lspconfig:

        require'lspconfig'.lua_ls.setup \{
            cmd = \{\"${prefix}/bin/${name}\"\};
        \}

    See more https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#sumneko_lua
"
