Skip to content

Commit 18eea16

Browse files
authored
fix(csharpier): check if the dotnet command is available (#772)
:ConformInfo failed for me because i have csharpier installed via mason.nvim, but have no dotnet on my working machine This commit adds a check for this case while keeping the local csharpier available
1 parent 9d6f881 commit 18eea16

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

lua/conform/formatters/csharpier.lua

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
local COMMAND = "dotnet"
22
local TOOL = "csharpier"
3-
local cache = nil -- For performance
3+
4+
--- Ask the system if csharpier is installed as dotnet tool
5+
--- NOTE: prefer the cached variant
6+
---@return boolean
7+
local function is_local_long()
8+
if vim.fn.executable(COMMAND) == 0 then
9+
return false -- if dotnet itself is not available, assume the csharpier executable
10+
end
11+
12+
local version_check = vim.system({ COMMAND, TOOL, "--version" }):wait()
13+
return version_check.code == 0 -- try calling dotnet tool
14+
end
15+
16+
local is_local_cache = nil
417

518
--- Verify if csharpier is installed locally.
619
---@return boolean
720
local function is_local()
8-
if cache == nil then
9-
local obj = vim.system({ COMMAND, TOOL, "--version" }):wait()
10-
cache = obj.code == 0
21+
if is_local_cache == nil then
22+
is_local_cache = is_local_long()
1123
end
12-
return cache
24+
return is_local_cache
1325
end
1426

1527
--- Get command favoring locally installed csharpier.

0 commit comments

Comments
 (0)