<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>vs code on Cory Knox</title>
    <link>https://coryknox.dev/tags/vs-code/</link>
    <description>Recent content in vs code on Cory Knox</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Fri, 23 Feb 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://coryknox.dev/tags/vs-code/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Run PowerShell no matter what</title>
      <link>https://coryknox.dev/posts/2024/run-powershell-no-mater-what/</link>
      <pubDate>Fri, 23 Feb 2024 00:00:00 +0000</pubDate>
      
      <guid>https://coryknox.dev/posts/2024/run-powershell-no-mater-what/</guid>
      <description>&lt;p&gt;VS Code is pretty amazing.
Having the ability to edit virtually all of your files, and launch debugging sessions of them.
But what if you have a codebase that has a &lt;code&gt;.vscode/launch.json&lt;/code&gt; file and want to debug a PowerShell script?&lt;/p&gt;
&lt;p&gt;Unfortunately, by default, &lt;code&gt;F5&lt;/code&gt; will only debug PowerShell if there are no debugger configurations.
This means that pressing &lt;code&gt;F5&lt;/code&gt; will attempt to run the configured debugger for your workspace regardless of if you&amp;rsquo;re in a PowerShell file.&lt;/p&gt;
&lt;p&gt;Fear not!
Although by default you&amp;rsquo;re not able to run PowerShell code with &lt;code&gt;F5&lt;/code&gt; when a debugger configuration exists, you are able to tell VS Code you want to do this!&lt;/p&gt;
&lt;h2 id=&#34;doing-it-through-the-gui&#34;&gt;Doing it through the GUI &lt;a href=&#34;#doing-it-through-the-gui&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;If you&amp;rsquo;d like to add this through the VS Code GUI, you can follow these steps:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Open the Keyboard Shortcuts UI (&lt;code&gt;Ctrl + K, Ctrl + S&lt;/code&gt; by default, or search for &lt;code&gt;Preferences: Keyboard Shortcuts&lt;/code&gt; with the Command Palette), then search for &lt;code&gt;PowerShell: Run&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Locate and double click the entry for &lt;code&gt;PowerShell: Run&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Press &lt;code&gt;F5&lt;/code&gt; followed by &lt;code&gt;Enter&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Right click the entry and choose &lt;code&gt;Change When Expression&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Enter the following for the expression: &lt;code&gt;editorTextFocus &amp;amp;&amp;amp; debugState == &#39;inactive&#39; &amp;amp;&amp;amp; editorLangId == &#39;powershell&#39;&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Bask in the glory that is pressing &lt;code&gt;F5&lt;/code&gt; in a PowerShell script and always having it do what you expect it to do.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;doing-it-through-the-keybindingsjson-file&#34;&gt;Doing it through the &lt;code&gt;keybindings.json&lt;/code&gt; file &lt;a href=&#34;#doing-it-through-the-keybindingsjson-file&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;If you&amp;rsquo;d prefer to just copy/paste something into the settings files, you can add the below to your &lt;code&gt;keybindings.json&lt;/code&gt; file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-json&#34; data-lang=&#34;json&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;nt&#34;&gt;&amp;#34;key&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;f5&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;nt&#34;&gt;&amp;#34;command&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;PowerShell.Debug.Start&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;        &lt;span class=&#34;nt&#34;&gt;&amp;#34;when&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;s2&#34;&gt;&amp;#34;editorTextFocus &amp;amp;&amp;amp; debugState == &amp;#39;inactive&amp;#39; &amp;amp;&amp;amp; editorLangId == &amp;#39;powershell&amp;#39;&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;    &lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You can locate your &lt;code&gt;keybindings.json&lt;/code&gt; file through the Command Palette &lt;code&gt;Preferences: Open Keyboard Shortcuts (JSON)&lt;/code&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>A Foray into vscode-powershell</title>
      <link>https://coryknox.dev/posts/2018/foray-into-vscode-powershell/</link>
      <pubDate>Mon, 03 Sep 2018 00:00:00 +0000</pubDate>
      
      <guid>https://coryknox.dev/posts/2018/foray-into-vscode-powershell/</guid>
      <description>&lt;p&gt;This is a foray into getting started with the vscode-powershell extension. In particular noting some of the perhaps less obvious things I needed to do in order to get it to build on Ubuntu 18.04.&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;First thing you&amp;rsquo;ll need to do of course is to fork the repository. There are two repositories that we want to fork to our github account: &lt;a href=&#34;https://github.com/PowerShell/PowerShellEditorServices&#34;&gt;PowerShellEditorService&lt;/a&gt; and &lt;a href=&#34;https://github.com/PowerShell/vscode-powershell&#34;&gt;vscode-powershell&lt;/a&gt;. Once you&amp;rsquo;ve forked them (and perhaps made hours of work that Tiler and Rob keep harrassing you as not being good enough&amp;hellip;) you need to clone them to your local machine. I highly recommend keeping them side by side and so I clone them into a repos directory. On my Windows machine all of my git repos are stored at &lt;code&gt;C:\repos\&lt;/code&gt; on my fresh install of Ubuntu Linux 18.04 they&amp;rsquo;re stored at &lt;code&gt;~/git/&lt;/code&gt;.&lt;/p&gt;
