├── .gitignore ├── LICENSE ├── README.md └── src └── AskChatGPT ├── AskChatGPT.csproj ├── AskChatGPT.sln ├── AskChatGPTPackage.cs ├── ChatGPT ├── ChatApi.cs ├── Models │ ├── ChatMessage.cs │ └── ResponseModel.cs └── ShowChatGPTWindow.cs ├── Commands └── ChatToolWindowCommand.cs ├── Data └── ChatDbContext.cs ├── Options └── AdvancedOptions.cs ├── Properties └── AssemblyInfo.cs ├── Resources ├── Delete.png ├── Icon.png └── Remove.png ├── ToolWindows ├── ChatToolWindow.cs ├── ChatToolWindowControl.xaml ├── ChatToolWindowControl.xaml.cs ├── ChatToolWindowControlViewModel.cs ├── Converters │ ├── BoolToVisibilityConverter.cs │ ├── InverseBoolToVisibilityConverter.cs │ └── TrimStringConverter.cs └── Templates │ └── ComboBoxTemplateSelector.cs ├── Utils ├── BrowserWrapper.cs ├── MarkdownToHtmlConverter.cs ├── MarkupCodeHighlighter.cs ├── highlight-dark.css ├── highlight.css ├── mathjax.js ├── md-template.html ├── mermaid.min.js ├── mermaid.min.js.LICENSE.txt ├── mermaid.min.js.map ├── prism-dark.css ├── prism.css └── prism.js ├── VSCommandTable.cs ├── VSCommandTable.vsct ├── source.extension.cs └── source.extension.vsixmanifest /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 adospace 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AskChatGPT Visual Studio Extension 2 | This extension for Visual Studio 2022 allows you to chat with ChatGPT directly inside the IDE. 3 | 4 | The tool is integrated into the environment so that you can ask questions about your code, see answers with syntax highlighting and copy back to your classes or functions returned code. 5 | 6 | Before using the extension you have to: 7 | 8 | Obtain an API key from the OpenAI website at this URL: https://platform.openai.com/account/api-keys 9 | Create an environment variable called OPENAI_API_KEY with the created key 10 | This tool is completely free under a permissive MIT license but the OpenAI service has a cost (https://openai.com/pricing) 11 | 12 | [Download at Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=adospace.AskChatGPT) 13 | 14 | https://user-images.githubusercontent.com/10573253/223367601-11e8ba71-0ef3-47b6-9523-8e5ea6be4233.mp4 15 | 16 | -------------------------------------------------------------------------------- /src/AskChatGPT/AskChatGPT.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 5 | latest 6 | 7 | 8 | 9 | Debug 10 | AnyCPU 11 | 2.0 12 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3} 14 | Library 15 | Properties 16 | AskChatGPT 17 | AskChatGPT 18 | v4.8 19 | true 20 | true 21 | true 22 | true 23 | false 24 | true 25 | true 26 | Program 27 | $(DevEnvDir)devenv.exe 28 | /rootsuffix Exp 29 | 30 | 31 | true 32 | full 33 | false 34 | bin\Debug\ 35 | DEBUG;TRACE 36 | prompt 37 | 4 38 | 39 | 40 | pdbonly 41 | true 42 | bin\Release\ 43 | TRACE 44 | prompt 45 | 4 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | True 59 | True 60 | source.extension.vsixmanifest 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | True 72 | True 73 | VSCommandTable.vsct 74 | 75 | 76 | 77 | 78 | 79 | 80 | true 81 | 82 | 83 | true 84 | 85 | 86 | true 87 | 88 | 89 | true 90 | 91 | 92 | true 93 | 94 | 95 | true 96 | 97 | 98 | true 99 | 100 | 101 | true 102 | 103 | 104 | true 105 | 106 | 107 | Designer 108 | VsixManifestGenerator 109 | source.extension.cs 110 | 111 | 112 | PreserveNewest 113 | true 114 | 115 | 116 | true 117 | 118 | 119 | 120 | 121 | Menus.ctmenu 122 | VsctGenerator 123 | VSCommandTable.cs 124 | 125 | 126 | 127 | 128 | 129 | Designer 130 | MSBuild:Compile 131 | 132 | 133 | ChatToolWindowControl.xaml 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | compile; build; native; contentfiles; analyzers; buildtransitive 150 | 151 | 152 | 8.1.0 153 | 154 | 155 | 2.1.24 156 | 157 | 158 | 0.31.0 159 | 160 | 161 | 8.0.0 162 | 163 | 164 | runtime; build; native; contentfiles; analyzers; buildtransitive 165 | all 166 | 167 | 168 | 1.0.1587.40 169 | 170 | 171 | 2.1.6 172 | 173 | 174 | 2.1.6 175 | True 176 | 177 | 178 | 179 | 180 | 181 | 182 | true 183 | . 184 | 185 | 186 | 193 | -------------------------------------------------------------------------------- /src/AskChatGPT/AskChatGPT.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.5.33326.253 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AskChatGPT", "AskChatGPT.csproj", "{0B0027CC-1A77-47D9-AA3C-8377436ABFB3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|arm64 = Debug|arm64 12 | Debug|x86 = Debug|x86 13 | Release|Any CPU = Release|Any CPU 14 | Release|arm64 = Release|arm64 15 | Release|x86 = Release|x86 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Debug|arm64.ActiveCfg = Debug|arm64 21 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Debug|arm64.Build.0 = Debug|arm64 22 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Debug|x86.ActiveCfg = Debug|x86 23 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Debug|x86.Build.0 = Debug|x86 24 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Release|arm64.ActiveCfg = Release|arm64 27 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Release|arm64.Build.0 = Release|arm64 28 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Release|x86.ActiveCfg = Release|x86 29 | {0B0027CC-1A77-47D9-AA3C-8377436ABFB3}.Release|x86.Build.0 = Release|x86 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {A2AD889F-4010-4236-8752-B273A93BE101} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /src/AskChatGPT/AskChatGPTPackage.cs: -------------------------------------------------------------------------------- 1 | global using Community.VisualStudio.Toolkit; 2 | global using Microsoft.VisualStudio.Shell; 3 | global using System; 4 | global using Task = System.Threading.Tasks.Task; 5 | using AskChatGPT.Options; 6 | using Microsoft.VisualStudio; 7 | using System.Runtime.InteropServices; 8 | using System.Threading; 9 | 10 | namespace AskChatGPT 11 | { 12 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] 13 | [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)] 14 | [ProvideToolWindow(typeof(ChatToolWindow.Pane), Style = VsDockStyle.Tabbed, Window = WindowGuids.SolutionExplorer)] 15 | [ProvideToolWindowVisibility(typeof(ChatToolWindow.Pane), VSConstants.UICONTEXT.SolutionHasSingleProject_string)] 16 | [ProvideToolWindowVisibility(typeof(ChatToolWindow.Pane), VSConstants.UICONTEXT.SolutionHasMultipleProjects_string)] 17 | [ProvideToolWindowVisibility(typeof(ChatToolWindow.Pane), VSConstants.UICONTEXT.NoSolution_string)] 18 | [ProvideToolWindowVisibility(typeof(ChatToolWindow.Pane), VSConstants.UICONTEXT.EmptySolution_string)] 19 | 20 | [ProvideOptionPage(typeof(OptionsProvider.AdvancedOptions), "ChatGPT", "ChatGPT Helper Tool", 0, 0, true, new[] { "help", "chat", "gpt" })] 21 | [ProvideMenuResource("Menus.ctmenu", 1)] 22 | [Guid(PackageGuids.AskChatGPTString)] 23 | public sealed class AskChatGPTPackage : ToolkitPackage 24 | { 25 | protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) 26 | { 27 | await this.RegisterCommandsAsync(); 28 | 29 | this.RegisterToolWindows(); 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /src/AskChatGPT/ChatGPT/ChatApi.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Net.Http; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using AskChatGPT.ChatGPT.Models; 9 | using AskChatGPT.Options; 10 | 11 | namespace AskChatGPT.ChatGPT; 12 | 13 | class ChatApi 14 | { 15 | readonly HttpClient _httpClientApi; 16 | 17 | private const string API_URL = "https://api.openai.com/v1/chat/completions"; 18 | 19 | private static readonly JsonSerializerSettings _defaultSerializerContext = 20 | new JsonSerializerSettings 21 | { 22 | NullValueHandling = NullValueHandling.Ignore, 23 | }; 24 | 25 | public ChatApi() 26 | { 27 | _httpClientApi = new HttpClient(); 28 | } 29 | 30 | public bool IsValid => !string.IsNullOrWhiteSpace(AdvancedOptions.Instance.ApiKey); 31 | 32 | public async Task> Prompt(IEnumerable messages) 33 | { 34 | _httpClientApi.DefaultRequestHeaders.Authorization = 35 | new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AdvancedOptions.Instance.ApiKey); 36 | 37 | var body = new 38 | { 39 | model = AdvancedOptions.Instance.GptModel, 40 | messages 41 | }; 42 | 43 | var bodyAsString = JsonConvert.SerializeObject(body, _defaultSerializerContext); 44 | 45 | var response = await _httpClientApi.PostAsync(API_URL, new StringContent(bodyAsString, Encoding.UTF8, "application/json")); 46 | 47 | response.EnsureSuccessStatusCode(); 48 | 49 | var responseAsString = await response.Content.ReadAsStringAsync(); 50 | 51 | var responseModel = JsonConvert.DeserializeObject(responseAsString); 52 | 53 | if (responseModel == null) 54 | { 55 | throw new InvalidOperationException(); 56 | } 57 | 58 | return responseModel.Choices.Select(_ => _.Message); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/AskChatGPT/ChatGPT/Models/ChatMessage.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AskChatGPT.ChatGPT.Models; 9 | 10 | record ChatMessageModel([property: JsonProperty("role")] string Role, [property: JsonProperty("content")] string Content); 11 | -------------------------------------------------------------------------------- /src/AskChatGPT/ChatGPT/Models/ResponseModel.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AskChatGPT.ChatGPT.Models; 9 | 10 | /* 11 | { 12 | "id": "chatcmpl-6q3Ge0ngjcpy47XXITLq3Nfs9mnvK", 13 | "object": "chat.completion", 14 | "created": 1677863636, 15 | "model": "gpt-3.5-turbo-0301", 16 | "usage": { 17 | "prompt_tokens": 9, 18 | "completion_tokens": 12, 19 | "total_tokens": 21 20 | }, 21 | "choices": [ 22 | { 23 | "message": { 24 | "role": "assistant", 25 | "content": "\n\nHello there! How may I assist you today?" 26 | }, 27 | "finish_reason": "stop", 28 | "index": 0 29 | } 30 | ] 31 | } 32 | */ 33 | 34 | record ResponseModel( 35 | [property: JsonProperty("id")] string Id, 36 | [property: JsonProperty("object")] string Object, 37 | [property: JsonProperty("created")] int Created, 38 | [property: JsonProperty("choices")] ResponseChoiceModel[] Choices, 39 | [property: JsonProperty("usage")] UsageModel Usage 40 | ); 41 | 42 | record ResponseChoiceModel( 43 | [property: JsonProperty("index")] string Index, 44 | [property: JsonProperty("message")] ChatMessageModel Message, 45 | [property: JsonProperty("finish_reason")] string FinishReason 46 | ); 47 | 48 | record UsageModel( 49 | [property: JsonProperty("prompt_tokens")] int PromptTokens, 50 | [property: JsonProperty("completion_tokens")] int CompletionTokens, 51 | [property: JsonProperty("total_tokens")] int TotalTokens 52 | ); -------------------------------------------------------------------------------- /src/AskChatGPT/ChatGPT/ShowChatGPTWindow.cs: -------------------------------------------------------------------------------- 1 | using CommunityToolkit.Mvvm.Messaging.Messages; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace AskChatGPT.ChatGPT; 9 | 10 | record ShowChatGPTWindow(string CodeChunk); 11 | 12 | class ShowChatGPTWindowMessage : ValueChangedMessage 13 | { 14 | public ShowChatGPTWindowMessage(ShowChatGPTWindow _) : base(_) 15 | { 16 | } 17 | } -------------------------------------------------------------------------------- /src/AskChatGPT/Commands/ChatToolWindowCommand.cs: -------------------------------------------------------------------------------- 1 | using AskChatGPT.ChatGPT; 2 | using CommunityToolkit.Mvvm.Messaging; 3 | using Microsoft.VisualStudio.Text; 4 | using System.Linq; 5 | 6 | namespace AskChatGPT 7 | { 8 | [Command(PackageIds.MyCommand)] 9 | internal sealed class ChatToolWindowCommand : BaseCommand 10 | { 11 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 12 | { 13 | await ChatToolWindow.ShowAsync(); 14 | 15 | DocumentView docView = await VS.Documents.GetActiveDocumentViewAsync(); 16 | NormalizedSnapshotSpanCollection selections = docView.TextView?.Selection.SelectedSpans; 17 | 18 | if (selections == null) 19 | return; 20 | 21 | var selectedCode = selections.FirstOrDefault().GetText(); 22 | 23 | WeakReferenceMessenger.Default.Send( 24 | new ShowChatGPTWindowMessage( 25 | new ShowChatGPTWindow(selectedCode))); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/AskChatGPT/Data/ChatDbContext.cs: -------------------------------------------------------------------------------- 1 | using AskChatGPT.Options; 2 | using Dapper; 3 | using Microsoft.Data.Sqlite; 4 | using Microsoft.VisualStudio.LanguageServer.Client; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Threading.Tasks; 11 | using static Microsoft.VisualStudio.Shell.ThreadedWaitDialogHelper; 12 | 13 | namespace AskChatGPT.Data; 14 | 15 | //public class ChatDbContext : DbContext 16 | //{ 17 | // protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 18 | // { 19 | // optionsBuilder.UseSqlite($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 20 | // } 21 | 22 | // public DbSet Sessions { get; set; } 23 | 24 | // public DbSet Messages { get; set; } 25 | //} 26 | 27 | public class ChatDbRepository 28 | { 29 | public async Task MigrateAsync() 30 | { 31 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 32 | 33 | await connection.ExecuteAsync(""" 34 | CREATE TABLE IF NOT EXISTS "Sessions" ( 35 | "Id" INTEGER NOT NULL CONSTRAINT "PK_Sessions" PRIMARY KEY AUTOINCREMENT, 36 | "Name" TEXT NULL, 37 | "Created" TEXT NOT NULL, 38 | "TimeStamp" TEXT NOT NULL 39 | ) 40 | """); 41 | 42 | await connection.ExecuteAsync(""" 43 | CREATE TABLE IF NOT EXISTS "Messages" ( 44 | "Id" INTEGER NOT NULL CONSTRAINT "PK_Messages" PRIMARY KEY AUTOINCREMENT, 45 | "SessionId" INTEGER NOT NULL, 46 | "Role" TEXT NULL, 47 | "Content" TEXT NULL, 48 | CONSTRAINT "FK_Messages_Sessions_SessionId" FOREIGN KEY ("SessionId") REFERENCES "Sessions" ("Id") ON DELETE CASCADE 49 | ) 50 | """); 51 | 52 | await connection.ExecuteAsync(""" 53 | CREATE INDEX IF NOT EXISTS "IX_Messages_SessionId" ON "Messages" ("SessionId") 54 | """); 55 | } 56 | 57 | public async Task> GetSessionsAsync() 58 | { 59 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 60 | return await connection.QueryAsync($"SELECT * FROM Sessions ORDER BY TimeStamp DESC LIMIT {AdvancedOptions.Instance.SessionLimit};"); 61 | } 62 | 63 | public async Task> GetMessagesAsync(int sessionId) 64 | { 65 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 66 | return await connection.QueryAsync("SELECT * FROM Messages WHERE SessionId = @SessionId ORDER BY Id;", new { SessionId = sessionId }); 67 | } 68 | 69 | public async Task InsertSessionsAsync(params ChatSession[] sessions) 70 | { 71 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 72 | await connection.ExecuteAsync(""" 73 | INSERT INTO Sessions Name, Created, TimeStamp) 74 | VALUES (@Name, @Created, @TimeStamp) 75 | """, sessions); 76 | } 77 | 78 | public async Task InsertSessionAsync(ChatSession session) 79 | { 80 | //select last_insert_rowid() 81 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 82 | var id = await connection.ExecuteScalarAsync(""" 83 | INSERT INTO Sessions (Name, Created, TimeStamp) 84 | VALUES (@Name, @Created, @TimeStamp) 85 | RETURNING Id; 86 | """, session); 87 | 88 | session.Id = id; 89 | } 90 | 91 | public async Task UpdateSessionsAsync(params ChatSession[] sessions) 92 | { 93 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 94 | await connection.ExecuteAsync(""" 95 | UPDATE Sessions 96 | SET Id = @Id, 97 | Name = @Name, 98 | Created = @Created, 99 | TimeStamp = @TimeStamp 100 | WHERE Id = @Id 101 | """, sessions); 102 | } 103 | 104 | public async Task InsertMessagesAsync(params ChatMessage[] messages) 105 | { 106 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 107 | await connection.ExecuteAsync(""" 108 | INSERT INTO Messages (SessionId, Role, Content) 109 | VALUES (@SessionId, @Role, @Content) 110 | """, messages); 111 | } 112 | 113 | public async Task DeleteSessionsAsync(params int[] ids) 114 | { 115 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 116 | foreach (var id in ids) 117 | { 118 | await connection.ExecuteAsync(""" 119 | DELETE FROM Sessions 120 | WHERE Id = @id 121 | """, new { id }); 122 | } 123 | } 124 | public async Task DeleteMessagesAsync(params int[] ids) 125 | { 126 | using var connection = new SqliteConnection($"Data Source={Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "chat.db")}"); 127 | foreach (var id in ids) 128 | { 129 | await connection.ExecuteAsync(""" 130 | DELETE FROM Messages 131 | WHERE Id = @id 132 | """, new { id }); 133 | } 134 | } 135 | } 136 | 137 | public class ChatSession 138 | { 139 | public int Id { get; set; } 140 | 141 | public string Name { get; set; } 142 | 143 | //public List Messages { get; set; } 144 | 145 | public DateTime Created { get; set; } 146 | 147 | public DateTime TimeStamp { get; set; } 148 | } 149 | 150 | public class ChatMessage 151 | { 152 | public int Id { get; set; } 153 | 154 | public int SessionId { get; set; } 155 | 156 | //public ChatSession Session { get; set; } 157 | 158 | public string Role { get; set; } 159 | 160 | public string Content { get; set; } 161 | 162 | } -------------------------------------------------------------------------------- /src/AskChatGPT/Options/AdvancedOptions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Linq; 5 | using System.Runtime.InteropServices; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace AskChatGPT.Options; 10 | 11 | internal class OptionsProvider 12 | { 13 | [ComVisible(true)] 14 | public class AdvancedOptions : BaseOptionPage { } 15 | } 16 | 17 | public class AdvancedOptions : BaseOptionModel, IRatingConfig 18 | { 19 | [DisplayName("Dark theme support")] 20 | [Description("Determines if the ChatGPT Helper tool window should render in dark mode when a dark Visual Studio theme is in use.")] 21 | [DefaultValue(Theme.Automatic)] 22 | [TypeConverter(typeof(EnumConverter))] 23 | public Theme Theme { get; set; } = Theme.Automatic; 24 | 25 | [DisplayName("Preferred source language")] 26 | [Description("Highlight code snippets according to the selected language.")] 27 | [DefaultValue("csharp")] 28 | public string PreferredSourceLanguage { get; set; } = "csharp"; 29 | 30 | [DisplayName("OpenAI Model")] 31 | [Description("Select the OpenAI model used to query chatGPT.\r\nFor example: gpt-3.5-turbo, gpt-4, or gpt-4-32k (more info: https://platform.openai.com/docs/models)")] 32 | [DefaultValue("gpt-3.5-turbo")] 33 | public string GptModel { get; set; } = "gpt-3.5-turbo"; 34 | 35 | [Browsable(false)] 36 | public int RatingRequests { get; set; } 37 | 38 | [DisplayName("OpenAI API Key")] 39 | [Description("Enter the API Key required to access OpenAI ChatGPT.")] 40 | public string ApiKey { get; set; } = Environment.GetEnvironmentVariable("OPENAI_API_KEY"); 41 | 42 | [DisplayName("Sessions count")] 43 | [Description("Total number of active chat sessions.")] 44 | [DefaultValue("40")] 45 | public int SessionLimit { get; set; } = 40; 46 | 47 | [DisplayName("Prompt")] 48 | [Description("Enter the prompt (system message) you want to use for each chat session.")] 49 | public string Prompt { get; set; } 50 | 51 | } 52 | 53 | public enum Theme 54 | { 55 | Automatic, 56 | Dark, 57 | Light, 58 | } 59 | -------------------------------------------------------------------------------- /src/AskChatGPT/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using AskChatGPT; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle(Vsix.Name)] 6 | [assembly: AssemblyDescription(Vsix.Description)] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany(Vsix.Author)] 9 | [assembly: AssemblyProduct(Vsix.Name)] 10 | [assembly: AssemblyCopyright(Vsix.Author)] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: AssemblyVersion(Vsix.Version)] 17 | [assembly: AssemblyFileVersion(Vsix.Version)] 18 | 19 | namespace System.Runtime.CompilerServices 20 | { 21 | public class IsExternalInit { } 22 | } -------------------------------------------------------------------------------- /src/AskChatGPT/Resources/Delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adospace/chatgpt-vs-tool/3cd9c220103e218bdf9a3fcc9482a9c47566bf5a/src/AskChatGPT/Resources/Delete.png -------------------------------------------------------------------------------- /src/AskChatGPT/Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adospace/chatgpt-vs-tool/3cd9c220103e218bdf9a3fcc9482a9c47566bf5a/src/AskChatGPT/Resources/Icon.png -------------------------------------------------------------------------------- /src/AskChatGPT/Resources/Remove.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adospace/chatgpt-vs-tool/3cd9c220103e218bdf9a3fcc9482a9c47566bf5a/src/AskChatGPT/Resources/Remove.png -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/ChatToolWindow.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualStudio.Imaging; 2 | using System.Runtime.InteropServices; 3 | using System.Threading; 4 | using System.Threading.Tasks; 5 | using System.Windows; 6 | 7 | namespace AskChatGPT; 8 | 9 | public class ChatToolWindow : BaseToolWindow 10 | { 11 | public override string GetTitle(int toolWindowId) => "ChatGPT Helper Tool"; 12 | 13 | public override Type PaneType => typeof(Pane); 14 | 15 | public override Task CreateAsync(int toolWindowId, CancellationToken cancellationToken) 16 | { 17 | return Task.FromResult(new ChatToolWindowControl()); 18 | } 19 | 20 | [Guid("789371c0-258b-43da-a1cf-86e5222ae2ed")] 21 | internal class Pane : ToolkitToolWindowPane 22 | { 23 | public Pane() 24 | { 25 | BitmapImageMoniker = KnownMonikers.ToolWindow; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/ChatToolWindowControl.xaml: -------------------------------------------------------------------------------- 1 |  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 | 63 | 64 | 67 | 68 | 69 | 70 | 85 | 86 | 87 | 91 | 92 | 98 | 99 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 117 | 118 | 121 | 130 | 131 | 141 | 142 | 147 | Add additional code 148 | 149 | 150 | 153 | 167 | 168 | 172 | Unable to find the ChatGPT key. 173 | 174 | 175 | 1. Please create an OpenAI ChatGPT API Key here: 176 | 177 | https://platform.openai.com/account/api-keys 178 | 179 | 2) Enter the key from VisualStudio menu Tools->AskChatGPT 180 | 181 | 182 | 189 | 190 | 191 | 192 | -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/ChatToolWindowControl.xaml.cs: -------------------------------------------------------------------------------- 1 | using AskChatGPT.ToolWindows; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | 5 | namespace AskChatGPT 6 | { 7 | public partial class ChatToolWindowControl : UserControl 8 | { 9 | public ChatToolWindowControl() 10 | { 11 | InitializeComponent(); 12 | 13 | this.Loaded += ChatToolWindowControl_Loaded; 14 | } 15 | 16 | private async void ChatToolWindowControl_Loaded(object sender, RoutedEventArgs e) 17 | { 18 | await ((ChatToolWindowControlViewModel)DataContext).InitializeAsync(); 19 | } 20 | 21 | private async void NewSession_Click(object sender, RoutedEventArgs e) 22 | { 23 | await ((ChatToolWindowControlViewModel)DataContext).NewMessageAsync(); 24 | } 25 | 26 | private void SelectedSessionIndexChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) 27 | { 28 | var comboBox = (ComboBox)sender; 29 | System.Diagnostics.Debug.WriteLine(comboBox.SelectedIndex); 30 | 31 | } 32 | 33 | private void ShowAdditionalCodeBox(object sender, RoutedEventArgs e) 34 | { 35 | ((ChatToolWindowControlViewModel)DataContext).IsAdditionalSourceCodeBoxVisible = true; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/ChatToolWindowControlViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.ComponentModel; 5 | using System.IO; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Text.RegularExpressions; 9 | using System.Threading.Tasks; 10 | using System.Windows; 11 | using System.Windows.Media.Animation; 12 | using AskChatGPT.ChatGPT; 13 | using AskChatGPT.ChatGPT.Models; 14 | using AskChatGPT.Data; 15 | using AskChatGPT.Options; 16 | using AskChatGPT.Utils; 17 | using CommunityToolkit.Mvvm; 18 | using CommunityToolkit.Mvvm.ComponentModel; 19 | using CommunityToolkit.Mvvm.Input; 20 | using CommunityToolkit.Mvvm.Messaging; 21 | using EnvDTE; 22 | using Markdig; 23 | using Markdig.Renderers; 24 | using Microsoft.Web.WebView2.Wpf; 25 | using Newtonsoft.Json; 26 | 27 | namespace AskChatGPT.ToolWindows; 28 | 29 | partial class ChatToolWindowControlViewModel : ObservableObject, IRecipient 30 | { 31 | readonly ChatApi _api = null; 32 | readonly MarkdownToHtmlConverter _markdownToHtmlConverter = new(); 33 | 34 | readonly BrowserWrapper _browser; 35 | 36 | readonly static MarkupCodeHighlighter _markupCodeHighlighter = new (); 37 | 38 | public ChatToolWindowControlViewModel() 39 | { 40 | PromptCommand = new AsyncRelayCommand(PromptAsync, () => IsNotBusy); 41 | DeleteSessionCommand = new AsyncRelayCommand(DeleteSessionAsync, () => IsNotBusy); 42 | 43 | _browser = new BrowserWrapper(OnCopyCodeToClipboard); 44 | _browser.Initialized += Browser_Initialized; 45 | 46 | WeakReferenceMessenger.Default.Register(this); 47 | 48 | _api = new ChatApi(); 49 | } 50 | 51 | private async void Browser_Initialized(object sender, EventArgs e) 52 | { 53 | await UpdateMarkdownToBrowserAsync(); 54 | } 55 | 56 | protected override async void OnPropertyChanged(PropertyChangedEventArgs e) 57 | { 58 | if (e.PropertyName == nameof(CurrentSession)) 59 | { 60 | await SelectCurrentSessionAsync(); 61 | await UpdateMarkdownToBrowserAsync(); 62 | } 63 | 64 | base.OnPropertyChanged(e); 65 | } 66 | 67 | public WebView2 BrowserView => _browser.WebView; 68 | 69 | public Visibility OpenAIMissingVisibility => _api.IsValid ? Visibility.Collapsed : Visibility.Visible; 70 | 71 | private bool _isAdditionalSourceCodeBoxVisible; 72 | 73 | public bool IsAdditionalSourceCodeBoxVisible 74 | { 75 | get => _isAdditionalSourceCodeBoxVisible; 76 | set => SetProperty(ref _isAdditionalSourceCodeBoxVisible, value); 77 | } 78 | 79 | private string _currentCommandText; 80 | 81 | public string CurrentCommandText 82 | { 83 | get => _currentCommandText; 84 | set => SetProperty(ref _currentCommandText, value); 85 | } 86 | 87 | private ObservableCollection _recentCommands = new(); 88 | 89 | public ObservableCollection RecentCommands 90 | { 91 | get => _recentCommands; 92 | } 93 | 94 | private string _currentSourceCode; 95 | 96 | public string CurrentSourceCode 97 | { 98 | get => _currentSourceCode; 99 | set => SetProperty(ref _currentSourceCode, value); 100 | } 101 | 102 | private ObservableCollection _messages = new(); 103 | 104 | public ObservableCollection Messages 105 | { 106 | get => _messages; 107 | set => SetProperty(ref _messages, value); 108 | } 109 | 110 | private ObservableCollection _sessions = []; 111 | 112 | public ObservableCollection Sessions 113 | { 114 | get => _sessions; 115 | set => SetProperty(ref _sessions, value); 116 | } 117 | 118 | public ChatSession _currentSession = new ChatSession 119 | { 120 | Name = "New Chat Session", 121 | Created = DateTime.Now, 122 | TimeStamp = DateTime.Now, 123 | }; 124 | 125 | public ChatSession CurrentSession 126 | { 127 | get => _currentSession; 128 | set 129 | { 130 | if (value != null) 131 | { 132 | SetProperty(ref _currentSession, value); 133 | OnPropertyChanged(nameof(CurrentSessionName)); 134 | } 135 | } 136 | } 137 | 138 | private async Task SelectCurrentSessionAsync() 139 | { 140 | if (_currentSession != null && _currentSession.Id != 0) 141 | { 142 | var chatRepo = new ChatDbRepository(); 143 | var messages = await chatRepo.GetMessagesAsync(_currentSession.Id); 144 | Messages = new ObservableCollection(messages); 145 | } 146 | } 147 | 148 | public string CurrentSessionName 149 | { 150 | get => _currentSession?.Name; 151 | set 152 | { 153 | if (_currentSession != null && value != typeof(ChatSession).FullName) 154 | { 155 | _currentSession.Name = value; 156 | OnPropertyChanged(nameof(CurrentSessionName)); 157 | } 158 | } 159 | } 160 | 161 | private string _messagesAsMarkdown; 162 | 163 | public string MessagesAsMarkdown 164 | { 165 | get => _messagesAsMarkdown; 166 | set => SetProperty(ref _messagesAsMarkdown, value); 167 | } 168 | 169 | private bool _isBusy; 170 | 171 | public bool IsBusy 172 | { 173 | get => _isBusy; 174 | set 175 | { 176 | SetProperty(ref _isBusy, value); 177 | OnPropertyChanged(nameof(IsNotBusy)); 178 | OnPropertyChanged(nameof(IsBusyIndicatorVisibility)); 179 | OnPropertyChanged(nameof(IsNotBusyIndicatorVisibility)); 180 | } 181 | } 182 | 183 | public bool IsNotBusy => !IsBusy; 184 | public Visibility IsBusyIndicatorVisibility => IsBusy ? Visibility.Visible : Visibility.Collapsed; 185 | public Visibility IsNotBusyIndicatorVisibility => !IsBusy ? Visibility.Visible : Visibility.Collapsed; 186 | 187 | private string _errorMessage; 188 | 189 | public string ErrorMessage 190 | { 191 | get => _errorMessage; 192 | set 193 | { 194 | SetProperty(ref _errorMessage, value); 195 | OnPropertyChanged(nameof(ErrorMessageVisibility)); 196 | } 197 | } 198 | 199 | public Visibility ErrorMessageVisibility => string.IsNullOrEmpty(_errorMessage) ? Visibility.Collapsed : Visibility.Visible; 200 | 201 | public IAsyncRelayCommand PromptCommand { get; } 202 | 203 | public IAsyncRelayCommand DeleteSessionCommand { get; } 204 | 205 | public async Task InitializeAsync() 206 | { 207 | var chatRepo = new ChatDbRepository(); 208 | await chatRepo.MigrateAsync(); 209 | 210 | var sessions = await chatRepo.GetSessionsAsync(); 211 | 212 | Sessions = new ObservableCollection(sessions); 213 | var firstSession = sessions.FirstOrDefault(); 214 | if (firstSession != null) 215 | { 216 | CurrentSession = firstSession; 217 | 218 | var messages = await chatRepo.GetMessagesAsync(_currentSession.Id); 219 | 220 | Messages = new ObservableCollection(messages); 221 | 222 | await UpdateMarkdownToBrowserAsync(); 223 | } 224 | else 225 | { 226 | Sessions.Add(CurrentSession); 227 | } 228 | } 229 | 230 | private async Task DeleteSessionAsync() 231 | { 232 | if (CurrentSession == null) 233 | { 234 | return; 235 | } 236 | 237 | var sessionIndex = Sessions.IndexOf(CurrentSession); 238 | 239 | var chatRepo = new ChatDbRepository(); 240 | await chatRepo.DeleteSessionsAsync(CurrentSession.Id); 241 | 242 | Sessions.Remove(CurrentSession); 243 | 244 | if (sessionIndex == Sessions.Count) 245 | { 246 | sessionIndex--; 247 | } 248 | 249 | if (sessionIndex >= 0 && 250 | sessionIndex <= Sessions.Count - 1) 251 | { 252 | CurrentSession = Sessions[sessionIndex]; 253 | } 254 | else 255 | { 256 | Sessions.Add(new ChatSession 257 | { 258 | Name = "New Chat Session", 259 | Created = DateTime.Now, 260 | TimeStamp = DateTime.Now, 261 | }); 262 | 263 | CurrentSession = Sessions.Last(); 264 | 265 | Messages = new ObservableCollection(); 266 | 267 | await UpdateMarkdownToBrowserAsync(); 268 | } 269 | } 270 | 271 | public async Task PromptAsync() 272 | { 273 | if (!_api.IsValid || !_browser.IsInitialized) 274 | { 275 | return; 276 | } 277 | 278 | if (string.IsNullOrWhiteSpace(CurrentCommandText)) 279 | { 280 | return; 281 | } 282 | 283 | IsBusy = true; 284 | 285 | try 286 | { 287 | var promptMessage = new ChatMessageModel("user", 288 | string.IsNullOrWhiteSpace(CurrentSourceCode) 289 | ? 290 | CurrentCommandText 291 | : 292 | $@"{CurrentCommandText} 293 | ``` 294 | {CurrentSourceCode} 295 | ``` 296 | "); 297 | var promptMessages = new List(); 298 | 299 | if (!string.IsNullOrWhiteSpace(AdvancedOptions.Instance.Prompt)) 300 | { 301 | var systemMessage = new ChatMessageModel("system", AdvancedOptions.Instance.Prompt); 302 | 303 | promptMessages.Add(systemMessage); 304 | } 305 | 306 | var replyMessages = await _api.Prompt(promptMessages 307 | .Concat(_messages.Select(_ => new ChatMessageModel(_.Role, _.Content))) 308 | .Concat(new[] { promptMessage })); 309 | 310 | var chatRepo = new ChatDbRepository(); 311 | 312 | if (_currentSession.Id == 0) 313 | { 314 | _sessions.Remove(_currentSession); 315 | 316 | var sessionName = CurrentCommandText 317 | .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries) 318 | .FirstOrDefault(_ => !string.IsNullOrWhiteSpace(_)) ?? "New Chat Session"; 319 | 320 | Sessions.Add(new ChatSession 321 | { 322 | Name = sessionName, 323 | Created = DateTime.Now, 324 | TimeStamp = DateTime.Now 325 | }); 326 | 327 | CurrentSession = Sessions.Last(); 328 | 329 | await chatRepo.InsertSessionAsync(CurrentSession); 330 | } 331 | else 332 | { 333 | _currentSession.TimeStamp = DateTime.Now; 334 | await chatRepo.UpdateSessionsAsync(_currentSession); 335 | } 336 | 337 | var newPromptMessage = new ChatMessage 338 | { 339 | Role = "user", 340 | Content = promptMessage.Content, 341 | SessionId = _currentSession.Id 342 | }; 343 | 344 | //chatDbContext.Messages.Add(newPromptMessage); 345 | await chatRepo.InsertMessagesAsync(newPromptMessage); 346 | _messages.Add(newPromptMessage); 347 | 348 | var newMessages = new List(); 349 | foreach (var reply in replyMessages) 350 | { 351 | var newReplyMessage = new ChatMessage 352 | { 353 | Role = reply.Role, 354 | Content = reply.Content, 355 | SessionId = _currentSession.Id 356 | }; 357 | 358 | newMessages.Add(newReplyMessage); 359 | 360 | _messages.Add(newReplyMessage); 361 | } 362 | 363 | await chatRepo.InsertMessagesAsync(newMessages.ToArray()); 364 | 365 | await UpdateMarkdownToBrowserAsync(); 366 | 367 | CurrentCommandText = string.Empty; 368 | CurrentSourceCode = string.Empty; 369 | 370 | ErrorMessage = null; 371 | 372 | IsAdditionalSourceCodeBoxVisible = false; 373 | } 374 | catch (Exception ex) 375 | { 376 | ErrorMessage = ex.Message; 377 | } 378 | finally 379 | { 380 | IsBusy = false; 381 | } 382 | } 383 | 384 | private async Task UpdateMarkdownToBrowserAsync() 385 | { 386 | if (!_browser.IsInitialized) 387 | { 388 | return; 389 | } 390 | 391 | MessagesAsMarkdown = _markupCodeHighlighter.TransformMarkdown( 392 | string.Join(Environment.NewLine + Environment.NewLine, 393 | Messages.Select(_ => 394 | { 395 | if (_.Role != "user") 396 | { 397 | return $@"{_.Content} 398 | 399 | --- 400 | "; 401 | } 402 | else //if (_.Role == "user") 403 | { 404 | return $"You: {_.Content}"; 405 | } 406 | }))); 407 | 408 | var html = await _markdownToHtmlConverter.ConvertToHtml(MessagesAsMarkdown); 409 | 410 | await _browser.UpdateBrowserAsync(html); 411 | } 412 | 413 | internal async Task NewMessageAsync() 414 | { 415 | //ChatSessions.Clear(); 416 | //ChatMessages.Clear(); 417 | Sessions.Add(new ChatSession 418 | { 419 | Name = "New Chat Session" 420 | }); 421 | CurrentSession = Sessions.Last(); 422 | Messages.Clear(); 423 | 424 | CurrentCommandText = string.Empty; 425 | CurrentSourceCode = string.Empty; 426 | 427 | _markupCodeHighlighter.ClearCopyCodeLinks(); 428 | 429 | await UpdateMarkdownToBrowserAsync(); 430 | 431 | IsAdditionalSourceCodeBoxVisible = false; 432 | } 433 | 434 | //private void SaveCurrentCommandToRecentList() 435 | //{ 436 | // var currentText = Regex.Replace(_currentCommandText.Trim(), @"\s+", " "); 437 | 438 | // if (string.IsNullOrWhiteSpace(currentText)) 439 | // { 440 | // return; 441 | // } 442 | 443 | // var existingCommand = RecentCommands 444 | // .FirstOrDefault(_ => string.Compare(_, currentText, true) == 0); 445 | 446 | // if (existingCommand != null) 447 | // { 448 | // RecentCommands.Remove(existingCommand); 449 | // } 450 | 451 | // RecentCommands.Insert(0, currentText); 452 | // if (RecentCommands.Count == 21) 453 | // { 454 | // RecentCommands.RemoveAt(20); 455 | // } 456 | 457 | // CurrentCommandText = string.Empty; 458 | // CurrentSourceCode = string.Empty; 459 | 460 | // File.WriteAllText( 461 | // Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "recent_commands.json"), 462 | // JsonConvert.SerializeObject(RecentCommands)); 463 | //} 464 | 465 | void OnCopyCodeToClipboard(string copyId) 466 | { 467 | _markupCodeHighlighter.Copy(copyId); 468 | } 469 | 470 | public void Receive(ShowChatGPTWindowMessage message) 471 | { 472 | if (message.Value?.CodeChunk != null) 473 | { 474 | CurrentSourceCode = message.Value.CodeChunk; 475 | } 476 | } 477 | } 478 | 479 | //record ChatMessageSession(ChatMessageModel Prompt, ChatMessageModel[] Replies); 480 | -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/Converters/BoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | using System.Windows.Data; 9 | 10 | namespace AskChatGPT.ToolWindows.Converters; 11 | 12 | public class BoolToVisibilityConverter : IValueConverter 13 | { 14 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 15 | { 16 | if (value is bool boolValue) 17 | { 18 | return boolValue ? Visibility.Visible : Visibility.Collapsed; 19 | } 20 | 21 | return value; 22 | } 23 | 24 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 25 | { 26 | throw new NotImplementedException(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/Converters/InverseBoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Windows; 3 | using System.Windows.Data; 4 | 5 | namespace AskChatGPT.ToolWindows.Converters; 6 | 7 | public class InverseBoolToVisibilityConverter : IValueConverter 8 | { 9 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 10 | { 11 | if (value is bool boolValue) 12 | { 13 | return !boolValue ? Visibility.Visible : Visibility.Collapsed; 14 | } 15 | 16 | return value; 17 | } 18 | 19 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 20 | { 21 | throw new NotImplementedException(); 22 | } 23 | } -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/Converters/TrimStringConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Globalization; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.Windows.Data; 8 | 9 | namespace AskChatGPT.ToolWindows.Converters; 10 | 11 | public class TrimStringConverter : IValueConverter 12 | { 13 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) 14 | { 15 | if (value is string stringValue) 16 | { 17 | if (stringValue.Length> 30) 18 | { 19 | return stringValue.Substring(0, 30) + "..."; 20 | } 21 | } 22 | 23 | return value; 24 | } 25 | 26 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/AskChatGPT/ToolWindows/Templates/ComboBoxTemplateSelector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Controls; 7 | using System.Windows.Media; 8 | using System.Windows; 9 | using System.Windows.Markup; 10 | 11 | namespace AskChatGPT.ToolWindows.Templates 12 | { 13 | public class ComboBoxTemplateSelector : DataTemplateSelector 14 | { 15 | 16 | public DataTemplate SelectedItemTemplate { get; set; } 17 | public DataTemplateSelector SelectedItemTemplateSelector { get; set; } 18 | public DataTemplate DropdownItemsTemplate { get; set; } 19 | public DataTemplateSelector DropdownItemsTemplateSelector { get; set; } 20 | 21 | public override DataTemplate SelectTemplate(object item, DependencyObject container) 22 | { 23 | 24 | var itemToCheck = container; 25 | 26 | // Search up the visual tree, stopping at either a ComboBox or 27 | // a ComboBoxItem (or null). This will determine which template to use 28 | while (itemToCheck is not null 29 | and not ComboBox 30 | and not ComboBoxItem) 31 | itemToCheck = VisualTreeHelper.GetParent(itemToCheck); 32 | 33 | // If you stopped at a ComboBoxItem, you're in the dropdown 34 | var inDropDown = itemToCheck is ComboBoxItem; 35 | 36 | return inDropDown 37 | ? DropdownItemsTemplate ?? DropdownItemsTemplateSelector?.SelectTemplate(item, container) 38 | : SelectedItemTemplate ?? SelectedItemTemplateSelector?.SelectTemplate(item, container); 39 | } 40 | } 41 | 42 | public class ComboBoxTemplateSelectorExtension : MarkupExtension 43 | { 44 | 45 | public DataTemplate SelectedItemTemplate { get; set; } 46 | public DataTemplateSelector SelectedItemTemplateSelector { get; set; } 47 | public DataTemplate DropdownItemsTemplate { get; set; } 48 | public DataTemplateSelector DropdownItemsTemplateSelector { get; set; } 49 | 50 | public override object ProvideValue(IServiceProvider serviceProvider) 51 | => new ComboBoxTemplateSelector() 52 | { 53 | SelectedItemTemplate = SelectedItemTemplate, 54 | SelectedItemTemplateSelector = SelectedItemTemplateSelector, 55 | DropdownItemsTemplate = DropdownItemsTemplate, 56 | DropdownItemsTemplateSelector = DropdownItemsTemplateSelector 57 | }; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/BrowserWrapper.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using Markdig.Renderers; 3 | using Markdig.Syntax; 4 | using Microsoft.VisualStudio.PlatformUI; 5 | using Microsoft.Web.WebView2.Core; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Globalization; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Reflection; 12 | using System.Text; 13 | using System.Text.RegularExpressions; 14 | using System.Threading.Tasks; 15 | using System.Windows.Media; 16 | using System.Windows; 17 | using AskChatGPT.Options; 18 | using Microsoft.Web.WebView2.Wpf; 19 | using System.Windows.Controls; 20 | 21 | namespace AskChatGPT.Utils; 22 | 23 | public class BrowserWrapper : IDisposable 24 | { 25 | private double _cachedPosition = 0, 26 | _cachedHeight = 0, 27 | _positionPercentage = 0; 28 | 29 | private const string _mappedMarkdownEditorVirtualHostName = "markdown-editor-host"; 30 | private const string _mappedBrowsingFileVirtualHostName = "browsing-file-host"; 31 | private readonly Action _copyCodeAction; 32 | 33 | public WebView2 WebView { get; } = new() { HorizontalAlignment = HorizontalAlignment.Stretch, Margin = new Thickness(0), Visibility = Visibility.Hidden }; 34 | public bool IsInitialized { get; private set; } 35 | 36 | public event EventHandler Initialized; 37 | 38 | public BrowserWrapper(Action copyCodeAction) 39 | { 40 | WebView.Initialized += BrowserInitialized; 41 | WebView.NavigationStarting += BrowserNavigationStarting; 42 | 43 | WebView.SetResourceReference(Control.BackgroundProperty, VsBrushes.ToolWindowBackgroundKey); 44 | _copyCodeAction = copyCodeAction; 45 | } 46 | 47 | public void Dispose() 48 | { 49 | WebView.Initialized -= BrowserInitialized; 50 | WebView.NavigationStarting -= BrowserNavigationStarting; 51 | WebView.Dispose(); 52 | } 53 | 54 | private void BrowserInitialized(object sender, EventArgs e) 55 | { 56 | ThreadHelper.JoinableTaskFactory.RunAsync(async () => 57 | { 58 | await InitializeWebView2CoreAsync(); 59 | SetVirtualFolderMapping(); 60 | WebView.Visibility = Visibility.Visible; 61 | 62 | string offsetHeightResult = await WebView.ExecuteScriptAsync("document.body.offsetHeight;"); 63 | double.TryParse(offsetHeightResult, out _cachedHeight); 64 | 65 | await WebView.ExecuteScriptAsync($@"document.documentElement.scrollTop={_positionPercentage * _cachedHeight / 100}"); 66 | 67 | await AdjustAnchorsAsync(); 68 | 69 | await UpdateBrowserAsync(string.Empty); 70 | 71 | IsInitialized = true; 72 | 73 | Initialized?.Invoke(this, EventArgs.Empty); 74 | }).FireAndForget(); 75 | 76 | async Task InitializeWebView2CoreAsync() 77 | { 78 | string tempDir = Path.Combine(Path.GetTempPath(), Assembly.GetExecutingAssembly().GetName().Name); 79 | CoreWebView2Environment webView2Environment = await CoreWebView2Environment.CreateAsync(browserExecutableFolder: null, userDataFolder: tempDir, options: null); 80 | 81 | await WebView.EnsureCoreWebView2Async(webView2Environment); 82 | } 83 | 84 | void SetVirtualFolderMapping() 85 | { 86 | WebView.CoreWebView2.SetVirtualHostNameToFolderMapping(_mappedMarkdownEditorVirtualHostName, GetFolder(), CoreWebView2HostResourceAccessKind.Allow); 87 | 88 | //string baseHref = Path.GetDirectoryName(_file).Replace("\\", "/"); 89 | WebView.CoreWebView2.SetVirtualHostNameToFolderMapping(_mappedBrowsingFileVirtualHostName, GetFolder(), CoreWebView2HostResourceAccessKind.Allow); 90 | } 91 | } 92 | 93 | private void BrowserNavigationStarting(object sender, CoreWebView2NavigationStartingEventArgs e) 94 | { 95 | ThreadHelper.JoinableTaskFactory.RunAsync(async () => 96 | { 97 | if (e.Uri == null) 98 | { 99 | return; 100 | } 101 | 102 | // Setting content rather than URL navigating 103 | if (e.Uri.StartsWith("data:text/html;")) 104 | { 105 | return; 106 | } 107 | 108 | e.Cancel = true; 109 | 110 | Uri uri = new(e.Uri); 111 | 112 | // If it's a file-based anchor we converted, open the related file if possible 113 | if (uri.Authority == "browsing-file-host") 114 | { 115 | if (uri.Fragment?.StartsWith("#copy_") == true) 116 | { 117 | var copyId = uri.Fragment.Substring(6); 118 | _copyCodeAction(copyId); 119 | return; 120 | } 121 | } 122 | else if (uri.IsAbsoluteUri && uri.Scheme.StartsWith("http")) 123 | { 124 | System.Diagnostics.Process.Start(uri.ToString()); 125 | } 126 | }).FireAndForget(); 127 | } 128 | 129 | private async Task NavigateToFragmentAsync(string fragmentId) 130 | { 131 | await WebView.ExecuteScriptAsync($"document.getElementById(\"{fragmentId}\").scrollIntoView(true)"); 132 | } 133 | 134 | /// 135 | /// Adjust the file-based anchors so that they are navigable on the local file system 136 | /// 137 | /// Anchors using the "file:" protocol appear to be blocked by security settings and won't work. 138 | /// If we convert them to use the "about:" protocol so that we recognize them, we can open the file in 139 | /// the Navigating event handler. 140 | private async Task AdjustAnchorsAsync() 141 | { 142 | string script = @" 143 | for (const anchor of document.links) { 144 | if (anchor != null && anchor.protocol == 'file:') { 145 | var pathName = null, hash = anchor.hash; 146 | if (hash != null) { 147 | pathName = anchor.pathname; 148 | anchor.hash = null; 149 | anchor.pathname = ''; 150 | } 151 | anchor.protocol = 'about:'; 152 | 153 | if (hash != null) { 154 | if (pathName == null || pathName.endsWith('/')) { 155 | pathName = 'blank'; 156 | } 157 | anchor.pathname = pathName; 158 | anchor.hash = hash; 159 | } 160 | } 161 | }"; 162 | await WebView.ExecuteScriptAsync(script.Replace("\r", "\\r").Replace("\n", "\\n")); 163 | } 164 | 165 | private async Task IsHtmlTemplateLoadedAsync() 166 | { 167 | string hasContentResult = await WebView.ExecuteScriptAsync($@"document.getElementById(""___markdown-content___"") !== null;"); 168 | return hasContentResult == "true"; 169 | } 170 | 171 | public async Task UpdateBrowserAsync(string html) 172 | { 173 | try 174 | { 175 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 176 | await UpdateContentAsync(html); 177 | } 178 | catch 179 | { 180 | } 181 | 182 | async Task UpdateContentAsync(string html) 183 | { 184 | bool isInit = await IsHtmlTemplateLoadedAsync(); 185 | if (isInit) 186 | { 187 | html = html.Replace("\\", "\\\\").Replace("\r", "\\r").Replace("\n", "\\n").Replace("\"", "\\\""); 188 | await WebView.ExecuteScriptAsync($@"document.getElementById(""___markdown-content___"").innerHTML=""{html}"";"); 189 | 190 | // Makes sure that any code blocks get syntax highlighted by Prism 191 | await WebView.ExecuteScriptAsync("Prism.highlightAll();"); 192 | await WebView.ExecuteScriptAsync("mermaid.init(undefined, document.querySelectorAll('.mermaid'));"); 193 | //await WebView.ExecuteScriptAsync("MathJax.Typeset(['.math']);"); 194 | //await WebView.ExecuteScriptAsync("if (typeof onMarkdownUpdate == 'function') onMarkdownUpdate();"); 195 | 196 | // Adjust the anchors after and edit 197 | await AdjustAnchorsAsync(); 198 | } 199 | else 200 | { 201 | string htmlTemplate = GetHtmlTemplate(); 202 | html = string.Format(CultureInfo.InvariantCulture, "{0}", html); 203 | html = htmlTemplate.Replace("[content]", html); 204 | WebView.NavigateToString(html); 205 | } 206 | } 207 | } 208 | 209 | public static string GetFolder() 210 | { 211 | string assembly = Assembly.GetExecutingAssembly().Location; 212 | return Path.GetDirectoryName(assembly); 213 | } 214 | 215 | private string GetHtmlTemplateFileNameFromResource() 216 | { 217 | return Path.Combine(GetFolder(), "Utils\\md-template.html"); 218 | } 219 | 220 | private string GetHtmlTemplate() 221 | { 222 | bool useLightTheme = UseLightTheme(); 223 | string css = ReadCSS(useLightTheme); 224 | string mermaidJsParameters = $"{{ 'securityLevel': 'loose', 'theme': '{(useLightTheme ? "forest" : "dark")}', startOnLoad: true, flowchart: {{ htmlLabels: false }} }}"; 225 | 226 | string defaultHeadBeg = $@" 227 | 228 | 229 | 230 | 231 | "; 235 | 236 | string defaultContent = $@" 237 |
238 | [content] 239 |
240 | 241 | 242 | 243 | 246 | "; 247 | 248 | string templateFileName = GetHtmlTemplateFileNameFromResource(); 249 | string template = File.ReadAllText(templateFileName); 250 | return template 251 | .Replace("", defaultHeadBeg) 252 | .Replace("[content]", defaultContent) 253 | .Replace("[title]", "Markdown Preview"); 254 | 255 | string ReadCSS(bool useLightTheme) 256 | { 257 | string cssHighlightFile = useLightTheme ? "highlight.css" : "highlight-dark.css"; 258 | 259 | string cssPrismFile = useLightTheme ? "prism.css" : "prism-dark.css"; 260 | 261 | string folder = GetFolder(); 262 | string cssHighlight = File.ReadAllText(Path.Combine(folder, "utils", cssHighlightFile)); 263 | string cssPrism = File.ReadAllText(Path.Combine(folder, "utils", cssPrismFile)); 264 | 265 | return cssHighlight + cssPrism; 266 | } 267 | 268 | bool UseLightTheme() 269 | { 270 | bool useLightTheme = AdvancedOptions.Instance.Theme == Theme.Light; 271 | 272 | if (AdvancedOptions.Instance.Theme == Theme.Automatic) 273 | { 274 | SolidColorBrush brush = (SolidColorBrush)Application.Current.Resources[CommonControlsColors.TextBoxBackgroundBrushKey]; 275 | ContrastComparisonResult contrast = ColorUtilities.CompareContrastWithBlackAndWhite(brush.Color); 276 | 277 | useLightTheme = contrast == ContrastComparisonResult.ContrastHigherWithBlack; 278 | } 279 | 280 | return useLightTheme; 281 | } 282 | } 283 | 284 | } 285 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/MarkdownToHtmlConverter.cs: -------------------------------------------------------------------------------- 1 | using Markdig.Syntax; 2 | using Markdig; 3 | using Microsoft.VisualStudio.Text; 4 | using Microsoft.VisualStudio.Threading; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.IO; 11 | using Markdig.Renderers; 12 | using System.Text.RegularExpressions; 13 | 14 | namespace AskChatGPT.Utils; 15 | 16 | class MarkdownToHtmlConverter 17 | { 18 | [ThreadStatic] 19 | static StringWriter _htmlWriterStatic; 20 | 21 | readonly static MarkdownPipeline _markdownPipeline = new MarkdownPipelineBuilder() 22 | .UseAdvancedExtensions() 23 | .UsePragmaLines() 24 | .UsePreciseSourceLocation() 25 | .UseYamlFrontMatter() 26 | .UseEmojiAndSmiley() 27 | .Build(); 28 | 29 | public MarkdownToHtmlConverter() 30 | { 31 | } 32 | 33 | public async Task ConvertToHtml(string markdown) 34 | { 35 | var htmlWriter = (_htmlWriterStatic ??= new StringWriter()); 36 | htmlWriter.GetStringBuilder().Clear(); 37 | 38 | try 39 | { 40 | var markdownDocument = Markdown.Parse(markdown, _markdownPipeline); 41 | 42 | HtmlRenderer htmlRenderer = new(htmlWriter); 43 | //Document.Pipeline.Setup(htmlRenderer); 44 | htmlRenderer.UseNonAsciiNoEscape = true; 45 | htmlRenderer.Render(markdownDocument); 46 | 47 | await htmlWriter.FlushAsync(); 48 | string html = htmlWriter.ToString(); 49 | html = Regex.Replace(html, "\"language-(c|C)#\"", "\"language-csharp\"", RegexOptions.Compiled); 50 | return html; 51 | } 52 | catch (Exception ex) 53 | { 54 | // We could output this to the exception pane of VS? 55 | // Though, it's easier to output it directly to the browser 56 | return "

An unexpected exception occurred:

" +
57 |                     ex.ToString().Replace("<", "<").Replace("&", "&") + "
"; 58 | } 59 | finally 60 | { 61 | // Free any resources allocated by HtmlWriter 62 | htmlWriter?.GetStringBuilder().Clear(); 63 | } 64 | } 65 | } 66 | 67 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/MarkupCodeHighlighter.cs: -------------------------------------------------------------------------------- 1 | using AskChatGPT.Options; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | using System.Windows; 9 | 10 | namespace AskChatGPT.Utils; 11 | 12 | public class MarkupCodeHighlighter 13 | { 14 | readonly Dictionary _copyCode = new(); 15 | 16 | public MarkupCodeHighlighter() 17 | { 18 | } 19 | 20 | internal void ClearCopyCodeLinks() 21 | { 22 | _copyCode.Clear(); 23 | } 24 | 25 | internal void Copy(string copyId) 26 | { 27 | if (_copyCode.TryGetValue(copyId, out var codeToCopy)) 28 | { 29 | Clipboard.SetText(codeToCopy); 30 | } 31 | } 32 | 33 | public string TransformMarkdown(string text) 34 | { 35 | using StringReader reader = new(text); 36 | 37 | string line; 38 | const string codeSeparator = "```"; 39 | bool insideCode = false; 40 | string sourceCopyId = null; 41 | StringBuilder codeToCopy = new(); 42 | 43 | StringBuilder outputText = new(); 44 | 45 | while ((line = reader.ReadLine()) != null) 46 | { 47 | int indexOfSeparator = line.IndexOf(codeSeparator); 48 | if (indexOfSeparator > -1) 49 | { 50 | if (!insideCode) 51 | { 52 | insideCode = true; 53 | 54 | sourceCopyId = Guid.NewGuid().ToString("N"); 55 | 56 | var linkToCopyText = $@" 57 | [Copy](#copy_{sourceCopyId}) 58 | "; 59 | 60 | if (line.Length == indexOfSeparator + 3) 61 | { 62 | line = line.Insert(indexOfSeparator + 3, AdvancedOptions.Instance.PreferredSourceLanguage); 63 | } 64 | 65 | outputText.AppendLine(linkToCopyText); 66 | } 67 | else 68 | { 69 | insideCode = false; 70 | if (sourceCopyId != null) 71 | { 72 | _copyCode.Add(sourceCopyId, codeToCopy.ToString()); 73 | } 74 | 75 | codeToCopy.Clear(); 76 | } 77 | 78 | outputText.AppendLine(line); 79 | } 80 | else 81 | { 82 | if (insideCode) 83 | { 84 | codeToCopy.AppendLine(line); 85 | } 86 | 87 | outputText.AppendLine(line); 88 | } 89 | } 90 | 91 | return outputText.ToString(); 92 | } 93 | 94 | // public string TransformMarkdown(string text) 95 | // { 96 | // int index = 0; 97 | // while (true) 98 | // { 99 | // int startingIndexOfCode = text.IndexOf($"```", index); 100 | // if (startingIndexOfCode == -1) 101 | // { 102 | // break; 103 | // } 104 | 105 | // int endingIndexOfCode = text.IndexOf("```", startingIndexOfCode + 3); 106 | // if (endingIndexOfCode == -1) 107 | // { 108 | // break; 109 | // } 110 | 111 | // int startIndexOfCodeToCopy = text.IndexOfAny(new[] { '\r', '\n' }, startingIndexOfCode); 112 | 113 | // if (startIndexOfCodeToCopy == -1) 114 | // { 115 | // break; 116 | // } 117 | 118 | // bool languageSpecPresent = startIndexOfCodeToCopy > startingIndexOfCode + 3; 119 | 120 | // if (text[startIndexOfCodeToCopy] == '\r' && 121 | // startIndexOfCodeToCopy < text.Length-1 && 122 | // text[startIndexOfCodeToCopy + 1]=='\n') 123 | // { 124 | // startIndexOfCodeToCopy+=2; 125 | // } 126 | // else 127 | // { 128 | // startingIndexOfCode++; 129 | // } 130 | 131 | // var codeToCopy = text 132 | // .Substring(startIndexOfCodeToCopy, endingIndexOfCode - startIndexOfCodeToCopy) 133 | // ; 134 | 135 | // if (!string.IsNullOrWhiteSpace(codeToCopy)) 136 | // { 137 | // string sourceCopyId = Guid.NewGuid().ToString("N"); 138 | // _copyCode.Add(sourceCopyId, codeToCopy); 139 | 140 | // if (!languageSpecPresent) 141 | // { 142 | // text = text.Insert(startingIndexOfCode + 3, AdvancedOptions.Instance.PreferredSourceLanguage); 143 | // } 144 | 145 | // var linkToCopyText = $@" 146 | //[Copy](#copy_{sourceCopyId}) 147 | //"; 148 | // text = text.Insert(startingIndexOfCode, linkToCopyText); 149 | 150 | // index = text.IndexOf("```", startingIndexOfCode + linkToCopyText.Length + (languageSpecPresent ? 0 : AdvancedOptions.Instance.PreferredSourceLanguage.Length)) + 3; 151 | // continue; 152 | // } 153 | 154 | // index = endingIndexOfCode + 3; 155 | // } 156 | 157 | // return text; 158 | // } 159 | 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/highlight-dark.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #1f1f1f 3 | } 4 | .markdown-body { 5 | color-scheme: dark; 6 | -ms-text-size-adjust: 100%; 7 | -webkit-text-size-adjust: 100%; 8 | margin: 0; 9 | color: #c9d1d9; 10 | background-color: #1f1f1f; 11 | font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"; 12 | font-size: 16px; 13 | line-height: 1.5; 14 | word-wrap: break-word; 15 | } 16 | 17 | .markdown-body .octicon { 18 | display: inline-block; 19 | fill: currentColor; 20 | vertical-align: text-bottom; 21 | } 22 | 23 | .markdown-body h1:hover .anchor .octicon-link:before, 24 | .markdown-body h2:hover .anchor .octicon-link:before, 25 | .markdown-body h3:hover .anchor .octicon-link:before, 26 | .markdown-body h4:hover .anchor .octicon-link:before, 27 | .markdown-body h5:hover .anchor .octicon-link:before, 28 | .markdown-body h6:hover .anchor .octicon-link:before { 29 | width: 16px; 30 | height: 16px; 31 | content: ' '; 32 | display: inline-block; 33 | background-color: currentColor; 34 | -webkit-mask-image: url("data:image/svg+xml,"); 35 | mask-image: url("data:image/svg+xml,"); 36 | } 37 | 38 | .markdown-body details, 39 | .markdown-body figcaption, 40 | .markdown-body figure { 41 | display: block; 42 | } 43 | 44 | .markdown-body summary { 45 | display: list-item; 46 | } 47 | 48 | .markdown-body [hidden] { 49 | display: none !important; 50 | } 51 | 52 | .markdown-body a { 53 | background-color: transparent; 54 | color: #58a6ff; 55 | text-decoration: none; 56 | } 57 | 58 | .markdown-body a:active, 59 | .markdown-body a:hover { 60 | outline-width: 0; 61 | } 62 | 63 | .markdown-body abbr[title] { 64 | border-bottom: none; 65 | text-decoration: underline dotted; 66 | } 67 | 68 | .markdown-body b, 69 | .markdown-body strong { 70 | font-weight: 600; 71 | } 72 | 73 | .markdown-body dfn { 74 | font-style: italic; 75 | } 76 | 77 | .markdown-body h1 { 78 | margin: .67em 0; 79 | font-weight: 600; 80 | padding-bottom: .3em; 81 | font-size: 2em; 82 | border-bottom: 1px solid #21262d; 83 | } 84 | 85 | .markdown-body mark { 86 | background-color: rgba(187,128,9,0.15); 87 | color: #c9d1d9; 88 | } 89 | 90 | .markdown-body small { 91 | font-size: 90%; 92 | } 93 | 94 | .markdown-body sub, 95 | .markdown-body sup { 96 | font-size: 75%; 97 | line-height: 0; 98 | position: relative; 99 | vertical-align: baseline; 100 | } 101 | 102 | .markdown-body sub { 103 | bottom: -0.25em; 104 | } 105 | 106 | .markdown-body sup { 107 | top: -0.5em; 108 | } 109 | 110 | .markdown-body img { 111 | border-style: none; 112 | max-width: 100%; 113 | box-sizing: content-box; 114 | background-color: #1f1f1f; 115 | } 116 | 117 | .markdown-body code, 118 | .markdown-body kbd, 119 | .markdown-body pre, 120 | .markdown-body samp { 121 | font-family: monospace,monospace; 122 | font-size: 1em; 123 | } 124 | 125 | .markdown-body figure { 126 | margin: 1em 40px; 127 | } 128 | 129 | .markdown-body hr { 130 | box-sizing: content-box; 131 | overflow: hidden; 132 | background: transparent; 133 | border-bottom: 1px solid #21262d; 134 | height: .25em; 135 | padding: 0; 136 | margin: 24px 0; 137 | background-color: #30363d; 138 | border: 0; 139 | } 140 | 141 | .markdown-body input { 142 | font: inherit; 143 | margin: 0; 144 | overflow: visible; 145 | font-family: inherit; 146 | font-size: inherit; 147 | line-height: inherit; 148 | } 149 | 150 | .markdown-body [type=button], 151 | .markdown-body [type=reset], 152 | .markdown-body [type=submit] { 153 | -webkit-appearance: button; 154 | } 155 | 156 | .markdown-body [type=button]::-moz-focus-inner, 157 | .markdown-body [type=reset]::-moz-focus-inner, 158 | .markdown-body [type=submit]::-moz-focus-inner { 159 | border-style: none; 160 | padding: 0; 161 | } 162 | 163 | .markdown-body [type=button]:-moz-focusring, 164 | .markdown-body [type=reset]:-moz-focusring, 165 | .markdown-body [type=submit]:-moz-focusring { 166 | outline: 1px dotted ButtonText; 167 | } 168 | 169 | .markdown-body [type=checkbox], 170 | .markdown-body [type=radio] { 171 | box-sizing: border-box; 172 | padding: 0; 173 | } 174 | 175 | .markdown-body [type=number]::-webkit-inner-spin-button, 176 | .markdown-body [type=number]::-webkit-outer-spin-button { 177 | height: auto; 178 | } 179 | 180 | .markdown-body [type=search] { 181 | -webkit-appearance: textfield; 182 | outline-offset: -2px; 183 | } 184 | 185 | .markdown-body [type=search]::-webkit-search-cancel-button, 186 | .markdown-body [type=search]::-webkit-search-decoration { 187 | -webkit-appearance: none; 188 | } 189 | 190 | .markdown-body ::-webkit-input-placeholder { 191 | color: inherit; 192 | opacity: .54; 193 | } 194 | 195 | .markdown-body ::-webkit-file-upload-button { 196 | -webkit-appearance: button; 197 | font: inherit; 198 | } 199 | 200 | .markdown-body a:hover { 201 | text-decoration: underline; 202 | } 203 | 204 | .markdown-body hr::before { 205 | display: table; 206 | content: ""; 207 | } 208 | 209 | .markdown-body hr::after { 210 | display: table; 211 | clear: both; 212 | content: ""; 213 | } 214 | 215 | .markdown-body table { 216 | border-spacing: 0; 217 | border-collapse: collapse; 218 | display: block; 219 | width: max-content; 220 | max-width: 100%; 221 | overflow: auto; 222 | } 223 | 224 | .markdown-body td, 225 | .markdown-body th { 226 | padding: 0; 227 | } 228 | 229 | .markdown-body details summary { 230 | cursor: pointer; 231 | } 232 | 233 | .markdown-body details:not([open]) > *:not(summary) { 234 | display: none !important; 235 | } 236 | 237 | .markdown-body kbd { 238 | display: inline-block; 239 | padding: 3px 5px; 240 | font: 11px ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; 241 | line-height: 10px; 242 | color: #c9d1d9; 243 | vertical-align: middle; 244 | background-color: #161b22; 245 | border: solid 1px rgba(110,118,129,0.4); 246 | border-bottom-color: rgba(110,118,129,0.4); 247 | border-radius: 6px; 248 | box-shadow: inset 0 -1px 0 rgba(110,118,129,0.4); 249 | } 250 | 251 | .markdown-body h1, 252 | .markdown-body h2, 253 | .markdown-body h3, 254 | .markdown-body h4, 255 | .markdown-body h5, 256 | .markdown-body h6 { 257 | margin-top: 24px; 258 | margin-bottom: 16px; 259 | font-weight: 600; 260 | line-height: 1.25; 261 | } 262 | 263 | .markdown-body h2 { 264 | font-weight: 600; 265 | padding-bottom: .3em; 266 | font-size: 1.5em; 267 | border-bottom: 1px solid #21262d; 268 | } 269 | 270 | .markdown-body h3 { 271 | font-weight: 600; 272 | font-size: 1.25em; 273 | } 274 | 275 | .markdown-body h4 { 276 | font-weight: 600; 277 | font-size: 1em; 278 | } 279 | 280 | .markdown-body h5 { 281 | font-weight: 600; 282 | font-size: .875em; 283 | } 284 | 285 | .markdown-body h6 { 286 | font-weight: 600; 287 | font-size: .85em; 288 | color: #8b949e; 289 | } 290 | 291 | .markdown-body p { 292 | margin-top: 0; 293 | margin-bottom: 10px; 294 | } 295 | 296 | .markdown-body blockquote { 297 | margin: 0; 298 | padding: 0 1em; 299 | color: #8b949e; 300 | border-left: .25em solid #30363d; 301 | } 302 | 303 | .markdown-body ul { 304 | list-style: disc 305 | } 306 | 307 | .markdown-body ul, 308 | .markdown-body ol { 309 | margin-top: 0; 310 | margin-bottom: 0; 311 | padding-left: 2em; 312 | } 313 | 314 | .markdown-body ol ol, 315 | .markdown-body ul ol { 316 | list-style-type: lower-roman; 317 | } 318 | 319 | .markdown-body ul ul ol, 320 | .markdown-body ul ol ol, 321 | .markdown-body ol ul ol, 322 | .markdown-body ol ol ol { 323 | list-style-type: lower-alpha; 324 | } 325 | 326 | .markdown-body dd { 327 | margin-left: 0; 328 | } 329 | 330 | .markdown-body tt, 331 | .markdown-body code { 332 | font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; 333 | font-size: 12px; 334 | } 335 | 336 | .markdown-body pre { 337 | margin-top: 0; 338 | margin-bottom: 0; 339 | font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace; 340 | font-size: 12px; 341 | word-wrap: normal; 342 | } 343 | 344 | .markdown-body .octicon { 345 | display: inline-block; 346 | overflow: visible !important; 347 | vertical-align: text-bottom; 348 | fill: currentColor; 349 | } 350 | 351 | .markdown-body ::placeholder { 352 | color: #484f58; 353 | opacity: 1; 354 | } 355 | 356 | .markdown-body input::-webkit-outer-spin-button, 357 | .markdown-body input::-webkit-inner-spin-button { 358 | margin: 0; 359 | -webkit-appearance: none; 360 | appearance: none; 361 | } 362 | 363 | .markdown-body .pl-c { 364 | color: #8b949e; 365 | } 366 | 367 | .markdown-body .pl-c1, 368 | .markdown-body .pl-s .pl-v { 369 | color: #79c0ff; 370 | } 371 | 372 | .markdown-body .pl-e, 373 | .markdown-body .pl-en { 374 | color: #d2a8ff; 375 | } 376 | 377 | .markdown-body .pl-smi, 378 | .markdown-body .pl-s .pl-s1 { 379 | color: #c9d1d9; 380 | } 381 | 382 | .markdown-body .pl-ent { 383 | color: #7ee787; 384 | } 385 | 386 | .markdown-body .pl-k { 387 | color: #ff7b72; 388 | } 389 | 390 | .markdown-body .pl-s, 391 | .markdown-body .pl-pds, 392 | .markdown-body .pl-s .pl-pse .pl-s1, 393 | .markdown-body .pl-sr, 394 | .markdown-body .pl-sr .pl-cce, 395 | .markdown-body .pl-sr .pl-sre, 396 | .markdown-body .pl-sr .pl-sra { 397 | color: #a5d6ff; 398 | } 399 | 400 | .markdown-body .pl-v, 401 | .markdown-body .pl-smw { 402 | color: #ffa657; 403 | } 404 | 405 | .markdown-body .pl-bu { 406 | color: #f85149; 407 | } 408 | 409 | .markdown-body .pl-ii { 410 | color: #f0f6fc; 411 | background-color: #8e1519; 412 | } 413 | 414 | .markdown-body .pl-c2 { 415 | color: #f0f6fc; 416 | background-color: #b62324; 417 | } 418 | 419 | .markdown-body .pl-sr .pl-cce { 420 | font-weight: bold; 421 | color: #7ee787; 422 | } 423 | 424 | .markdown-body .pl-ml { 425 | color: #f2cc60; 426 | } 427 | 428 | .markdown-body .pl-mh, 429 | .markdown-body .pl-mh .pl-en, 430 | .markdown-body .pl-ms { 431 | font-weight: bold; 432 | color: #1f6feb; 433 | } 434 | 435 | .markdown-body .pl-mi { 436 | font-style: italic; 437 | color: #c9d1d9; 438 | } 439 | 440 | .markdown-body .pl-mb { 441 | font-weight: bold; 442 | color: #c9d1d9; 443 | } 444 | 445 | .markdown-body .pl-md { 446 | color: #ffdcd7; 447 | background-color: #67060c; 448 | } 449 | 450 | .markdown-body .pl-mi1 { 451 | color: #aff5b4; 452 | background-color: #033a16; 453 | } 454 | 455 | .markdown-body .pl-mc { 456 | color: #ffdfb6; 457 | background-color: #5a1e02; 458 | } 459 | 460 | .markdown-body .pl-mi2 { 461 | color: #c9d1d9; 462 | background-color: #1158c7; 463 | } 464 | 465 | .markdown-body .pl-mdr { 466 | font-weight: bold; 467 | color: #d2a8ff; 468 | } 469 | 470 | .markdown-body .pl-ba { 471 | color: #8b949e; 472 | } 473 | 474 | .markdown-body .pl-sg { 475 | color: #484f58; 476 | } 477 | 478 | .markdown-body .pl-corl { 479 | text-decoration: underline; 480 | color: #a5d6ff; 481 | } 482 | 483 | .markdown-body [data-catalyst] { 484 | display: block; 485 | } 486 | 487 | .markdown-body g-emoji { 488 | font-family: "Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol"; 489 | font-size: 1em; 490 | font-style: normal !important; 491 | font-weight: 400; 492 | line-height: 1; 493 | vertical-align: -0.075em; 494 | } 495 | 496 | .markdown-body g-emoji img { 497 | width: 1em; 498 | height: 1em; 499 | } 500 | 501 | .markdown-body::before { 502 | display: table; 503 | content: ""; 504 | } 505 | 506 | .markdown-body::after { 507 | display: table; 508 | clear: both; 509 | content: ""; 510 | } 511 | 512 | .markdown-body > *:first-child { 513 | margin-top: 0 !important; 514 | } 515 | 516 | .markdown-body > *:last-child { 517 | margin-bottom: 0 !important; 518 | } 519 | 520 | .markdown-body a:not([href]) { 521 | color: inherit; 522 | text-decoration: none; 523 | } 524 | 525 | .markdown-body .absent { 526 | color: #f85149; 527 | } 528 | 529 | .markdown-body .anchor { 530 | float: left; 531 | padding-right: 4px; 532 | margin-left: -20px; 533 | line-height: 1; 534 | } 535 | 536 | .markdown-body .anchor:focus { 537 | outline: none; 538 | } 539 | 540 | .markdown-body p, 541 | .markdown-body blockquote, 542 | .markdown-body ul, 543 | .markdown-body ol, 544 | .markdown-body dl, 545 | .markdown-body table, 546 | .markdown-body pre, 547 | .markdown-body details { 548 | margin-top: 0; 549 | margin-bottom: 16px; 550 | } 551 | 552 | .markdown-body blockquote > :first-child { 553 | margin-top: 0; 554 | } 555 | 556 | .markdown-body blockquote > :last-child { 557 | margin-bottom: 0; 558 | } 559 | 560 | .markdown-body sup > a::before { 561 | content: "["; 562 | } 563 | 564 | .markdown-body sup > a::after { 565 | content: "]"; 566 | } 567 | 568 | .markdown-body h1 .octicon-link, 569 | .markdown-body h2 .octicon-link, 570 | .markdown-body h3 .octicon-link, 571 | .markdown-body h4 .octicon-link, 572 | .markdown-body h5 .octicon-link, 573 | .markdown-body h6 .octicon-link { 574 | color: #c9d1d9; 575 | vertical-align: middle; 576 | visibility: hidden; 577 | } 578 | 579 | .markdown-body h1:hover .anchor, 580 | .markdown-body h2:hover .anchor, 581 | .markdown-body h3:hover .anchor, 582 | .markdown-body h4:hover .anchor, 583 | .markdown-body h5:hover .anchor, 584 | .markdown-body h6:hover .anchor { 585 | text-decoration: none; 586 | } 587 | 588 | .markdown-body h1:hover .anchor .octicon-link, 589 | .markdown-body h2:hover .anchor .octicon-link, 590 | .markdown-body h3:hover .anchor .octicon-link, 591 | .markdown-body h4:hover .anchor .octicon-link, 592 | .markdown-body h5:hover .anchor .octicon-link, 593 | .markdown-body h6:hover .anchor .octicon-link { 594 | visibility: visible; 595 | } 596 | 597 | .markdown-body h1 tt, 598 | .markdown-body h1 code, 599 | .markdown-body h2 tt, 600 | .markdown-body h2 code, 601 | .markdown-body h3 tt, 602 | .markdown-body h3 code, 603 | .markdown-body h4 tt, 604 | .markdown-body h4 code, 605 | .markdown-body h5 tt, 606 | .markdown-body h5 code, 607 | .markdown-body h6 tt, 608 | .markdown-body h6 code { 609 | padding: 0 .2em; 610 | font-size: inherit; 611 | } 612 | 613 | .markdown-body ul.no-list, 614 | .markdown-body ol.no-list { 615 | padding: 0; 616 | list-style-type: none; 617 | } 618 | 619 | .markdown-body ol[type="1"] { 620 | list-style-type: decimal; 621 | } 622 | 623 | .markdown-body ol[type=a] { 624 | list-style-type: lower-alpha; 625 | } 626 | 627 | .markdown-body ol[type=i] { 628 | list-style-type: lower-roman; 629 | } 630 | 631 | .markdown-body div > ol:not([type]) { 632 | list-style-type: decimal; 633 | } 634 | 635 | .markdown-body ul ul, 636 | .markdown-body ul ol, 637 | .markdown-body ol ol, 638 | .markdown-body ol ul { 639 | margin-top: 0; 640 | margin-bottom: 0; 641 | } 642 | 643 | .markdown-body li > p { 644 | margin-top: 16px; 645 | } 646 | 647 | .markdown-body li + li { 648 | margin-top: .25em; 649 | } 650 | 651 | .markdown-body dl { 652 | padding: 0; 653 | } 654 | 655 | .markdown-body dl dt { 656 | padding: 0; 657 | margin-top: 16px; 658 | font-size: 1em; 659 | font-style: italic; 660 | font-weight: 600; 661 | } 662 | 663 | .markdown-body dl dd { 664 | padding: 0 16px; 665 | margin-bottom: 16px; 666 | } 667 | 668 | .markdown-body table th { 669 | font-weight: 600; 670 | } 671 | 672 | .markdown-body table th, 673 | .markdown-body table td { 674 | padding: 6px 13px; 675 | border: 1px solid #30363d; 676 | } 677 | 678 | .markdown-body table tr { 679 | background-color: #1f1f1f; 680 | border-top: 1px solid #21262d; 681 | } 682 | 683 | .markdown-body table tr:nth-child(2n) { 684 | background-color: #161b22; 685 | } 686 | 687 | .markdown-body table img { 688 | background-color: transparent; 689 | } 690 | 691 | .markdown-body img[align=right] { 692 | padding-left: 20px; 693 | } 694 | 695 | .markdown-body img[align=left] { 696 | padding-right: 20px; 697 | } 698 | 699 | .markdown-body .emoji { 700 | max-width: none; 701 | vertical-align: text-top; 702 | background-color: transparent; 703 | } 704 | 705 | .markdown-body span.frame { 706 | display: block; 707 | overflow: hidden; 708 | } 709 | 710 | .markdown-body span.frame > span { 711 | display: block; 712 | float: left; 713 | width: auto; 714 | padding: 7px; 715 | margin: 13px 0 0; 716 | overflow: hidden; 717 | border: 1px solid #30363d; 718 | } 719 | 720 | .markdown-body span.frame span img { 721 | display: block; 722 | float: left; 723 | } 724 | 725 | .markdown-body span.frame span span { 726 | display: block; 727 | padding: 5px 0 0; 728 | clear: both; 729 | color: #c9d1d9; 730 | } 731 | 732 | .markdown-body span.align-center { 733 | display: block; 734 | overflow: hidden; 735 | clear: both; 736 | } 737 | 738 | .markdown-body span.align-center > span { 739 | display: block; 740 | margin: 13px auto 0; 741 | overflow: hidden; 742 | text-align: center; 743 | } 744 | 745 | .markdown-body span.align-center span img { 746 | margin: 0 auto; 747 | text-align: center; 748 | } 749 | 750 | .markdown-body span.align-right { 751 | display: block; 752 | overflow: hidden; 753 | clear: both; 754 | } 755 | 756 | .markdown-body span.align-right > span { 757 | display: block; 758 | margin: 13px 0 0; 759 | overflow: hidden; 760 | text-align: right; 761 | } 762 | 763 | .markdown-body span.align-right span img { 764 | margin: 0; 765 | text-align: right; 766 | } 767 | 768 | .markdown-body span.float-left { 769 | display: block; 770 | float: left; 771 | margin-right: 13px; 772 | overflow: hidden; 773 | } 774 | 775 | .markdown-body span.float-left span { 776 | margin: 13px 0 0; 777 | } 778 | 779 | .markdown-body span.float-right { 780 | display: block; 781 | float: right; 782 | margin-left: 13px; 783 | overflow: hidden; 784 | } 785 | 786 | .markdown-body span.float-right > span { 787 | display: block; 788 | margin: 13px auto 0; 789 | overflow: hidden; 790 | text-align: right; 791 | } 792 | 793 | .markdown-body code, 794 | .markdown-body tt { 795 | padding: .2em .4em; 796 | margin: 0; 797 | font-size: 85%; 798 | background-color: rgba(110,118,129,0.4); 799 | border-radius: 6px; 800 | } 801 | 802 | .markdown-body code br, 803 | .markdown-body tt br { 804 | display: none; 805 | } 806 | 807 | .markdown-body del code { 808 | text-decoration: inherit; 809 | } 810 | 811 | .markdown-body pre code { 812 | font-size: 100%; 813 | } 814 | 815 | .markdown-body pre > code { 816 | padding: 0; 817 | margin: 0; 818 | word-break: normal; 819 | white-space: pre; 820 | background: transparent; 821 | border: 0; 822 | } 823 | 824 | .markdown-body .highlight { 825 | margin-bottom: 16px; 826 | } 827 | 828 | .markdown-body .highlight pre { 829 | margin-bottom: 0; 830 | word-break: normal; 831 | } 832 | 833 | .markdown-body .highlight pre, 834 | .markdown-body pre { 835 | padding: 16px; 836 | overflow: auto; 837 | font-size: 85%; 838 | line-height: 1.45; 839 | background-color: #161b22; 840 | border-radius: 6px; 841 | } 842 | 843 | .markdown-body pre code, 844 | .markdown-body pre tt { 845 | display: inline; 846 | max-width: auto; 847 | padding: 0; 848 | margin: 0; 849 | overflow: visible; 850 | line-height: inherit; 851 | word-wrap: normal; 852 | background-color: transparent; 853 | border: 0; 854 | } 855 | 856 | .markdown-body .csv-data td, 857 | .markdown-body .csv-data th { 858 | padding: 5px; 859 | overflow: hidden; 860 | font-size: 12px; 861 | line-height: 1; 862 | text-align: left; 863 | white-space: nowrap; 864 | } 865 | 866 | .markdown-body .csv-data .blob-num { 867 | padding: 10px 8px 9px; 868 | text-align: right; 869 | background: #1f1f1f; 870 | border: 0; 871 | } 872 | 873 | .markdown-body .csv-data tr { 874 | border-top: 0; 875 | } 876 | 877 | .markdown-body .csv-data th { 878 | font-weight: 600; 879 | background: #161b22; 880 | border-top: 0; 881 | } 882 | 883 | .markdown-body .footnotes { 884 | font-size: 12px; 885 | color: #8b949e; 886 | border-top: 1px solid #30363d; 887 | } 888 | 889 | .markdown-body .footnotes ol { 890 | padding-left: 16px; 891 | } 892 | 893 | .markdown-body .footnotes li { 894 | position: relative; 895 | } 896 | 897 | .markdown-body .footnotes li:target::before { 898 | position: absolute; 899 | top: -8px; 900 | right: -8px; 901 | bottom: -8px; 902 | left: -24px; 903 | pointer-events: none; 904 | content: ""; 905 | border: 2px solid #1f6feb; 906 | border-radius: 6px; 907 | } 908 | 909 | .markdown-body .footnotes li:target { 910 | color: #c9d1d9; 911 | } 912 | 913 | .markdown-body .footnotes .data-footnote-backref g-emoji { 914 | font-family: monospace; 915 | } 916 | 917 | .markdown-body .task-list-item { 918 | list-style-type: none; 919 | } 920 | 921 | .markdown-body .task-list-item label { 922 | font-weight: 400; 923 | } 924 | 925 | .markdown-body .task-list-item.enabled label { 926 | cursor: pointer; 927 | } 928 | 929 | .markdown-body .task-list-item + .task-list-item { 930 | margin-top: 3px; 931 | } 932 | 933 | .markdown-body .task-list-item .handle { 934 | display: none; 935 | } 936 | 937 | .markdown-body .task-list-item-checkbox { 938 | margin: 0 .2em .25em -1.6em; 939 | vertical-align: middle; 940 | } 941 | 942 | .markdown-body .contains-task-list:dir(rtl) .task-list-item-checkbox { 943 | margin: 0 -1.6em .25em .2em; 944 | } 945 | 946 | .markdown-body ::-webkit-calendar-picker-indicator { 947 | filter: invert(50%); 948 | } 949 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/highlight.css: -------------------------------------------------------------------------------- 1 | /* From https://github.com/sindresorhus/github-markdown-css */ 2 | 3 | .markdown-body{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;margin:0;color:#24292f;background-color:#fff;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji";font-size:16px;line-height:1.5;word-wrap:break-word}.markdown-body .octicon{display:inline-block;fill:currentColor;vertical-align:text-bottom}.markdown-body h1:hover .anchor .octicon-link:before,.markdown-body h2:hover .anchor .octicon-link:before,.markdown-body h3:hover .anchor .octicon-link:before,.markdown-body h4:hover .anchor .octicon-link:before,.markdown-body h5:hover .anchor .octicon-link:before,.markdown-body h6:hover .anchor .octicon-link:before{width:16px;height:16px;content:' ';display:inline-block;background-color:currentColor;-webkit-mask-image:url("data:image/svg+xml,");mask-image:url("data:image/svg+xml,")}.markdown-body details,.markdown-body figcaption,.markdown-body figure{display:block}.markdown-body summary{display:list-item}.markdown-body [hidden]{display:none !important} 4 | .markdown-body a{background-color:transparent;color:#0969da;text-decoration:none}.markdown-body a:active,.markdown-body a:hover{outline-width:0}.markdown-body abbr[title]{border-bottom:none;text-decoration:underline dotted}.markdown-body b,.markdown-body strong{font-weight:600}.markdown-body dfn{font-style:italic}.markdown-body h1{margin:.67em 0;font-weight:600;padding-bottom:.3em;font-size:2em;border-bottom:1px solid hsla(210,18%,87%,1)}.markdown-body mark{background-color:#fff8c5;color:#24292f}.markdown-body small{font-size:90%}.markdown-body sub,.markdown-body sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}.markdown-body sub{bottom:-.25em}.markdown-body sup{top:-.5em}.markdown-body img{border-style:none;max-width:100%;box-sizing:content-box;background-color:#fff}.markdown-body code,.markdown-body kbd,.markdown-body pre,.markdown-body samp{font-family:monospace,monospace;font-size:1em}.markdown-body figure{margin:1em 40px}.markdown-body hr{box-sizing:content-box;overflow:hidden;background:0 0;border-bottom:1px solid hsla(210,18%,87%,1);height:.25em;padding:0;margin:24px 0;background-color:#d0d7de;border:0} 5 | .markdown-body input{font:inherit;margin:0;overflow:visible;font-family:inherit;font-size:inherit;line-height:inherit}.markdown-body [type=button],.markdown-body [type=reset],.markdown-body [type=submit]{-webkit-appearance:button}.markdown-body [type=button]::-moz-focus-inner,.markdown-body [type=reset]::-moz-focus-inner,.markdown-body [type=submit]::-moz-focus-inner{border-style:none;padding:0}.markdown-body [type=button]:-moz-focusring,.markdown-body [type=reset]:-moz-focusring,.markdown-body [type=submit]:-moz-focusring{outline:1px dotted ButtonText}.markdown-body [type=checkbox],.markdown-body [type=radio]{box-sizing:border-box;padding:0}.markdown-body [type=number]::-webkit-inner-spin-button,.markdown-body [type=number]::-webkit-outer-spin-button{height:auto}.markdown-body [type=search]{-webkit-appearance:textfield;outline-offset:-2px}.markdown-body [type=search]::-webkit-search-cancel-button,.markdown-body [type=search]::-webkit-search-decoration{-webkit-appearance:none}.markdown-body ::-webkit-input-placeholder{color:inherit;opacity:.54} 6 | .markdown-body ::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}.markdown-body a:hover{text-decoration:underline}.markdown-body hr:before{display:table;content:""}.markdown-body hr:after{display:table;clear:both;content:""}.markdown-body table{border-spacing:0;border-collapse:collapse;display:block;width:max-content;max-width:100%;overflow:auto}.markdown-body td,.markdown-body th{padding:0}.markdown-body details summary{cursor:pointer}.markdown-body details:not([open])>*:not(summary){display:none !important}.markdown-body kbd{display:inline-block;padding:3px 5px;font:11px ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;line-height:10px;color:#24292f;vertical-align:middle;background-color:#f6f8fa;border:solid 1px rgba(175,184,193,.2);border-bottom-color:rgba(175,184,193,.2);border-radius:6px;box-shadow:inset 0 -1px 0 rgba(175,184,193,.2)}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:24px;margin-bottom:16px;font-weight:600;line-height:1.25} 7 | .markdown-body h2{font-weight:600;padding-bottom:.3em;font-size:1.5em;border-bottom:1px solid hsla(210,18%,87%,1)}.markdown-body h3{font-weight:600;font-size:1.25em}.markdown-body h4{font-weight:600;font-size:1em}.markdown-body h5{font-weight:600;font-size:.875em}.markdown-body h6{font-weight:600;font-size:.85em;color:#57606a}.markdown-body p{margin-top:0;margin-bottom:10px}.markdown-body blockquote{margin:0;padding:0 1em;color:#57606a;border-left:.25em solid #d0d7de}.markdown-body ul {list-style:disc}.markdown-body ul,.markdown-body ol{margin-top:0;margin-bottom:0;padding-left:2em}.markdown-body ol ol,.markdown-body ul ol{list-style-type:lower-roman}.markdown-body ul ul ol,.markdown-body ul ol ol,.markdown-body ol ul ol,.markdown-body ol ol ol{list-style-type:lower-alpha}.markdown-body dd{margin-left:0}.markdown-body tt,.markdown-body code{font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;font-size:12px}.markdown-body pre{margin-top:0;margin-bottom:0;font-family:ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;font-size:12px;word-wrap:normal} 8 | .markdown-body .octicon{display:inline-block;overflow:visible !important;vertical-align:text-bottom;fill:currentColor}.markdown-body ::placeholder{color:#6e7781;opacity:1}.markdown-body input::-webkit-outer-spin-button,.markdown-body input::-webkit-inner-spin-button{margin:0;-webkit-appearance:none;appearance:none}.markdown-body .pl-c{color:#6e7781}.markdown-body .pl-c1,.markdown-body .pl-s .pl-v{color:#0550ae}.markdown-body .pl-e,.markdown-body .pl-en{color:#8250df}.markdown-body .pl-smi,.markdown-body .pl-s .pl-s1{color:#24292f}.markdown-body .pl-ent{color:#116329}.markdown-body .pl-k{color:#cf222e}.markdown-body .pl-s,.markdown-body .pl-pds,.markdown-body .pl-s .pl-pse .pl-s1,.markdown-body .pl-sr,.markdown-body .pl-sr .pl-cce,.markdown-body .pl-sr .pl-sre,.markdown-body .pl-sr .pl-sra{color:#0a3069}.markdown-body .pl-v,.markdown-body .pl-smw{color:#953800}.markdown-body .pl-bu{color:#82071e}.markdown-body .pl-ii{color:#f6f8fa;background-color:#82071e}.markdown-body .pl-c2{color:#f6f8fa;background-color:#cf222e} 9 | .markdown-body .pl-sr .pl-cce{font-weight:700;color:#116329}.markdown-body .pl-ml{color:#3b2300}.markdown-body .pl-mh,.markdown-body .pl-mh .pl-en,.markdown-body .pl-ms{font-weight:700;color:#0550ae}.markdown-body .pl-mi{font-style:italic;color:#24292f}.markdown-body .pl-mb{font-weight:700;color:#24292f}.markdown-body .pl-md{color:#82071e;background-color:#ffebe9}.markdown-body .pl-mi1{color:#116329;background-color:#dafbe1}.markdown-body .pl-mc{color:#953800;background-color:#ffd8b5}.markdown-body .pl-mi2{color:#eaeef2;background-color:#0550ae}.markdown-body .pl-mdr{font-weight:700;color:#8250df}.markdown-body .pl-ba{color:#57606a}.markdown-body .pl-sg{color:#8c959f}.markdown-body .pl-corl{text-decoration:underline;color:#0a3069}.markdown-body [data-catalyst]{display:block}.markdown-body g-emoji{font-family:"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol";font-size:1em;font-style:normal !important;font-weight:400;line-height:1;vertical-align:-.075em}.markdown-body g-emoji img{width:1em;height:1em} 10 | .markdown-body:before{display:table;content:""}.markdown-body:after{display:table;clear:both;content:""}.markdown-body>*:first-child{margin-top:0 !important}.markdown-body>*:last-child{margin-bottom:0 !important}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body .absent{color:#cf222e}.markdown-body .anchor{float:left;padding-right:4px;margin-left:-20px;line-height:1}.markdown-body .anchor:focus{outline:none}.markdown-body p,.markdown-body blockquote,.markdown-body ul,.markdown-body ol,.markdown-body dl,.markdown-body table,.markdown-body pre,.markdown-body details{margin-top:0;margin-bottom:16px}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body sup>a:before{content:"["}.markdown-body sup>a:after{content:"]"}.markdown-body h1 .octicon-link,.markdown-body h2 .octicon-link,.markdown-body h3 .octicon-link,.markdown-body h4 .octicon-link,.markdown-body h5 .octicon-link,.markdown-body h6 .octicon-link{color:#24292f;vertical-align:middle;visibility:hidden} 11 | .markdown-body h1:hover .anchor,.markdown-body h2:hover .anchor,.markdown-body h3:hover .anchor,.markdown-body h4:hover .anchor,.markdown-body h5:hover .anchor,.markdown-body h6:hover .anchor{text-decoration:none}.markdown-body h1:hover .anchor .octicon-link,.markdown-body h2:hover .anchor .octicon-link,.markdown-body h3:hover .anchor .octicon-link,.markdown-body h4:hover .anchor .octicon-link,.markdown-body h5:hover .anchor .octicon-link,.markdown-body h6:hover .anchor .octicon-link{visibility:visible}.markdown-body h1 tt,.markdown-body h1 code,.markdown-body h2 tt,.markdown-body h2 code,.markdown-body h3 tt,.markdown-body h3 code,.markdown-body h4 tt,.markdown-body h4 code,.markdown-body h5 tt,.markdown-body h5 code,.markdown-body h6 tt,.markdown-body h6 code{padding:0 .2em;font-size:inherit}.markdown-body ul.no-list,.markdown-body ol.no-list{padding:0;list-style-type:none}.markdown-body ol[type="1"]{list-style-type:decimal}.markdown-body ol[type=a]{list-style-type:lower-alpha} 12 | .markdown-body ol[type=i]{list-style-type:lower-roman}.markdown-body div>ol:not([type]){list-style-type:decimal}.markdown-body ul ul,.markdown-body ul ol,.markdown-body ol ol,.markdown-body ol ul{margin-top:0;margin-bottom:0}.markdown-body li>p{margin-top:16px}.markdown-body li+li{margin-top:.25em}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:600}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body table th{font-weight:600}.markdown-body table th,.markdown-body table td{padding:6px 13px;border:1px solid #d0d7de}.markdown-body table tr{background-color:#fff;border-top:1px solid hsla(210,18%,87%,1)}.markdown-body table tr:nth-child(2n){background-color:#f6f8fa}.markdown-body table img{background-color:transparent}.markdown-body img[align=right]{padding-left:20px}.markdown-body img[align=left]{padding-right:20px}.markdown-body .emoji{max-width:none;vertical-align:text-top;background-color:transparent} 13 | .markdown-body span.frame{display:block;overflow:hidden}.markdown-body span.frame>span{display:block;float:left;width:auto;padding:7px;margin:13px 0 0;overflow:hidden;border:1px solid #d0d7de}.markdown-body span.frame span img{display:block;float:left}.markdown-body span.frame span span{display:block;padding:5px 0 0;clear:both;color:#24292f}.markdown-body span.align-center{display:block;overflow:hidden;clear:both}.markdown-body span.align-center>span{display:block;margin:13px auto 0;overflow:hidden;text-align:center}.markdown-body span.align-center span img{margin:0 auto;text-align:center}.markdown-body span.align-right{display:block;overflow:hidden;clear:both}.markdown-body span.align-right>span{display:block;margin:13px 0 0;overflow:hidden;text-align:right}.markdown-body span.align-right span img{margin:0;text-align:right}.markdown-body span.float-left{display:block;float:left;margin-right:13px;overflow:hidden}.markdown-body span.float-left span{margin:13px 0 0}.markdown-body span.float-right{display:block;float:right;margin-left:13px;overflow:hidden} 14 | .markdown-body span.float-right>span{display:block;margin:13px auto 0;overflow:hidden;text-align:right}.markdown-body code,.markdown-body tt{padding:.2em .4em;margin:0;font-size:85%;background-color:rgba(175,184,193,.2);border-radius:6px}.markdown-body code br,.markdown-body tt br{display:none}.markdown-body del code{text-decoration:inherit}.markdown-body pre code{font-size:100%}.markdown-body pre>code{padding:0;margin:0;word-break:normal;white-space:pre;background:0 0;border:0}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f6f8fa;border-radius:6px}.markdown-body pre code,.markdown-body pre tt{display:inline;max-width:auto;padding:0;margin:0;overflow:visible;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}.markdown-body .csv-data td,.markdown-body .csv-data th{padding:5px;overflow:hidden;font-size:12px;line-height:1;text-align:left;white-space:nowrap} 15 | .markdown-body .csv-data .blob-num{padding:10px 8px 9px;text-align:right;background:#fff;border:0}.markdown-body .csv-data tr{border-top:0}.markdown-body .csv-data th{font-weight:600;background:#f6f8fa;border-top:0}.markdown-body .footnotes{font-size:12px;color:#57606a;border-top:1px solid #d0d7de}.markdown-body .footnotes ol{padding-left:16px}.markdown-body .footnotes li{position:relative}.markdown-body .footnotes li:target:before{position:absolute;top:-8px;right:-8px;bottom:-8px;left:-24px;pointer-events:none;content:"";border:2px solid #0969da;border-radius:6px}.markdown-body .footnotes li:target{color:#24292f}.markdown-body .footnotes .data-footnote-backref g-emoji{font-family:monospace}.markdown-body .task-list-item{list-style-type:none}.markdown-body .task-list-item label{font-weight:400}.markdown-body .task-list-item.enabled label{cursor:pointer}.markdown-body .task-list-item+.task-list-item{margin-top:3px}.markdown-body .task-list-item .handle{display:none}.markdown-body .task-list-item-checkbox{margin:0 .2em .25em -1.6em;vertical-align:middle} 16 | .markdown-body .contains-task-list:dir(rtl) .task-list-item-checkbox{margin:0 -1.6em .25em .2em}.markdown-body ::-webkit-calendar-picker-indicator{filter:invert(50%)} -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/md-template.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | [title] 5 | 6 | 7 | 8 | 9 | [content] 10 | 11 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/mermaid.min.js.LICENSE.txt: -------------------------------------------------------------------------------- 1 | /*! 2 | * Wait for document loaded before starting the execution 3 | */ 4 | 5 | /*! @license DOMPurify 2.3.8 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.3.8/LICENSE */ 6 | 7 | /*! Check if previously processed */ 8 | 9 | /*! sequence config was passed as #1 */ 10 | 11 | /** 12 | * @license 13 | * Copyright (c) 2012-2013 Chris Pettitt 14 | * 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy 16 | * of this software and associated documentation files (the "Software"), to deal 17 | * in the Software without restriction, including without limitation the rights 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 19 | * copies of the Software, and to permit persons to whom the Software is 20 | * furnished to do so, subject to the following conditions: 21 | * 22 | * The above copyright notice and this permission notice shall be included in 23 | * all copies or substantial portions of the Software. 24 | * 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 31 | * THE SOFTWARE. 32 | */ 33 | -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/prism-dark.css: -------------------------------------------------------------------------------- 1 | /* PrismJS 1.25.0 2 | https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript */ 3 | code[class*=language-],pre[class*=language-]{color:#ccc;background:0 0;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#2d2d2d}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.block-comment,.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#999}.token.punctuation{color:#ccc}.token.attr-name,.token.deleted,.token.namespace,.token.tag{color:#e2777a}.token.function-name{color:#6196cc}.token.boolean,.token.function,.token.number{color:#f08d49}.token.class-name,.token.constant,.token.property,.token.symbol{color:#f8c555}.token.atrule,.token.builtin,.token.important,.token.keyword,.token.selector{color:#cc99cd}.token.attr-value,.token.char,.token.regex,.token.string,.token.variable{color:#7ec699}.token.entity,.token.operator,.token.url{color:#67cdcc}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help}.token.inserted{color:green} -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/prism.css: -------------------------------------------------------------------------------- 1 | /* PrismJS 1.25.0 2 | https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+aspnet+basic+c+csharp+cpp+clojure+dart+docker+fsharp+go+graphql+java+json+kotlin+markdown+markup-templating+perl+php+powershell+protobuf+python+qsharp+r+cshtml+ruby+rust+scss+sql+typescript+vbnet+visual-basic+yaml */ 3 | code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.class-name,.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help} -------------------------------------------------------------------------------- /src/AskChatGPT/Utils/prism.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/adospace/chatgpt-vs-tool/3cd9c220103e218bdf9a3fcc9482a9c47566bf5a/src/AskChatGPT/Utils/prism.js -------------------------------------------------------------------------------- /src/AskChatGPT/VSCommandTable.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace AskChatGPT 7 | { 8 | using System; 9 | 10 | /// 11 | /// Helper class that exposes all GUIDs used across VS Package. 12 | /// 13 | internal sealed partial class PackageGuids 14 | { 15 | public const string AskChatGPTString = "dacfd347-05d7-43aa-9d44-b132e3bee4f7"; 16 | public static Guid AskChatGPT = new Guid(AskChatGPTString); 17 | } 18 | /// 19 | /// Helper class that encapsulates all CommandIDs uses across VS Package. 20 | /// 21 | internal sealed partial class PackageIds 22 | { 23 | public const int MyCommand = 0x0100; 24 | } 25 | } -------------------------------------------------------------------------------- /src/AskChatGPT/VSCommandTable.vsct: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /src/AskChatGPT/source.extension.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace AskChatGPT 7 | { 8 | internal sealed partial class Vsix 9 | { 10 | public const string Id = "AskChatGPT.809330fd-3f8f-4d94-98a8-7214d273c896"; 11 | public const string Name = "AskChatGPT"; 12 | public const string Description = @"This extension allows you to get help from ChatGPT directly inside Visual Studio."; 13 | public const string Language = "en-US"; 14 | public const string Version = "1.4"; 15 | public const string Author = "Adolfo Marinucci"; 16 | public const string Tags = ""; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/AskChatGPT/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AskChatGPT 6 | This extension allows you to get help from ChatGPT directly inside Visual Studio. 7 | Resources\Icon.png 8 | Resources\Icon.png 9 | 10 | 11 | 12 | amd64 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | --------------------------------------------------------------------------------