Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Up Language Server Protocol (LSP) for Ballerina in Neovim

Tags:

ballerina

I'm trying to use Ballerina with neovim editor and would like to use the Language Server Protocol (LSP) with it. However, It is unclear to me from the documentation here (https://github.com/ballerina-platform/ballerina-lang/tree/master/language-server) how I should go about achieving that.

Is the suggested workflow for me to build a language server executable from the java source in the repo linked above and use that, or is it published as an artifact somewhere?

like image 974
Poorna Avatar asked Oct 25 '25 15:10

Poorna


1 Answers

Language server executable comes with Ballerina installation itself and you can run it using bal start-language-server command. In order to configure Neovim to use it (assuming you have already configured LSP in general) I would,

1.Add Ballerina file type (in init.lua)

vim.filetype.add({
    extension = {
        bal = 'ballerina'
    }
})

This allows you to have configurations specific to ballerina

2.Create a new LSP client when we have a ballerina file (in ftplugin/ballerina.lua)

vim.lsp.start({
    name = 'ballerina-lsp',
    cmd = { 'bal', 'start-language-server' },
    root_dir = vim.fs.dirname(vim.fs.find({ 'Ballerina.toml' }, { upward = true })[1])
})
like image 67
Heshan Padmasiri Avatar answered Oct 28 '25 03:10

Heshan Padmasiri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!