This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDebugAdapterHostInvoker.cs
85 lines (73 loc) · 2.72 KB
/
DebugAdapterHostInvoker.cs
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
using System;
using System.IO;
using EnvDTE;
using Microsoft.VisualStudio.Shell;
using Task = System.Threading.Tasks.Task;
namespace AttachToDockerContainer
{
public class DebugAdapterHostLauncher
{
private readonly DTE _dte;
private DebugAdapterHostLauncher(DTE dte)
{
_dte = dte;
}
public void Launch(string containerName, string vsDbgPath, int pid)
{
ThreadHelper.ThrowIfNotOnUIThread();
// Need to create json file to pass to DebugAdapterHost.Launch
var launchJsonPath = CreateLaunchJson(containerName, vsDbgPath, pid);
try
{
_dte.ExecuteCommand("DebugAdapterHost.Launch", $"/LaunchJson:\"{launchJsonPath}\"");
}
finally
{
File.Delete(launchJsonPath);
}
}
private string CreateLaunchJson(string containerName, string vsDbgPath, int dotnetPid)
{
var jsonText = $@"
{{
""version"": ""0.2.0"",
""adapter"": ""docker.exe"",
""adapterArgs"": ""exec -i {containerName} {vsDbgPath} --interpreter=vscode"",
""languageMappings"": {{
""C#"": {{
""languageId"": ""3F5162F8-07C6-11D3-9053-00C04FA302A1"",
""extensions"": [ ""*"" ]
}}
}},
""exceptionCategoryMappings"": {{
""CLR"": ""449EC4CC-30D2-4032-9256-EE18EB41B62B"",
""MDA"": ""6ECE07A9-0EDE-45C4-8296-818D8FC401D4""
}},
""configurations"": [
{{
""name"": "".NET Core Docker Attach"",
""type"": ""coreclr"",
""request"": ""attach"",
""processId"": {dotnetPid}
}}
]
}}";
var fileName = $"LaunchJson.{Guid.NewGuid()}.json";
var path = Path.Combine(Path.GetTempPath(), fileName);
using (var file = File.CreateText(path))
{
file.Write(jsonText);
}
return path;
}
public static DebugAdapterHostLauncher Instance { get; private set; }
public static async Task InitializeAsync(AsyncPackage package)
{
// Switch to the main thread - the call to AddCommand in AttachToDockerContainerDialogCommand's constructor requires
// the UI thread.
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(package.DisposalToken);
var dte = await package.GetServiceAsync(typeof(DTE)) as DTE;
Instance = new DebugAdapterHostLauncher(dte);
}
}
}