Skip to content

Commit 61018a8

Browse files
committed
Typing for elan's state, and a toolchain list function.
1 parent 3e2dbf7 commit 61018a8

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

lua/lean/elan.lua

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
local subprocess_check_output = require('lean._util').subprocess_check_output
2-
local elan = {}
2+
local elan = { toolchain = {} }
3+
4+
---Elan's dumped state, which can partially change from project to project.
5+
---@class ElanState
6+
---@field elan_version ElanVersionInfo
7+
---@field toolchains ElanToolchainInfo
8+
9+
---@class ElanVersionInfo
10+
---@field current string elan's own version
11+
---@field newest table
12+
13+
---Information about installed and active Lean toolchains.
14+
---@class ElanToolchainInfo
15+
---@field active_override? table information about an overridden toolchain for the current project
16+
---@field default? table information about the default toolchain
17+
---@field installed ElanToolchain[] the currently installed toolchains
18+
---@field resolved_active table information about the resolved active toolchain
19+
20+
---A single toolchain.
21+
---@class ElanToolchain
22+
---@field path string the path to the toolchain on this machine
23+
---@field resolved_name string the identifier for this toolchain
24+
25+
--List the installed toolchains.
26+
function elan.toolchain.list()
27+
local state = elan.state()
28+
return vim
29+
.iter(state.toolchains.installed)
30+
:map(function(each)
31+
return each.resolved_name
32+
end)
33+
:totable()
34+
end
335

436
---Dump elan's state.
5-
---@return table
37+
---@return ElanState
638
function elan.state()
739
local stdout = subprocess_check_output { 'elan', 'dump-state' }
840
return vim.json.decode(stdout)

0 commit comments

Comments
 (0)