-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move luaurc logic to another file
- Loading branch information
Showing
4 changed files
with
59 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
local json = require "luau-lsp.json" | ||
local log = require "luau-lsp.log" | ||
local util = require "luau-lsp.util" | ||
|
||
local M = {} | ||
|
||
---@param dirs string[] | ||
---@return string? | ||
function M.find_luaurc(dirs) | ||
if util.is_file ".luaurc" then | ||
return ".luaurc" | ||
end | ||
|
||
for _, dir in ipairs(dirs) do | ||
if util.is_file(vim.fs.joinpath(dir, ".luaurc")) then | ||
return vim.fs.joinpath(dir, ".luaurc") | ||
end | ||
end | ||
end | ||
|
||
---@param dirs? string[] | ||
---@return table<string, string>? | ||
function M.aliases(dirs) | ||
local path = M.find_luaurc(dirs or {}) | ||
if not path then | ||
return | ||
end | ||
|
||
local luaurc = io.open(path, "r") | ||
assert(luaurc) | ||
|
||
local ok, content = pcall(json.decode, luaurc:read "a") | ||
if not ok then | ||
log.error("Failed to read '.luaurc': %s", content) | ||
return | ||
end | ||
|
||
local aliases = vim.empty_dict() | ||
for alias, value in pairs(content.aliases or {}) do | ||
aliases["@" .. alias] = value | ||
end | ||
return aliases | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters