lopi-py / luau-lsp.nvim

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

lsp errors out Unable to find default.project.json #29

Open Nizarll opened 3 weeks ago

Nizarll commented 3 weeks ago

heres my luau_lsp.lua :

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", "lua" },
              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 = {},
            platform = {
              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",
    },
  },
}
lopi-py commented 3 weeks ago

Make sure to start neovim in the same directory you have your default.project.json file. Also can you provide more information about the error? like the result of LuauLsp log and the steps to reproduce the issue.

It seems like you are you using LazyVim. If that's the case, the setup should be really simple:

return {
  {
    "nvim-treesitter/nvim-treesitter",
    opts = { ensure_installed = { "luau" } },
  },
  {
    "neovim/nvim-lspconfig",
    opts = {
      -- make sure mason installs the server
      servers = {
        luau_lsp = {},
      },
      setup = {
        luau_lsp = function()
          return true -- avoid duplicate servers (calling `lspconfig.luau_lsp.setup`)
        end,
      },
    },
  },
  {
    "lopi-py/luau-lsp.nvim",
    ft = "luau",
    opts = {
      -- your luau-lsp.nvim options
      -- all the options you put in the config you sent are already the default so no need to duplicate them
    },
  },
}
Nizarll commented 3 weeks ago

the problem was from not starting neovim in the same directory as the default.project.json since i thought utils.find_root_directory function in the configuration find the default.project.json according to the directory

lopi-py commented 3 weeks ago

@Nizarll Oops I edited your comment by accident, I've reverted it back to the original. Someone commented a spam (and potentially virus) link so I deleted it and maybe I got distracted and edited your comment.

the problem was from not starting neovim in the same directory as the default.project.json since i thought utils.find_root_directory function in the configuration find the default.project.json according to the directory

It could be the problem, the root_directory is only used for the server, not sourcemap generation. Try starting neovim in the same directory of the default.project.json.