Open miguno opened 1 year ago
Support for neovim (any editors aside from vscode, really) still needs to be built out. Contributions are welcome! I haven't made an LSP extension for neovim before, but these look like some good starting resources: https://github.com/neovim/nvim-lspconfig https://neovim.io/doc/user/lsp.html
It looks like if you use this: https://github.com/autozimu/LanguageClient-neovim
it might be as simple as adding a new language-server config (see readme for that file). I'm guessing you'd just want to build the Typescript files under server/
in this repo into Javascript (see scripts in server/package.json
), and then you could just use Node to run server.js
.
This seems to work for me:
git clone https://github.com/japhib/pico8-ls
cd pico8-ls
npm install
cd server
npm run compile
echo -e '#!/usr/bin/env bash\n'"node $PWD/out/server.js" '"$@"' > ~/bin/pico8-ls # or any other folder in your $PATH
I might submit it to mason later on to make it easier to install for neovim users.
for me i have some errors when i try to launch the server : PICO-8 Language Server starting. /Users/davidbachman/pico8-ls/server/node_modules/vscode-languageserver/lib/node/main.js:185 throw new Error('Connection input stream is not set. ' + commandLineMessage); ^
Error: Connection input stream is not set. Use arguments of createConnection or set command line parameters: '--node-ipc', '--stdio' or '--socket={number}'
at _createConnection (/Users/davidbachman/pico8-ls/server/node_modules/vscode-languageserver/lib/node/main.js:185:15)
at createConnection (/Users/davidbachman/pico8-ls/server/node_modules/vscode-languageserver/lib/node/main.js:132:12)
at Object.
Node.js v18.10.0
Update: i started with --stdio seems to have launched without the error but then no idea what to do to make it work in neovim ? thanks for any help
So, that only gets you the language server part. The other half is getting a language-server client. The thing I linked to above, https://github.com/autozimu/LanguageClient-neovim, provides the client. I think you have to install that as a plugin though.
Anyways, the thing about --stdio
or --socket={number}
, what you want to do is dependent on the language server client. Looking through the readme for https://github.com/autozimu/LanguageClient-neovim, the examples shown there invoke the respective language server with stdio
.
This seems to work for me:
git clone https://github.com/japhib/pico8-ls cd pico8-ls npm install cd server npm run compile echo -e '#!/usr/bin/env bash\n'"node $PWD/out/server.js" '"$@"' > ~/bin/pico8-ls # or any other folder in your $PATH
I might submit it to mason later on to make it easier to install for neovim users.
could you please share your configuration for the client side ? and what you are using ? it could be nice to submit that to mason as well like you mentioned it if you have any time to do so. Cheers !
Here's my attempt at adding support for this LSP in mason: https://github.com/mason-org/mason-registry/pull/2365
I could not find a way to add a "client" there - I am not sure that is needed.
The mason PR above was merged
Despite the above being merged, I was not able to make pico-ls work in any fashion. I am not knowledgeable enough about LSPs to know what is wrong. I see no difference at all when I open a p8 file, independently of whether I have the mason plugin enabled or not.
I don't use this LSP anymore, but if you're using neovim you don't need a plugin because it has a built-in LSP client.
A simple setup could look like this (untested):
vim.api.nvim_create_autocmd("FileType", {
pattern = "pico8", -- or whatever filetype you have for *.p8 files
callback = function(args)
-- For now, the root directory is set to the directory of your *.p8 file.
-- If you want a more complex root matching behavior, see `:help vim.fs.find()`
local path = vim.fs.dirname(vim.api.nvim_buf_get_name(args.buf))
vim.lsp.start {
name = "pico8-ls",
cmd = { "pico8-ls", "--stdio" }, -- you might need to tweak this
root_dir = path,
}
end,
})
Most users however, would use the nvim-lspconfig plugin because it's more convenient. Unfortunately, there is no configuration for pico8-ls
yet. You can look at lua/lspconfig/server_configurations
if you want to contribute.
The following configuration gets the server up and running for me (more options at :h lsp), however, without syntax highlighting. I've spent sometime trying to get syntax highlighting to work to no avail. But this will get the server attached auto-completing for you though.
vim.api.nvim_create_autocmd({'BufNew', 'BufEnter'}, {
pattern = { '*.p8' },
callback = function(args)
vim.lsp.start({
name = 'pico8-ls',
cmd = { 'pico8-ls', '--stdio' },
root_dir = vim.fs.dirname(vim.api.nvim_buf_get_name(args.buf)),
-- Setup your keybinds in the on_attach function
on_attach = on_attach,
})
end
})
For syntax highlighter there's https://github.com/Bakudankun/PICO-8.vim, but it's very bare-bones.
If you want richer syntax highlighting, you can try using tree-sitter's lua parser for *.p8
files by doing vim.treesitter.language.register("lua", "pico8")
. But since pico-8's syntax isn't 100% compatible with lua, you might get some incorrect highlighting.
Btw, you can set a filetype for *.p8
files by adding vim.filetype.add { extension = { p8 = "pico8" } }
to your config.
Thanks for the suggestions, much appreciated.
for those who are like me and looking to get neovim working properly with pico8-ls
- first install pico8-ls with mason,
- then place the following code into your lua.init file
vim.api.nvim_create_autocmd({'BufNew', 'BufEnter'}, { pattern = { '*.p8' }, callback = function(args) vim.lsp.start({ name = 'pico8-ls', cmd = { 'pico8-ls', '--stdio' }, root_dir = vim.fs.dirname(vim.api.nvim_buf_get_name(args.buf)), -- Setup your keybinds in the on_attach function on_attach = on_attach, }) end })
code block from @JacobVanzella
for highlighting, I use the pico8.vim plugin but as @musjj said it is "very bare bones"
should work from that point on
Any pointers how to install pico8-ls for non-vscode setups?