Skip to content

Commit e3d3c2f

Browse files
authored
Merge pull request #52 from Shad0wRim/main
Add support for Gleam
2 parents 4ad0395 + e8cf7c2 commit e3d3c2f

9 files changed

Lines changed: 156 additions & 14 deletions

File tree

lua/compiler/languages/gleam.lua

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
--- Gleam language actions
2+
3+
local M = {}
4+
5+
-- Frontend - options displayed on telescope
6+
M.options = {
7+
{ text = "Gleam build and run", value = "option1" },
8+
{ text = "Gleam build", value = "option2" },
9+
{ text = "Gleam run", value = "option3" },
10+
}
11+
12+
-- Backend - overseer tasks performed on option selected
13+
function M.action(selected_option)
14+
local overseer = require("overseer")
15+
local final_message = "--task finished--"
16+
17+
if selected_option == "option1" then
18+
local task = overseer.new_task({
19+
name = "- Gleam compiler",
20+
strategy = { "orchestrator",
21+
tasks = {{ name = "- gleam build & run → " .. "\"./gleam.toml\"",
22+
cmd = "gleam build " .. -- compile
23+
" && gleam run" .. -- run
24+
" && echo \"" .. final_message .. "\"", -- echo
25+
components = { "default_extended" }
26+
},},},})
27+
task:start()
28+
elseif selected_option == "option2" then
29+
local task = overseer.new_task({
30+
name = "- Gleam compiler",
31+
strategy = { "orchestrator",
32+
tasks = {{ name = "- gleam build → " .. "\"./gleam.toml\"",
33+
cmd = "gleam build " .. -- compile
34+
" && echo \"" .. final_message .. "\"", -- echo
35+
components = { "default_extended" }
36+
},},},})
37+
task:start()
38+
elseif selected_option == "option3" then
39+
local task = overseer.new_task({
40+
name = "- Gleam compiler",
41+
strategy = { "orchestrator",
42+
tasks = {{ name = "- gleam run → " .. "\"./gleam.toml\"",
43+
cmd = "gleam run " .. -- compile
44+
" && echo \"" .. final_message .. "\"", -- echo
45+
components = { "default_extended" }
46+
},},},})
47+
task:start()
48+
end
49+
end
50+
51+
return M
52+
53+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name = "build_and_run"
2+
version = "1.0.0"
3+
4+
# Fill out these fields if you intend to generate HTML documentation or publish
5+
# your project to the Hex package manager.
6+
#
7+
# description = ""
8+
# licences = ["Apache-2.0"]
9+
# repository = { type = "github", user = "", repo = "" }
10+
# links = [{ title = "Website", href = "" }]
11+
#
12+
# For a full reference of all the available options, you can have a look at
13+
# https://gleam.run/writing-gleam/gleam-toml/.
14+
15+
[dependencies]
16+
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
17+
18+
[dev-dependencies]
19+
gleeunit = ">= 1.0.0 and < 2.0.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import hello_world
2+
3+
pub fn main() {
4+
hello_world.hello_world()
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import gleam/io
2+
3+
pub fn hello_world() -> Nil {
4+
io.println("Hello, world!")
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name = "build"
2+
version = "1.0.0"
3+
4+
# Fill out these fields if you intend to generate HTML documentation or publish
5+
# your project to the Hex package manager.
6+
#
7+
# description = ""
8+
# licences = ["Apache-2.0"]
9+
# repository = { type = "github", user = "", repo = "" }
10+
# links = [{ title = "Website", href = "" }]
11+
#
12+
# For a full reference of all the available options, you can have a look at
13+
# https://gleam.run/writing-gleam/gleam-toml/.
14+
15+
[dependencies]
16+
gleam_stdlib = ">= 0.34.0 and < 2.0.0"
17+
18+
[dev-dependencies]
19+
gleeunit = ">= 1.0.0 and < 2.0.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import hello_world
2+
3+
pub fn main() {
4+
hello_world.hello_world()
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import gleam/io
2+
3+
pub fn hello_world() -> Nil {
4+
io.println("Hello, world!")
5+
}

tests/tests.lua

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ coroutine.resume(coroutine.create(function()
3030
sleep(5000)
3131
dofile(tests_dir .. 'fsharp.lua')
3232
sleep(5000)
33+
dofile(tests_dir .. 'gleam.lua')
34+
sleep(5000)
3335
dofile(tests_dir .. 'go.lua')
3436
sleep(25000)
3537
dofile(tests_dir .. 'java.lua')
@@ -62,18 +64,18 @@ coroutine.resume(coroutine.create(function()
6264
sleep(5000)
6365
dofile(tests_dir .. 'zig.lua')
6466

65-
-- Cases that require to be tested manually atm.
66-
-- * python → Run this file.
67-
-- * ruby → Run this file.
68-
-- * shell → Run this file.
69-
-- * elixir → Run this file.
70-
-- * fortran → Run this file.
71-
-- * fsharp → Run this file.
72-
-- * r → Run this file.
73-
-- * typescript → Run this file.
74-
-- * javascript → Run this file.
75-
-- * dart → Run this file.
76-
-- * python/r/elixir/F#/kotlin/swift → REPL
77-
-- * flutter → Run program (its a loop).
78-
--
67+
-- Cases that require to be tested manually atm.
68+
-- * python → Run this file.
69+
-- * ruby → Run this file.
70+
-- * shell → Run this file.
71+
-- * elixir → Run this file.
72+
-- * fortran → Run this file.
73+
-- * fsharp → Run this file.
74+
-- * r → Run this file.
75+
-- * typescript → Run this file.
76+
-- * javascript → Run this file.
77+
-- * dart → Run this file.
78+
-- * python/r/elixir/F#/kotlin/swift → REPL
79+
-- * flutter → Run program (its a loop).
80+
--
7981
end))

tests/tests/languages/gleam.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--- This test file run all supported cases of use.
2+
--- @usage :luafile ~/.local/share/nvim/lazy/compiler.nvim/tests/tests/languages/gleam.lua
3+
4+
local ms = 1000 -- wait time
5+
local language = require("compiler.languages.gleam")
6+
local example = require("compiler.utils").get_tests_dir("code samples/languages/gleam/")
7+
8+
coroutine.resume(coroutine.create(function()
9+
local co = coroutine.running()
10+
local function sleep()
11+
vim.defer_fn(function() coroutine.resume(co) end, ms)
12+
coroutine.yield()
13+
end
14+
15+
-- Build and run
16+
vim.api.nvim_set_current_dir(example .. "build-and-run/")
17+
language.action("option1")
18+
sleep()
19+
20+
-- Build
21+
vim.api.nvim_set_current_dir(example .. "build/")
22+
language.action("option2")
23+
sleep()
24+
25+
-- Run
26+
vim.api.nvim_set_current_dir(example .. "build/")
27+
language.action("option3")
28+
sleep()
29+
end))

0 commit comments

Comments
 (0)