-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvscode.lua
More file actions
137 lines (112 loc) · 3.29 KB
/
vscode.lua
File metadata and controls
137 lines (112 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
--
-- Name: vscode.lua
-- Purpose: Define the vscode action(s).
-- Author: Ryan Pusztai
-- Modified by: Andrea Zanellato
-- Andrew Gough
-- Manu Evans
-- Jason Perkins
-- Yehonatan Ballas
-- Jan "GamesTrap" Schürkamp
-- Created: 2013/05/06
-- Updated: 2025/11/04
-- Copyright: (c) 2008-2020 Jason Perkins and the Premake project
-- (c) 2022-2025 Jan "GamesTrap" Schürkamp
--
local p = premake
local vscode = {}
p.modules.vscode = vscode
local function GetCProjects(wks)
local list = {}
local idx = 1
for prj in p.workspace.eachproject(wks) do
if p.project.isc(prj) or p.project.iscpp(prj) then
list[idx] = prj
idx = idx + 1
end
end
return list
end
-- Create .code-workspace file if it doesnt already exist
local function GenerateVSCodeWorkspaceFile(wks)
local workspaceFilename = string.format("%s.code-workspace", wks.name)
local workspacePath = p.filename(wks, workspaceFilename)
if os.isfile(workspacePath) then
return
end
p.generate(wks, workspaceFilename, function(wks)
p.push('{')
p.w('"folders":')
p.push('[')
p.push('{')
p.w('"path": "."')
p.pop('}')
p.pop(']')
p.pop('}')
p.outln('')
end)
end
-- Create tasks.json file
local function GenerateTasksFile(wks, cProjects)
local tasksPath = string.format("%s/.vscode/tasks.json", wks.location)
p.generate(wks, tasksPath, function(wks)
p.push('{')
p.w('"version": "2.0.0",')
p.w('"tasks":')
p.push('[')
for _, prj in ipairs(cProjects) do
vscode.project.vscode_tasks(prj)
end
if #cProjects > 0 then
vscode.project.vscode_tasks_build_all(wks)
end
p.pop(']')
p.pop('}')
p.outln('')
end)
end
-- Create launch.json file
local function GenerateLaunchFile(wks, cProjects)
local launchPath = string.format("%s/.vscode/launch.json", wks.location)
p.generate(wks, launchPath, function(wks)
p.push('{')
p.w('"version": "2.0.0",')
p.w('"configurations":')
p.push('[')
for idx, prj in ipairs(cProjects) do
vscode.project.vscode_launch(prj, idx == #cProjects)
end
p.pop(']')
p.pop('}')
p.outln('')
end)
end
-- Create c_cpp_properties.json file
local function GenerateCCppPropertiesFile(wks, cProjects)
if #cProjects == 0 then
return
end
local ccppPropertiesPath = string.format("%s/.vscode/c_cpp_properties.json", wks.location)
p.generate(wks, ccppPropertiesPath, function(wks)
p.push('{')
p.w('"version": 4,')
p.w('"configurations":')
p.push('[')
for idx, prj in ipairs(cProjects) do
vscode.project.vscode_c_cpp_properties(prj, idx == #cProjects)
end
p.pop(']')
p.pop('}')
p.outln('')
end)
end
function vscode.generateWorkspace(wks)
local cProjects = GetCProjects(wks)
GenerateVSCodeWorkspaceFile(wks)
GenerateTasksFile(wks, cProjects)
GenerateLaunchFile(wks, cProjects)
GenerateCCppPropertiesFile(wks, cProjects)
end
include("vscode_project.lua")
include("_preload.lua")
return vscode