pxp-lang / pxp

A suite of high-performance tools for PHP developers – includes a code formatter, static analyser, language server and superset language.
https://pxplang.org
Other
784 stars 0 forks source link

Language Server Implementation #61

Closed aashan10 closed 3 months ago

aashan10 commented 6 months ago

Hello @ryangjchandler,

First of all, thank you for this initiative. This project is a task that was long overdue and someone had to step up. I hope many more people come and see the potential value of this project for the entire php ecosystem.

Anyway, I tried to implement the language server protocol with pxp-parser and show the diagnostic information in the lsp client (neovim for me). This can be a starting for many more features as the language/platform as a whole grows. For now, it supports any diagnostics that the parser may generate.

https://github.com/pxp-lang/pxp/assets/18713900/f6c14a70-285d-4531-bdfa-e21c1f2e450a

If you want to try it out in neovim, here's how I configured it using nvim-lspconfig. It should theoretically support any editor with an lsp client, but I haven't tested in other editors.

    local capabilities = require('cmp_nvim_lsp').default_capabilities();
    local lspconfig = require('lspconfig');
    local config = require('lspconfig.configs');

    config.pxp = {
        default_config = {
            cmd = { '<path-to-pxp-ls-executable>' },
            filetypes = { 'php' },
            root_dir = lspconfig.util.root_pattern('composer.json', '.git'),
            settings = {},
        },
    }

    lspconfig.pxp.setup {
        capabilities = capabilities,
    }
ryangjchandler commented 6 months ago

Hey @aashan10, thank you very much for opening this PR!

The language server side of things is actually something I've been working on in the background for a little while, mainly focusing on ease of development and testing.

The work you've done here is an excellent start to getting things going inside of the repo and I'll definitely keep your PR open. Focus on the language server will ramp up very soon once I've got the type analysis side of things ready to use.

There are a couple of things that need to change, such as the name of the project / crate, but I can take care of those when the time comes.

Wanted to leave a comment so you didn't think I was ignoring you or anything – life is very busy right now so my time for things outside of work is essentially zero.

Thank you again, I'll pick this up very soon!