Skip to content

Commit

Permalink
fix: server binary not found when root directory is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
lopi-py committed Aug 18, 2024
1 parent 727ec51 commit 69f8c6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Fixed

- Error loading the server when root directory not found
- Definition files that depend on Roblox types will now load properly
- Merge internal modified capabilities with the default client capabilities if not specified in the server config
- Sourcemap generation and studio server will only start if the configured platform is `roblox`
Expand Down
26 changes: 12 additions & 14 deletions lua/luau-lsp/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,6 @@ local function get_cmd()
return cmd
end

---@return string?
local function get_root_dir()
local bufnr = vim.api.nvim_get_current_buf()
return config.get().server.root_dir(vim.api.nvim_buf_get_name(bufnr))
end

--- Patch shared settings between the client extension and the server
local function get_settings()
return {
Expand All @@ -107,7 +101,7 @@ end
--- Neovim does not support diagnostic's relatedDocuments, but push-based diagnostics should work
--- fine
---
---@param opts luau-lsp.ClientConfig
---@param opts vim.lsp.ClientConfig
local function force_push_diagnostics(opts)
local capabilities = opts.capabilities or vim.lsp.protocol.make_client_capabilities()
opts.capabilities = vim.tbl_deep_extend("force", capabilities, {
Expand All @@ -128,13 +122,17 @@ end
---@async
---@return number?
local function start_language_server()
local opts = vim.tbl_deep_extend("force", config.get().server, {
name = "luau-lsp",
root_dir = get_root_dir(),
cmd = get_cmd(),
settings = get_settings(),
init_options = { fflags = get_fflags() },
})
local bufnr = vim.api.nvim_get_current_buf()
local bufname = vim.api.nvim_buf_get_name(bufnr)

local opts = vim.deepcopy(config.get().server) --[[@as vim.lsp.ClientConfig]]
opts.name = "luau-lsp"
opts.cmd = get_cmd()
opts.root_dir = opts.root_dir(bufname)
opts.settings = vim.tbl_deep_extend("force", opts.settings or {}, get_settings())
opts.init_options = {
fflags = get_fflags(),
}

force_push_diagnostics(opts)

Expand Down

0 comments on commit 69f8c6e

Please sign in to comment.