Skip to content

Commit d0bc068

Browse files
committed
♻️refactor(fortran): Removed options that might cause trouble due to execution order. They have been replaced by the new option Run this file. It's still possible to run multi file projects with the option FPM.
1 parent ca41461 commit d0bc068

1 file changed

Lines changed: 20 additions & 121 deletions

File tree

lua/compiler/languages/fortran.lua

Lines changed: 20 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -4,165 +4,64 @@ local M = {}
44

55
-- Frontend - options displayed on telescope
66
M.options = {
7-
{ text = "Build and run program", value = "option1" },
8-
{ text = "Build program", value = "option2" },
9-
{ text = "Run program", value = "option3" },
10-
{ text = "Build solution", value = "option4" },
11-
{ text = "", value = "separator" },
12-
{ text = "fpm build and run", value = "option5" },
13-
{ text = "fpm build", value = "option6" },
14-
{ text = "fpm run", value = "option7" },
7+
{ text = "Run this file", value = "option1" },
8+
{ text = "FPM build and run", value = "option2" },
9+
{ text = "FPM build", value = "option3" },
10+
{ text = "FPM run", value = "option4" },
1511
}
1612

1713
-- Backend - overseer tasks performed on option selected
1814
function M.action(selected_option)
1915
local utils = require("compiler.utils")
2016
local overseer = require("overseer")
21-
local entry_point = utils.os_path(vim.fn.getcwd() .. "/main.f90") -- working_directory/main.f90
22-
local output_dir = utils.os_path(vim.fn.getcwd() .. "/bin/") -- working_directory/bin/
23-
local output = utils.os_path(vim.fn.getcwd() .. "/bin/program") -- working_directory/bin/program
24-
local arguments = "-D warnings -g" -- arguments can be overriden in .solution
17+
local current_file = vim.fn.expand('%:p') -- current file
18+
local output_dir = utils.os_path(vim.fn.stdpath("cache") .. "/compiler/fortran/") -- working_directory/bin/
19+
local output = output_dir .. "program" -- working_directory/bin/program
20+
local arguments = "" -- arguments can be overriden in .solution
2521
local final_message = "--task finished--"
2622

