Skip to content

Commit

Permalink
Added support for C# language
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Nilsson committed Jun 26, 2023
1 parent a734d5b commit 84712ee
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 120 deletions.
2 changes: 1 addition & 1 deletion _preload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ newaction {

-- Capabilities
valid_kinds = { "ConsoleApp", "WindowedApp", "Makefile", "SharedLib", "StaticLib", "Utility" },
valid_languages = { "C", "C++" },
valid_languages = { "C", "C++", "C#" },
valid_tools = { "gcc", "clang", "msc" },

onStart = function()
Expand Down
22 changes: 11 additions & 11 deletions vscode.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@ function vscode.generateProject(prj)

if (project.isc(prj) or project.iscpp(prj)) then
p.generate(prj, prj.location .. "/.vscode/c_cpp_properties.json", vscode.project.cCppProperties.generate)
end

local isLaunchable = false
local isLaunchable = false

for cfg in project.eachconfig(prj) do
isLaunchable = cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp"
for cfg in project.eachconfig(prj) do
isLaunchable = cfg.kind == "ConsoleApp" or cfg.kind == "WindowedApp"

if isLaunchable then
break
end
end
if isLaunchable then
break
end
end

if isLaunchable then
p.generate(prj, prj.location .. "/.vscode/launch.json", vscode.project.launch.generate)
end
end
if isLaunchable then
p.generate(prj, prj.location .. "/.vscode/launch.json", vscode.project.launch.generate)
end
end

function vscode.configName(config, includePlatform)
Expand Down
6 changes: 3 additions & 3 deletions vscode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ function cCppProperties.includeDirs(prj, cfg)
-- NOTE(Peter): VS Code currently doesn't have a property for external include dirs or system include dirs

for _, includedir in ipairs(cfg.sysincludedirs) do
p.w('"%s",', includedir)
p.w('"%s",', includedir:gsub([[\]], "/"))
end

for _, includedir in ipairs(cfg.externalincludedirs) do
p.w('"%s",', includedir)
p.w('"%s",', includedir:gsub([[\]], "/"))
end

for _, includedir in ipairs(cfg.includedirs) do
p.w('"%s",', includedir)
p.w('"%s",', includedir:gsub([[\]], "/"))
end

p.pop('],')
Expand Down
105 changes: 0 additions & 105 deletions vscode_workspace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,111 +38,6 @@ function m.generate(wks)
end

local tasks = vscode.workspace.tasks
--[[tasks.taskLabels = {}
tasks.toolsetPaths = {
["windows"] = {
["msc"] = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.35.32215/bin/Hostx64/x64/cl.exe",
["clang"] = "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/Llvm/x64/bin/clang-cl.exe"
},
["linux"] = {
["gcc"] = "/usr/bin/g++",
["clang"] = "/usr/bin/clang++"
}
}
tasks.problemMatchers = {
["msc"] = "msCompile",
["clang"] = "gcc", -- No problem matcher for clang currently?
["gcc"] = "gcc"
}
tasks.configProps = function(prj, cfg)
return {
tasks.gatherFiles,
tasks.type,
tasks.label,
tasks.command,
tasks.args,
tasks.problemMatcher,
tasks.dependsOn
}
end
function tasks.gatherFiles(prj, cfg)
local tr = project.getsourcetree(prj)
tree.traverse(tr, {
onleaf = function(node, depth)
table.insert(prj.__vscode.files, node.abspath)
end
}, true)
end
function tasks.type(prj, cfg)
p.w('"type": "shell",')
end
function tasks.getTaskLabel(prj, cfg)
local configName = vscode.configName(cfg, #prj.workspace.platforms > 1)
local toolsetName = vscode.getToolsetName(cfg)
local taskLabel = "C/C++: Build " .. prj.name .. " (" .. configName .. ", " .. toolsetName .. ")"
return taskLabel
end
-- Label: C/C++: Build {ProjectName} {ToolsetName}
function tasks.label(prj, cfg)
local taskLabel = tasks.getTaskLabel(prj, cfg)
p.w('"label": "%s",', taskLabel)
end
function tasks.command(prj, cfg)
local toolsetName = vscode.getToolsetName(cfg)
local compileCommand = tasks.toolsetPaths[cfg.system][toolsetName]
p.w('"command": "%s",', compileCommand)
end
function tasks.args(prj, cfg)
local toolsetName = vscode.getToolsetName(cfg)
local toolsetModule = nil
if toolsetName == "msc" then
toolsetModule = vscode.msc
end
if toolsetModule == nil then
error("Unknown toolset")
end
local compilerFlags = toolsetModule.getCompilerFlags(prj, cfg)
p.push('"args": [')
for _, flag in ipairs(compilerFlags) do
p.w('"%s",', vscode.esc(flag))
end
for _, file in ipairs(prj.__vscode.files) do
p.w('"%s",', vscode.esc(file))
end
p.pop('],')
end
function tasks.problemMatcher(prj, cfg)
local toolsetName = vscode.getToolsetName(cfg)
p.w('"problemMatcher": "$%s",', tasks.problemMatchers[toolsetName])
end
function tasks.dependsOn(prj, cfg)
local dependencies = project.getdependencies(prj, cfg)
if #dependencies > 0 then
p.push('"dependsOn": [')
for _, dependency in ipairs(dependencies) do
local dependencyTaskName = tasks.getTaskLabel(dependency, cfg)
p.w('"%s",', dependencyTaskName)
end
p.pop(']')
end
end]]--

function tasks.buildSolutionTask(wks)
local solutionFile = p.filename(wks, ".sln")
Expand Down

0 comments on commit 84712ee

Please sign in to comment.