Neovim central thread

,

There probably aren't that many people using neovim, but it has great LSP support. And also since all the plugins and configuration are in lua these days, it's been pretty easy to get going with lua for playdate. So I figured to make a central thread here for anyone to talk about using Neovim, vs just one-off threads that the rest of the playdate community probably wouldn't care about.

To start off, I was able to get the sumneko_lua LSP server to pull in the sdk files but only when editing a playdate project directory, otherwise keep with completing all the neovim APIs. I'm still on lsp installer, and not the new maven replacement, but you can probably figure out how to make this work with maven just as easily.

local path = require "plenary.path"
local exists = function(name) return path:new(vim.fn.getcwd() .. "/" .. name):exists() end

lsp_installer.on_server_ready(function(server)
  local setup = true
  local opts = {
    on_attach = require("user.lsp.handlers").on_attach,
    -- You can disable features with this function
    capabilities = require("user.lsp.handlers").capabilities,
  }
  if server.name == "sumneko_lua" then
    if exists "source/main.lua" then -- playdate
      opts = vim.tbl_deep_extend("force", {
        settings = {
          Lua = {
            completion = { callSnippet = "Replace" },
            runtime = { nonstandardSymbol = { "+=", "-=", "*=", "/=" } },
            telemetry = { enable = false },
            diagnostics = { globals = { "playdate" } },
            workspace = {
              library = { os.getenv("HOME") .. "/Developer/PlaydateSDK/CoreLibs/" },
            },
          },
        },
      }, opts)
    else
      local luadev = prequire "lua-dev"
      if luadev then opts = vim.tbl_deep_extend("force", luadev.setup(), opts) end
    end
  end
end

Seems to be working great with just that!

One thing I wish that the __stub.lua file had comments above each function with documentation. Maybe even EmmyLua styled comments with the expected types of all the params. Then it'd show up in the cmp popups. Maybe the panic staff will add that one day?

9 Likes

Add a feature request

Good idea, I opened a dicussion for that. Thanks!

2 Likes

Hi Will, neovim user here. Thank you so much for sharing your config. However it seems there's a syntax error in the snippet, or somehow I messed up copying/pasting.

On the other hand, according to a topic on nvim-lsp-installer project, on_server_ready() is deprecating.

I tried modifying the code but didn't work out how to make sumneko_lua recognize Playdate SDK using just the on_attach function. Could you share your code if possible?

Hi, this is my current full lsp-installer file if you can get help from that lsp-installer.lua · GitHub

The only strange thing in there is my prequire which is

---@diagnostic disable-next-line: lowercase-global
function prequire(package)
  local status, lib = pcall(require, package)
  if status then
    return lib
  else
    vim.notify("Failed to require '" .. package .. "' from " .. debug.getinfo(2).source)
    return nil
  end
end

Hi Will, thanks a lot for sharing! The Gist looked great!

This was really helpful!

Here is my final .luarc.json at the root of the project

{
  "telemetry.enable": false,
  "runtime.version": "Lua 5.4",
  "runtime.special": {
    "import": "require"
  },
  "runtime.nonstandardSymbol": ["+=", "-=", "*=", "/="],
  "diagnostics.globals": [
    "playdate",
    "json"
  ],
  "diagnostics.disable": ["redefined-local"],
  "diagnostics.neededFileStatus": {
    "codestyle-check": "Any"
  },
  "diagnostics.libraryFiles": "Disable",
  "completion.callSnippet": "Replace",
  "workspace.library": ["$PLAYDATE_SDK_PATH/CoreLibs"],
  "workspace.ignoreDir": ["Source/external"]
}

1 Like

Hi all, thanks for this helpful guide! I've got neovim set up for playdate dev now, using coc-lua and the helpful configs posted here. I'm new to playdate, and new to lua, so I'm struggling now to figure out if this issue is one that can be resolved:

I'm guessing this may be because the language server doesn't know about playdate's special object orientation 'library'? Has anyone else run into this issue and got it working? It's not the end of the world, but it does litter my code with these diagnostic errors, and I'm not really clear if the 'objects' returned by the call to .new actually have the correct methods available on them.

Just checked and I have the same issue :frowning:

I got annoyed by the amount of warning the LSP diagnostics was throwing so I disabled the rule on my localconfig

"diagnostics.disable": ["redefined-local", "undefined-field"],

It seems is a change on the 3.0 version of the LSP server

1 Like

Glad to see I'm not the only one struggling with this same issue... developing only with a TUI is possible ? How do you do when testing on the Playdate? The simulator is cool but when we have no GUI.. :smile:

I try to use print statements until I fail, then I launch VSCode only for debugging haha