2723
if selected_option == "option1" then
2824
local task = overseer.new_task({
2925
name = "- Fortran compiler",
3026
strategy = { "orchestrator",
31-
tasks = {{ "shell", name = "- Build & run program " .. entry_point,
27+
tasks = {{ "shell", name = "- Run this file " .. current_file,
3228
cmd = "rm -f " .. output .. " || true" .. -- clean
3329
" && mkdir -p " .. output_dir .. -- mkdir
34-
" && gfortran " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile
30+
" && gfortran " .. current_file .. " -o " .. output .. " " .. arguments .. -- compile
3531
" && " .. output .. -- run
36-
" && echo " .. entry_point .. -- echo
32+
" && echo " .. current_file .. -- echo
3733
" && echo '" .. final_message .. "'"
3834
},},},})
3935
task:start()
4036
vim.cmd("OverseerOpen")
4137
elseif selected_option == "option2" then
42-
local task = overseer.new_task({
43-
name = "- Fortran compiler",
44-
strategy = { "orchestrator",
45-
tasks = {{ "shell", name = "- Build program → " .. entry_point,
46-
cmd = "rm -f " .. output .. " || true" .. -- clean
47-
" && mkdir -p " .. output_dir .. -- mkdir
48-
" && gfortran " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile
49-
" && echo " .. entry_point .. -- echo
50-
" && echo '" .. final_message .. "'"
51-
},},},})
52-
task:start()
53-
vim.cmd("OverseerOpen")
54-
elseif selected_option == "option3" then
55-
local task = overseer.new_task({
56-
name = "- Fortran compiler",
57-
strategy = { "orchestrator",
58-
tasks = {{ "shell", name = "- Run program → " .. entry_point,
59-
cmd = output .. -- run
60-
" && echo " .. output .. -- echo
61-
" && echo '" .. final_message .. "'"
62-
},},},})
63-
task:start()
64-
vim.cmd("OverseerOpen")
65-
elseif selected_option == "option4" then
66-
local entry_points
67-
local task = {}
68-
local tasks = {}
69-
local executables = {}
70-
71-
-- if .solution file exists in working dir
72-
local solution_file = utils.get_solution_file()
73-
if solution_file then
74-
local config = utils.parse_solution_file(solution_file)
75-
76-
for entry, variables in pairs(config) do
77-
if entry == "executables" then goto continue end
78-
entry_point = utils.os_path(variables.entry_point)
79-
output = utils.os_path(variables.output)
80-
output_dir = utils.os_path(output:match("^(.-[/\\])[^/\\]*$"))
81-
arguments = variables.arguments or arguments -- optional
82-
task = { "shell", name = "- Build program → " .. entry_point,
83-
cmd = "rm -f " .. output .. " || true" .. -- clean
84-
" && mkdir -p " .. output_dir .. -- mkdir
85-
" && gfortran " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile
86-
" && echo " .. entry_point .. -- echo
87-
" && echo '" .. final_message .. "'"
88-
}
89-
table.insert(tasks, task) -- store all the tasks we've created
90-
::continue::
91-
end
92-
93-
local solution_executables = config["executables"]
94-
if solution_executables then
95-
for entry, executable in pairs(solution_executables) do
96-
task = { "shell", name = "- Run program → " .. executable,
97-
cmd = executable .. -- run
98-
" && echo " .. executable .. -- echo
99-
" && echo '" .. final_message .. "'"
100-
}
101-
table.insert(executables, task) -- store all the executables we've created
102-
end
103-
end
104-
105-
task = overseer.new_task({
106-
name = "- Fortran compiler", strategy = { "orchestrator",
107-
tasks = {
108-
tasks, -- Build all the programs in the solution in parallel
109-
executables -- Then run the solution executable(s)
110-
}}})
111-
task:start()
112-
vim.cmd("OverseerOpen")
113-
114-
else -- If no .solution file
115-
-- Create a list of all entry point files in the working directory
116-
entry_points = utils.find_files(vim.fn.getcwd(), "main.f90")
117-
118-
for _, entry_point in ipairs(entry_points) do
119-
entry_point = utils.os_path(entry_point)
120-
output_dir = utils.os_path(entry_point:match("^(.-[/\\])[^/\\]*$") .. "bin") -- entry_point/bin
121-
output = utils.os_path(output_dir .. "/program") -- entry_point/bin/program
122-
task = { "shell", name = "- Build program → " .. entry_point,
123-
cmd = "rm -f " .. output .. " || true" .. -- clean
124-
" && mkdir -p " .. output_dir .. -- mkdir
125-
" && gfortran " .. entry_point .. " -o " .. output .. " " .. arguments .. -- compile
126-
" && echo " .. entry_point .. -- echo
127-
" && echo '" .. final_message .. "'"
128-
}
129-
table.insert(tasks, task) -- store all the tasks we've created
130-
end
131-
132-
task = overseer.new_task({ -- run all tasks we've created in parallel
133-
name = "- Fortran compiler", strategy = { "orchestrator", tasks = tasks }
134-
})
135-
task:start()
136-
vim.cmd("OverseerOpen")
137-
end
138-
elseif selected_option == "option5" then
13938
local task = overseer.new_task({
14039
name = "- Fortran compiler",
14140
strategy = { "orchestrator",
14241
tasks = {{ "shell", name = "- fpm build & run → " .. "fpm.toml",
143-
cmd = "fpm build " .. -- compile
144-
" && fpm run" .. --run
145-
" && echo '" .. final_message .. "'" -- echo
42+
cmd = "fpm build " .. -- compile
43+
" && fpm run" .. -- run
44+
" && echo '" .. final_message .. "'" -- echo
14645
},},},})
14746
task:start()
14847
vim.cmd("OverseerOpen")
149-
elseif selected_option == "option6" then
48+
elseif selected_option == "option3" then
15049
local task = overseer.new_task({
15150
name = "- Fortran compiler",
15251
strategy = { "orchestrator",
15352
tasks = {{ "shell", name = "- fpm build → " .. "fpm.toml",
154-
cmd = "fpm build " .. -- compile
155-
" && echo '" .. final_message .. "'" -- echo
53+
cmd = "fpm build " .. -- compile
54+
" && echo '" .. final_message .. "'" -- echo
15655
},},},})
15756
task:start()
15857
vim.cmd("OverseerOpen")
159-
elseif selected_option == "option7" then
58+
elseif selected_option == "option4" then
16059
local task = overseer.new_task({
16160
name = "- Fortran compiler",
16261
strategy = { "orchestrator",
16362
tasks = {{ "shell", name = "- fpm run → " .. "fpm.toml",
164-
cmd = "fpm run " .. -- run
165-
" && echo '" .. final_message .. "'" -- echo
63+
cmd = "fpm run " .. -- run
64+
" && echo '" .. final_message .. "'" -- echo
16665
},},},})
16766
task:start()
16867
vim.cmd("OverseerOpen")

0 commit comments

Comments
 (0)