123 lines
6.1 KiB
HTML
123 lines
6.1 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml"><head>
|
|
<meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<link rel="stylesheet" href="main.css" type="text/css" />
|
|
<link rel="stylesheet" href="blog.css" type="text/css" />
|
|
<link rel="alternate" type="application/rss+xml" title="Subscribe to this page..." href="feed.rss" />
|
|
<title>Vim Quickfix and PowerShell revisited</title>
|
|
</head><body>
|
|
<div id="divbodyholder">
|
|
<div class="headerholder"><div class="header">
|
|
<div id="title">
|
|
<h1 class="nomargin"><a class="ablack" href="http://zigford.org/index.html">zigford.org</a></h1>
|
|
<div id="description"><a href="about.html">About</a><a href="links.html"> | Links</a><a href="scripts.html"> | Scripts</a><br>Sharing linux/windows scripts and tips</br></div>
|
|
</div></div></div>
|
|
<div id="divbody"><div class="content">
|
|
<!-- entry begin -->
|
|
<h3><a class="ablack" href="vim-quickfix-and-powershell-revisited.html">
|
|
Vim Quickfix and PowerShell revisited
|
|
</a></h3>
|
|
<!-- bashblog_timestamp: #201908212349.18# -->
|
|
<div class="subtitle">August 21, 2019 —
|
|
Jesse Harris
|
|
</div>
|
|
<!-- text begin -->
|
|
<p>Pretty much any language can be made to work well with Vim without having to
|
|
resort to Plugins. That's the beauty of it. Vim is a tool, PowerShell is a tool.
|
|
It's worth getting to know your tools intermitly to become an expert.</p>
|
|
<hr />
|
|
<p>I won't say I'm an expert, but I have been enjoying using some more advanced
|
|
features of Vim and PowerShell lately. That's why when <a href="vim-quickfix-and-powershell.html">Enno wrote in
|
|
originally</a>, I was eager to find a solution.</p>
|
|
<p>Recently Enno wrote in again</p>
|
|
<blockquote>
|
|
<p>Dear Jesse,</p>
|
|
<p>I found no issue tracker in your repository
|
|
<a href="https://github.com/zigford/vim-powershell">https://github.com/zigford/vim-powershell</a>, therefore let me try to
|
|
reach out to you by mail:</p>
|
|
<p>Currently, one cannot jump to the error shown in the quickfix list,
|
|
because the file name is not contained in the output of &makeprg. Sadly,
|
|
:help errorfmt says</p>
|
|
<p>If the error format does not contain a file name Vim cannot switch to the
|
|
correct file. You will have to do this by hand.</p>
|
|
<p>But perhaps the parameters passed to pwsh can be tweaked so that the
|
|
file name shows up at some point?</p>
|
|
<p>Best wishes</p>
|
|
<p>Enno</p>
|
|
</blockquote>
|
|
<p>That was about a month ago. Apologies for the delayed response Enno, I've been
|
|
busy playing with Gentoo on my new Raspberry Pi 4.</p>
|
|
<p>Anyway, tonight I decided to investigate how to solve the problem.</p>
|
|
<p>The problem can be summed up in 2 parts.</p>
|
|
<ol>
|
|
<li>How to make PowerShell emit the filename</li>
|
|
<li>How to read the filename with <code>errorformat</code></li>
|
|
</ol>
|
|
<h2 id="emit-the-filename">Emit the FileName!</h2>
|
|
<p>This one didn't take me too long to figure out. When I first <a href="https://github.com/dense-analysis/ale/blob/73812c3e41c1c7fcf1705811f35ac4c9ccec003e/ale_linters/powershell/powershell.vim#L12">borrowed code</a>
|
|
from <a href="https://rkeithhill.wordpress.com/2007/10/30/powershell-quicktip-preparsing-scripts-to-check-for-syntax-errors/">keith hill</a>, I looked and understood what was happening conceptually
|
|
but did not think to use the interactive nature of PowerShell and see what else
|
|
it could do.</p>
|
|
<p>Anyway, tonight, the good ole <code>Get-Member</code> makes a solution bleeding obvious:</p>
|
|
<pre><code> $ExecutionContext.InvokeCommand|Get-Member
|
|
|
|
Name MemberType
|
|
---- ----------
|
|
InvokeScript Method
|
|
NewScriptBlock Method
|
|
ToString Method
|
|
CommandNotFoundAction Property
|
|
HasErrors Property
|
|
LocationChangedAction Property
|
|
PostCommandLookupAction Property
|
|
PreCommandLookupAction Property
|
|
</code></pre>
|
|
<p>Using Keith Hills, code I quick adapt to using InvokeScript which probably (and
|
|
doesn't) need to be joining strings arrays together anymore.</p>
|
|
<p>Here, I demonstrate:</p>
|
|
<pre><code> trap {$_.tostring();continue}&{
|
|
>> [void]$ExecutionContext.InvokeCommand.InvokeScript('./bad.ps1')
|
|
>> }
|
|
At /Users/jpharris/bad.ps1:1 char:16
|
|
+ function silly {
|
|
+ ~
|
|
Missing closing '}' in statement block or type definition.
|
|
</code></pre>
|
|
<p>So finally we have the filename where 'line' used to be before. All that's left
|
|
to do now is update the errorformat.</p>
|
|
<h2 id="errorformat">Errorformat</h2>
|
|
<p>I say to myself "this shouldn't be too hard", and this is what I think should
|
|
work:</p>
|
|
<pre><code> set errorformat=%EAt\ %f:%l\ char:%c,%-C+%.%#,%Z%m,%-G\\s%#
|
|
</code></pre>
|
|
<p>But it doesn't! And I sit there for a few hours trying to debug it. Why won't it
|
|
work? The silly thing is, it does work and the errorformat is correct, but today
|
|
is one of those days I get to learn something new about Vim (just like every
|
|
other day).</p>
|
|
<p>I haven't been setting the errorformat in my vim window (I'm not a monster).
|
|
I've been setting it by editing the compiler PowerShell.vim file in my plugin.</p>
|
|
<p>I decide to check if the errorformat is being set correctly with:</p>
|
|
<pre><code> verbose set errorformat?
|
|
errorformat=%EAt line:%l char:%c,%-+%.%#,%Z%m,%-G\s%#
|
|
Last set from ~/.vimother/views/~=+bad.ps1= line 29
|
|
</code></pre>
|
|
<p>Ahuh! I did not know it, but errorformat can be saved into a view, therefore I
|
|
was never testing any of my changes!</p>
|
|
<p>Anyway, I best upload my change to github and head off to sleep.</p>
|
|
<p>Tags: <a href='tag_vim.html'>vim</a>, <a href='tag_powershell.html'>powershell</a></p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<!-- text end -->
|
|
<!-- entry end -->
|
|
</div>
|
|
<div id="footer">© <a href="http://twitter.com/zigford_org">Jesse Harris</a> — <a href="mailto:jesse@zigford.org">jesse@zigford.org</a><br/>
|
|
Generated with <a href="https://github.com/cfenollosa/bashblog">bashblog</a>, a single bash script to easily create blogs like this one</div>
|
|
</div></div>
|
|
</body></html>
|