-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: debugger, code run, and profile settings (#3)
- Loading branch information
1 parent
c0b6c0d
commit 24cb02f
Showing
25 changed files
with
659 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local M = {} | ||
local utils = require("csharp.utils") | ||
local notify = require("csharp.notify") | ||
|
||
--- @async | ||
local function _execute() | ||
local project_information = require("csharp.features.workspace-information").select_project() | ||
|
||
if project_information == nil then | ||
logger.error("No project selected", { feature = "code-runner" }) | ||
return | ||
end | ||
|
||
local project_folder_path = vim.fn.fnamemodify(project_information.Path, ":h") | ||
|
||
local launch_profile = require("csharp.modules.launch-settings").select_launch_profile(project_folder_path) | ||
|
||
local opt = { | ||
"--project", | ||
project_information.Path, | ||
"-c", | ||
"Debug", | ||
} | ||
|
||
if launch_profile then | ||
opt = vim.list_extend(opt, { "--launch-profile", launch_profile.name }) | ||
end | ||
|
||
require("csharp.modules.dotnet-cli").run(opt) | ||
end | ||
|
||
function M.execute() | ||
utils.run_async(_execute) | ||
end | ||
|
||
return M |
26 changes: 26 additions & 0 deletions
26
lua/csharp/features/debugger/config_factories/attach-debugger.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
local ui = require("csharp.ui") | ||
|
||
--- @async | ||
--- @param args DebugConfigFactoryArgs | ||
--- @return table | ||
local function create_config(args) | ||
local processes = require("dap.utils").get_processes() | ||
local process = ui.select_sync(processes, { | ||
format_item = function(item) | ||
return item.name | ||
end, | ||
}) | ||
|
||
return { | ||
name = "Attach - .NET", | ||
request = "attach", | ||
type = "coreclr", | ||
processId = process.pid, | ||
} | ||
end | ||
|
||
return { | ||
name = "Attach - .NET", | ||
request = "attach", | ||
create_config = create_config, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local M = {} | ||
local ui = require("csharp.ui") | ||
|
||
--- @class DebugConfigFactoryArgs | ||
--- @field project_information OmnisharpProjectInformation? | ||
|
||
--- @class DebugConfigFactory | ||
--- @field name string | ||
--- @field request "launch"|"attach" | ||
--- @field create_config fun(args: DebugConfigFactoryArgs): table | ||
|
||
--- @type DebugConfigFactory[] | ||
local debug_config_factories = { | ||
require("csharp.features.debugger.config_factories.launch-debugger"), | ||
require("csharp.features.debugger.config_factories.attach-debugger"), | ||
} | ||
|
||
--- @async | ||
--- @return DebugConfigFactory | ||
function M.select_debug_config() | ||
return ui.select_sync(debug_config_factories, { | ||
prompt = "Start Debugging:", | ||
format_item = function(item) | ||
return item.name | ||
end, | ||
}) | ||
end | ||
|
||
return M |
31 changes: 31 additions & 0 deletions
31
lua/csharp/features/debugger/config_factories/launch-debugger.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local dap = require("dap") | ||
|
||
--- @async | ||
--- @param args DebugConfigFactoryArgs | ||
--- @return table | ||
local function create_config(args) | ||
local project_folder_path = vim.fn.fnamemodify(args.project_information.Path, ":h") | ||
|
||
local build_succeded = require("csharp.modules.dotnet-cli").build(args.project_information.Path, { "-c Debug" }) | ||
|
||
if not build_succeded then | ||
logger.debug("Skip debugging, build failed!", { feature = "debugger" }) | ||
error("Skip debugging, build failed!") | ||
end | ||
|
||
return { | ||
name = "Launch - .NET", | ||
request = "launch", | ||
type = "coreclr", | ||
cwd = project_folder_path, | ||
program = args.project_information.TargetPath, | ||
args = {}, | ||
env = {}, | ||
} | ||
end | ||
|
||
return { | ||
name = "Launch - .NET", | ||
request = "launch", | ||
create_config = create_config, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
local M = {} | ||
local ui = require("csharp.ui") | ||
local dap = require("dap") | ||
local logger = require("csharp.log") | ||
local utils = require("csharp.utils") | ||
local notify = require("csharp.notify") | ||
local next = next | ||
|
||
--- @param debug_config table | ||
--- @param launch_profile DotNetLaunchProfile | ||
--- @return table | ||
local function apply_launch_profile(debug_config, launch_profile) | ||
if launch_profile.environmentVariables then | ||
for key, value in pairs(launch_profile.environmentVariables) do | ||
debug_config.env[key] = value | ||
end | ||
end | ||
|
||
if launch_profile.commandLineArgs then | ||
vim.tbl_deep_extend("force", debug_config.args, vim.split(launch_profile.commandLineArgs, " ", { trimempty = true })) | ||
end | ||
|
||
if launch_profile.applicationUrl then | ||
table.insert(debug_config.args, "--urls=" .. launch_profile.applicationUrl) | ||
end | ||
|
||
return debug_config | ||
end | ||
|
||
--- @async | ||
local function _execute() | ||
local debug_adapter = require("csharp.modules.dap").get_debug_adapter() | ||
if debug_adapter == nil then | ||
logger.error("Debug Adapter is not installed or configured.", { feature = "debugger" }) | ||
return | ||
end | ||
|
||
if next(dap.sessions()) ~= nil then | ||
logger.debug("Debugging is already running, using dap.continue().", { feature = "debugger" }) | ||
dap.continue() | ||
return | ||
end | ||
|
||
notify.info("Preparing debugger!") | ||
local debug_config_factory = require("csharp.features.debugger.config_factories").select_debug_config() | ||
local debug_config | ||
|
||
logger.debug("Selected debug config factory", { feature = "debugger", debug_config_factory = debug_config_factory }) | ||
if debug_config_factory.request == "attach" then | ||
debug_config = debug_config_factory.create_config({}) | ||
else | ||
local project_information = require("csharp.features.workspace-information").select_project() | ||
|
||
if project_information == nil then | ||
logger.error("No project selected", { feature = "debugger" }) | ||
return | ||
end | ||
|
||
debug_config = debug_config_factory.create_config({ project_information = project_information }) | ||
local project_folder_path = vim.fn.fnamemodify(project_information.Path, ":h") | ||
local launch_profile = require("csharp.modules.launch-settings").select_launch_profile(project_folder_path) | ||
|
||
if launch_profile then | ||
logger.debug("Applying launch profile to debug config.", { feature = "debugger", launch_profile = launch_profile, debug_config }) | ||
debug_config = apply_launch_profile(debug_config, launch_profile) | ||
end | ||
end | ||
|
||
logger.debug("Starting debugger", { feature = "debugger", debug_config = debug_config }) | ||
notify.info("Starting debugger!") | ||
dap.launch(debug_adapter, debug_config) | ||
end | ||
|
||
function M.execute() | ||
utils.run_async(_execute) | ||
end | ||
|
||
return M |
Oops, something went wrong.