Skip to content

Commit

Permalink
Fix literate code to be compatible with v0.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jesterKing committed Dec 8, 2023
1 parent 7704f57 commit 87cbbb1
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 206 deletions.
12 changes: 6 additions & 6 deletions literate/code_actions.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h2>Provider class</h2>
<p>The action provider class takes a <code>FragmentRepository</code> in the constructor. This
will be used to compute the fragment name for which we need to create an action.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">LiterateCodeActionProvider</span> <span class="hljs-keyword">implements</span> vscode.<span class="hljs-property">CodeActionProvider</span>
{
Expand All @@ -22,7 +22,7 @@ <h2>Provider class</h2>
document, range, context and cancellation token. The cancellation token and
range we don't use.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="hljs-keyword">public</span> <span class="hljs-title function_">provideCodeActions</span>(
<span class="hljs-variable language_">document</span> : vscode.<span class="hljs-property">TextDocument</span>,
Expand All @@ -37,7 +37,7 @@ <h2>Provider class</h2>
</div><p>We start by initializing a new array of <code>CodeAction</code>, to which we will add any
if we determine we can provide them.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="hljs-keyword">let</span> codeActions = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Array</span>&lt;vscode.<span class="hljs-property">CodeAction</span>&gt;();
</code></pre>
Expand All @@ -47,7 +47,7 @@ <h2>Provider class</h2>
that starts with <code>&quot;Could not find fragment&quot;</code> we know we can create an action for
defining the fragment.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="hljs-keyword">for</span>(<span class="hljs-keyword">const</span> diag <span class="hljs-keyword">of</span> context.<span class="hljs-property">diagnostics</span>)
{
Expand All @@ -61,7 +61,7 @@ <h2>Provider class</h2>
diagnostics. We also get the fragment location so that we have access to its
name.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="hljs-keyword">let</span> fragmentLocation = <span class="hljs-variable language_">this</span>.<span class="hljs-property">repository</span>.<span class="hljs-title function_">getFragmentTagLocation</span>(<span class="hljs-variable language_">document</span>, <span class="hljs-variable language_">document</span>.<span class="hljs-title function_">lineAt</span>(diag.<span class="hljs-property">range</span>.<span class="hljs-property">start</span>), diag.<span class="hljs-property">range</span>.<span class="hljs-property">start</span>);
<span class="hljs-keyword">let</span> action = <span class="hljs-keyword">new</span> vscode.<span class="hljs-title class_">CodeAction</span>(<span class="hljs-string">`Create fragment for <span class="hljs-subst">${OPENING}</span><span class="hljs-subst">${fragmentLocation.name}</span><span class="hljs-subst">${CLOSING}</span>`</span>, context.<span class="hljs-property">only</span> ? context.<span class="hljs-property">only</span> : vscode.<span class="hljs-property">CodeActionKind</span>.<span class="hljs-property">Refactor</span>);
Expand All @@ -74,7 +74,7 @@ <h2>Provider class</h2>
</div>
</div><p>Finally return the code actions array.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;code action provider class&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="hljs-keyword">return</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">resolve</span>(codeActions);
}
Expand Down
18 changes: 9 additions & 9 deletions literate/code_completion.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h1>Code completion</h1>
<p>Until there is a good <strong>literate</strong> file type integration with Visual Studio Code
we'll be relying on the built-in <strong>Markdown</strong> functionality.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;register completion item provider&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;register completion item provider&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">const</span> completionItemProvider =
vscode.<span class="hljs-property">languages</span>.<span class="hljs-title function_">registerCompletionItemProvider</span>(<span class="hljs-string">&#x27;markdown&#x27;</span>, {
Expand All @@ -27,7 +27,7 @@ <h1>Code completion</h1>
we currently know of. Although the provider gets passed in the <code>TextDocument</code>
for which it was triggered we will present fragments from the entire project.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">async</span> <span class="hljs-title function_">provideCompletionItems</span>(<span class="hljs-params">
<span class="hljs-variable language_">document</span> : vscode.TextDocument,
Expand All @@ -43,7 +43,7 @@ <h1>Code completion</h1>
determined we return an empty array. This can happen with an unsaved new file,
or when documents were opened that are not part of the workspace.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="literate-tag-name">&lt;&lt;setup variables for providing completion items&gt;&gt;</span>
<span class="literate-tag-name">&lt;&lt;get workspace for TextDocument&gt;&gt;</span>
Expand All @@ -53,7 +53,7 @@ <h1>Code completion</h1>
</div><p>After the workspace folder has been determined we can gather all fragments in
our project.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="literate-tag-name">&lt;&lt;get fragments for completion items&gt;&gt;</span>
</code></pre>
Expand All @@ -62,7 +62,7 @@ <h1>Code completion</h1>
</div><p>Finally we generate the completion items into the array <code>completionItems</code> that
we return when done.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=+</div>
<div class="fragmentname">&lt;&lt;implement provide completion items&gt;&gt;=+ </div>
<div class="code">
<pre><code> <span class="literate-tag-name">&lt;&lt;for each fragment create a completion item&gt;&gt;</span>
<span class="hljs-keyword">return</span> completionItems;
Expand All @@ -73,7 +73,7 @@ <h1>Code completion</h1>
</div><h3>Setting up variables</h3>
<p>Completion items are going to be collected in an <code>Array&lt;CompletionItem&gt;</code>.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;setup variables for providing completion items&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;setup variables for providing completion items&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">let</span> completionItems : <span class="hljs-title class_">Array</span>&lt;vscode.<span class="hljs-property">CompletionItem</span>&gt; =
<span class="hljs-keyword">new</span> <span class="hljs-title class_">Array</span>&lt;vscode.<span class="hljs-property">CompletionItem</span>&gt;();
Expand All @@ -88,7 +88,7 @@ <h1>Code completion</h1>
workspace folder we essentially end up returning an empty array from the
completion item provider.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;get workspace for TextDocument&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;get workspace for TextDocument&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">const</span> workspaceFolder : vscode.<span class="hljs-property">WorkspaceFolder</span> | <span class="hljs-literal">undefined</span> = <span class="hljs-title function_">determineWorkspaceFolder</span>(<span class="hljs-variable language_">document</span>);
<span class="hljs-keyword">if</span>(!workspaceFolder) { <span class="hljs-keyword">return</span> []; }
Expand All @@ -102,7 +102,7 @@ <h1>Code completion</h1>
opening chevron. That means we need to ensure <strong>literate</strong> files are processed
before getting the fragment map for our workspace folder.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;get fragments for completion items&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;get fragments for completion items&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">await</span> theOneRepository.<span class="hljs-title function_">processLiterateFiles</span>(workspaceFolder);
<span class="hljs-keyword">let</span> fragments = theOneRepository.<span class="hljs-title function_">getFragments</span>(workspaceFolder).<span class="hljs-property">map</span>;
Expand All @@ -119,7 +119,7 @@ <h1>Code completion</h1>
<p>Finally the set the completion item kind to <code>Reference</code> so that we get a nice
icon in the completion list pop-up.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;for each fragment create a completion item&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;for each fragment create a completion item&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">for</span>(<span class="hljs-keyword">const</span> fragmentName <span class="hljs-keyword">of</span> fragments.<span class="hljs-title function_">keys</span>())
{
Expand Down
8 changes: 4 additions & 4 deletions literate/definition_provider.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ <h1>Definition provider</h1>
The provider method will return a <code>vscode.Location</code> when the definition is
found.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;definition provider class&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;definition provider class&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">export</span> <span class="hljs-keyword">class</span> <span class="hljs-title class_">LiterateDefinitionProvider</span> <span class="hljs-keyword">implements</span> vscode.<span class="hljs-property">DefinitionProvider</span>
{
Expand All @@ -24,7 +24,7 @@ <h1>Definition provider</h1>
access the tools necessary to find the correct fragment definition. We'll do
this as a parameter property.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;definiton provider construction&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;definiton provider construction&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-title function_">constructor</span>(<span class="hljs-params">
<span class="hljs-keyword">private</span> <span class="hljs-keyword">readonly</span> repository : FragmentRepository
Expand All @@ -35,7 +35,7 @@ <h1>Definition provider</h1>
</div><p>The provider method takes a text document and a position. The cancellation token
is unused.</p>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;definiton provider implementation&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;definiton provider implementation&gt;&gt;= </div>
<div class="code">
<pre><code><span class="hljs-keyword">public</span> provideDefinition
(
Expand Down Expand Up @@ -67,7 +67,7 @@ <h1>Definition provider</h1>
</div>
</div><h2>Registering the definition provider</h2>
<div class="codefragment">
<div class="fragmentname">&lt;&lt;register definiton provider&gt;&gt;=</div>
<div class="fragmentname">&lt;&lt;register definiton provider&gt;&gt;= </div>
<div class="code">
<pre><code>context.<span class="hljs-property">subscriptions</span>.<span class="hljs-title function_">push</span>(
vscode.<span class="hljs-property">languages</span>.<span class="hljs-title function_">registerDefinitionProvider</span>(
Expand Down
Loading

0 comments on commit 87cbbb1

Please sign in to comment.