unity debugging
This commit is contained in:
1 parent
26085ed02b
commit
e5f6d0d9a4
3 files changed
+105
No files matched your search
@@ -268,6 +268,62 @@ return {
|
||||
end
|
||||
|
||||
dap.configurations.c = dap.configurations.cpp
|
||||
|
||||
-- Unity (Mono soft debugger) via Unity's MIT-licensed vscode-unity-debug
|
||||
-- adapter, extracted from its .vsix into stdpath("data")/unity-debug.
|
||||
-- Avoids vstuc, whose license (like vsdbg's) is VS Code only.
|
||||
--
|
||||
-- UnityDebug.exe is patched by unity-debug/install.sh (see patch.cs there;
|
||||
-- original kept as UnityDebug.exe.orig): stock, it only matches editor
|
||||
-- processes named exactly "Unity"/"Unity Editor", but Unity Hub launches
|
||||
-- the editor as "unityhub-unity-editor-<version>". The patch makes it a
|
||||
-- case-insensitive "Unity" prefix match, covering both launch methods and
|
||||
-- any version. Helper processes (UnityPackageManager, import workers...)
|
||||
-- match too, so the adapter picks the real editor by the process_id in
|
||||
-- EditorInstance.json -- which needs the config name to contain "Editor".
|
||||
local unity_debug_exe = vim.fn.stdpath("data") .. "/unity-debug/extension/bin/UnityDebug.exe"
|
||||
local unity_debug_install = vim.fn.stdpath("config") .. "/unity-debug/install.sh"
|
||||
dap.adapters.unity = function(callback)
|
||||
if vim.fn.filereadable(unity_debug_exe) == 0 then
|
||||
vim.notify("Installing Unity debug adapter...")
|
||||
local result = vim.system({ unity_debug_install }, { text = true }):wait()
|
||||
if result.code ~= 0 then
|
||||
vim.notify("Unity debug adapter install failed:\n" .. result.stderr, vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
end
|
||||
callback({
|
||||
type = "executable",
|
||||
command = "mono",
|
||||
args = { unity_debug_exe },
|
||||
-- The adapter strips the leading "/" from `path` (a Windows-ism)
|
||||
-- before reading it, so run it from / for the now-relative path
|
||||
-- to resolve.
|
||||
options = { cwd = "/" },
|
||||
})
|
||||
end
|
||||
|
||||
-- Library/EditorInstance.json only exists while the editor is open; the
|
||||
-- adapter reads the editor PID from it to derive the debugger port.
|
||||
-- The Unity project may sit in a repo subfolder, so search upward from
|
||||
-- the buffer first, then downward from cwd.
|
||||
local function unity_editor_instance()
|
||||
local root = vim.fs.root(0, "ProjectSettings")
|
||||
if root then
|
||||
return root .. "/Library/EditorInstance.json"
|
||||
end
|
||||
local found = vim.fs.find("EditorInstance.json", { path = vim.fn.getcwd(), type = "file", limit = 1 })
|
||||
return found[1]
|
||||
end
|
||||
|
||||
dap.configurations.cs = {
|
||||
{
|
||||
name = "Unity Editor",
|
||||
type = "unity",
|
||||
request = "launch", -- unity-debug attaches to the running editor despite "launch"
|
||||
path = unity_editor_instance,
|
||||
},
|
||||
}
|
||||
end
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user