-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add diagnostics for incorrect specs
- Loading branch information
1 parent
940e6e1
commit 046219f
Showing
4 changed files
with
296 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ISpectralDiagnostic } from '@stoplight/spectral-core'; | ||
import * as vscode from 'vscode'; | ||
import * as ejs from 'ejs'; | ||
import * as path from 'path'; | ||
|
||
export default async function diagnosticsMarkdown(diagnostics: ISpectralDiagnostic[], context: vscode.ExtensionContext){ | ||
const templatePath = path.join(context.extensionPath,'dist', 'components','Diagnostics.ejs'); | ||
let data: object[] = []; | ||
let recentErrorPath: string = ""; | ||
let joinedPath: string = ""; | ||
diagnostics.forEach(diagnostic =>{ | ||
joinedPath = diagnostic.path.join(' / '); | ||
console.log(joinedPath, recentErrorPath, data.length); | ||
if(joinedPath.indexOf(recentErrorPath) === -1 || !recentErrorPath){ | ||
recentErrorPath = joinedPath; | ||
data.push({ | ||
code: diagnostic.code, | ||
message: diagnostic.message, | ||
path: recentErrorPath, | ||
severity: diagnostic.severity, | ||
source: diagnostic.source | ||
}); | ||
}else{ | ||
recentErrorPath = joinedPath; | ||
data[data.length - 1] = { | ||
code: diagnostic.code, | ||
message: diagnostic.message, | ||
path: recentErrorPath, | ||
severity: diagnostic.severity, | ||
source: diagnostic.source | ||
}; | ||
} | ||
}); | ||
return await ejs.renderFile(templatePath, {data}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<h3> Error Loading Preview </h3> | ||
<% data.forEach(diagnostic => { %> | ||
<div class="diagnostic"> | ||
<% if(diagnostic.severity == 0) { %> | ||
<div class="left-bar high"></div> | ||
<% } else if(diagnostic.severity == 1) { %> | ||
<div class="left-bar medium"></div> | ||
<% }else if(diagnostic.severity == 2) { %> | ||
<div class="left-bar low"></div> | ||
<% }else if(diagnostic.severity == 3) { %> | ||
<div class="left-bar hint"></div> | ||
<% } %> | ||
<div class="content-box"> | ||
<h2 class="message"><span class="icon">⚠️</span><%= diagnostic.message %></h2> | ||
<p class="secondary-text"><%= diagnostic.path %></p> | ||
<pre class="code"><%= diagnostic.code %></pre> | ||
<p class="source">Source: <%= diagnostic.source %></p> | ||
<p class="severity">Severity: <%= diagnostic.severity %></p> | ||
</div> | ||
</div> | ||
<% }) %> |
Oops, something went wrong.