Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use pico8-ls with neovim? #34

Open
miguno opened this issue Dec 15, 2022 · 14 comments
Open

How to use pico8-ls with neovim? #34

miguno opened this issue Dec 15, 2022 · 14 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@miguno
Copy link
Contributor

miguno commented Dec 15, 2022

Any pointers how to install pico8-ls for non-vscode setups?

@japhib
Copy link
Owner

japhib commented Dec 15, 2022

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

@japhib japhib added enhancement New feature or request help wanted Extra attention is needed labels Dec 15, 2022
@japhib
Copy link
Owner

japhib commented Dec 29, 2022

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.

@musjj
Copy link

musjj commented Feb 2, 2023

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.

@chandrahmuki
Copy link

chandrahmuki commented Feb 14, 2023

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. (/Users/davidbachman/pico8-ls/server/out/server.js:41:48)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Module.load (node:internal/modules/cjs/loader:1027:32)
at Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47

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

@japhib
Copy link
Owner

japhib commented Feb 15, 2023

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.

@chandrahmuki
Copy link

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 !

@kikito
Copy link

kikito commented Aug 5, 2023

Here's my attempt at adding support for this LSP in mason: mason-org/mason-registry#2365

I could not find a way to add a "client" there - I am not sure that is needed.

@kikito
Copy link

kikito commented Aug 10, 2023

The mason PR above was merged

@kikito
Copy link

kikito commented Aug 11, 2023

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.

@musjj
Copy link

musjj commented Aug 11, 2023

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.

@JacobVanzella
Copy link

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
})

@musjj
Copy link

musjj commented Sep 4, 2023

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.

@JacobVanzella
Copy link

Thanks for the suggestions, much appreciated.

@Bcarpenter5
Copy link

quick guide

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants