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?

5 Likes

Add a feature request

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

1 Like

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!