lopi-py / luau-lsp.nvim

A luau-lsp extension to improve your experience in neovim.
MIT License
46 stars 10 forks source link

How do i use this with lsp config, and lazy.nvim. #4

Closed CapedBojji closed 10 months ago

CapedBojji commented 10 months ago

Title is self explanatory, i dont get if this is a plugin or the lsp client itself

lopi-py commented 10 months ago

You need to download the client by yourself, I suggest to use mason. This plugin helps you to properly set up the client via lspconfig, install this like any other plugin. You can see how to integrate this with mason in the readme.md

CapedBojji commented 10 months ago

I figured it out, I will submit an updated docs, because the docs is very confusing for begginers thank you

lopi-py commented 10 months ago

So what is confusing about the docs? tell me so I can improve the docs

CapedBojji commented 10 months ago

i think, you should include examples on how to use it with the popular plugin managers. Its not as simple as requiring it, you also have to add the plugin as a dependency. i kept getting luau-lsp not found till i figured that out

return {
  {
    "williamboman/mason.nvim",
    dependencies = {
      "williamboman/mason-lspconfig.nvim",
      "lopi-py/luau-lsp.nvim",
    },
    config = function(_, opts)
      require("mason").setup(opts)
      local mr = require("mason-registry")
      mr:on("package:install:success", function()
        vim.defer_fn(function()
          -- trigger FileType event to possibly load this newly installed LSP server
          require("lazy.core.handler.event").trigger({
            event = "FileType",
            buf = vim.api.nvim_get_current_buf(),
          })
        end, 100)
      end)

      local mason_lspconfig = require("mason-lspconfig")
      mason_lspconfig.setup_handlers({
        luau_lsp = function()
          require("luau-lsp").setup({
            server = {
              filetypes = { "luau" }, -- default is { "luau" }
              capabilities = vim.lsp.protocol.make_client_capabilities(),
              root_dir = function(path)
                local util = require("lspconfig.util")
                return util.find_git_ancestor(path)
                  or util.root_pattern(
                    ".luaurc",
                    "selene.toml",
                    "stylua.toml",
                    "aftman.toml",
                    "wally.toml",
                    "mantle.yml",
                    "*.project.json"
                  )(path)
              end,
            },
            settings = {},
            types = {
              roblox = true,
            },
            sourcemap = {
              enable = true,
              rojo_path = "rojo",
            },
          })
        end,
      })
      mason_lspconfig.setup({
        ensure_installed = {
          "luau_lsp",
        },
        automatic_installation = true,
      })
    end,
  },

  {
    "neovim/nvim-lspconfig",
    opts = {
      servers = {
        luau_lsp = {},
      },
      setup = {},
    },
    event = {
      "BufReadPre",
      "BufNewFile",
      "BufEnter",
      "BufUnload",
    },
  },
}

This is the lazy.nvim version of it

CapedBojji commented 10 months ago

image here is a better image of it