&lt;h1 id=&#34;system-software-to-install&#34;&gt;System software to install &lt;a href=&#34;#system-software-to-install&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h1&gt;&lt;p&gt;Now after freshly installing Ubuntu 18.04, I have installed the following software on top of the base:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;PowerShell-Preview - PowerShell 6.1 is in Release Candidate, and is the only &amp;ldquo;Supported&amp;rdquo; version for Ubuntu 18.04&lt;/li&gt;
&lt;li&gt;npm - Not entirely sure if I installed this one, or if it&amp;rsquo;s just installed as part of Ubuntu&amp;hellip; It&amp;rsquo;s definitely installed though.&lt;/li&gt;
&lt;li&gt;VS Code Insiders&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Once this is installed, and the repos are cloned. I opened vscode-powershell in vscode-insiders. I then selected &lt;code&gt;Debug &amp;gt; Start Debugging&lt;/code&gt; This greeted me with the message: &amp;ldquo;The preLaunchTask &amp;lsquo;BuildAll&amp;rsquo; terminated with exit code 1.&amp;rdquo; Clearly we&amp;rsquo;re missing some pre-requisites&amp;hellip; Looking in the terminal we see:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;&amp;gt; Executing task: Invoke-Build BuildAll &amp;lt;

execvp(3) failed.: No such file or directory
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This initially felt like we were missing InvokeBuild from the PowerShell Gallery. Unfortunately, after installing that, the error is still present. The build appears to work if we do Invoke-Build from pwsh-preview.&lt;/p&gt;
&lt;p&gt;It turns out that this is the trick here. We&amp;rsquo;re using a preview build of pwsh on Ubuntu 18.04, because that is what&amp;rsquo;s available. To resolve this, we can simply create a symlink from pwsh to pwsh-preview&amp;hellip; This may need to be resolved once pwsh 6.1 leaves Release Candidate, or the installation of pwsh may resolve it for us. To create the symlink: &lt;code&gt;sudo ln -s /usr/bin/pwsh-preview /usr/bin/pwsh&lt;/code&gt;. Once this symlink is created, debugging of both vscode-powershell and PowerShellEditorServices seems to go off without a hitch.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion &lt;a href=&#34;#conclusion&#34; class=&#34;anchor&#34;&gt;🔗&lt;/a&gt;&lt;/h2&gt;&lt;p&gt;Once getting over the hurdle of pwsh not being available outside of a preview on Ubuntu 18.04, getting vscode-powershell and PowerShellEditorServices development going in Ubuntu 18.04 is actually really easy, and dare I say may be even easier than doing the same thing on Windows 10&amp;hellip;&lt;/p&gt;
&lt;p&gt;I did note while investigating the pwsh-preview issue that there are already documents that may provide more information (and will at least be more up to date than this document) here: &lt;a href=&#34;https://github.com/PowerShell/vscode-powershell/blob/master/docs/development.md&#34;&gt;vscode-powershell Development Document&lt;/a&gt; and here: &lt;a href=&#34;https://github.com/PowerShell/PowerShellEditorServices#development&#34;&gt;PowerShellEditorServices ReadMe&lt;/a&gt;.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>So you want to make a VS Code extension</title>
      <link>https://coryknox.dev/posts/2018/vscode-extensioning/</link>
      <pubDate>Tue, 03 Jul 2018 00:00:00 +0000</pubDate>
      
      <guid>https://coryknox.dev/posts/2018/vscode-extensioning/</guid>
      <description>&lt;p&gt;So, you have this great idea for a VS Code extension? But perhaps you&amp;rsquo;re thinking &amp;ldquo;where do I start?&amp;rdquo; Well, fear not! for I have written this post to tell you the answer!&lt;/p&gt;
&lt;!-- raw HTML omitted --&gt;
&lt;p&gt;Oh? Were you expecting me to have the answer? Well, you see the truth is I have no idea. I just took some code, put some other code in it, and it worked (well sorta).&lt;/p&gt;
&lt;p&gt;But for reals: Decide if you want to use TypeScript or JavaScript (I picked TypeScript because all the samples were in TypeScript). Then take a look at &lt;a href=&#34;https://code.visualstudio.com/docs/extensions/example-hello-world&#34;&gt;https://code.visualstudio.com/docs/extensions/example-hello-world&lt;/a&gt; to get your first example done.&lt;/p&gt;
&lt;p&gt;If like me you have little experience with TypeScript, it is worth reading through this one to try and understand what it is doing. Also take a look at the examples: &lt;a href=&#34;https://code.visualstudio.com/docs/extensions/example-hello-world&#34;&gt;https://github.com/Microsoft/vscode-extension-samples&lt;/a&gt; I went here to look at the tree-view-sample for the one I&amp;rsquo;m working on.&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>
