Skip to content

Commit

Permalink
Add source and hover information to error output
Browse files Browse the repository at this point in the history
For the CLI, only the source (i.e. title property) is added.
FOr the CI, the hover information (title, description, examples) are
added and formatted according to YAMLHover.
  • Loading branch information
AndreasMadsen committed Jan 12, 2024
1 parent 7d24f5d commit 18e1187
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 14 deletions.
24 changes: 16 additions & 8 deletions github-action/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import * as core from '@actions/core';
import * as path from 'path';
import { YamlVersion } from 'yaml-language-server/out/server/src/languageservice/parser/yamlParser07';
import { SchemaMapping, validateDirectory } from '../src';
import { MarkupContent } from 'vscode-languageserver-types';

import { marked } from 'marked';
import { markedTerminal } from 'marked-terminal';

async function run() {
marked.use(markedTerminal() as any);

let rootPath = process.env['GITHUB_WORKSPACE'] as string;
let relativeToRoot = core.getInput('root', { trimWhitespace: true });
if (relativeToRoot) {
Expand All @@ -29,17 +35,19 @@ async function run() {
if (results && results.length > 0) {
for (const result of results) {
for (const error of result.error) {
const { diag, hover } = error;
const hoverMessage = (hover && MarkupContent.is(hover.contents)) ? `\n\n${marked(hover.contents.value)}` : ''


core.error(
`${result.filePath}:${error.range.start.line + 1}:${error.range.start.character + 1}: ${
error.message
}`,
diag.message + hoverMessage,
{
title: error.message,
title: `${diag.message}${diag.source ? ' ' + diag.source + '.' : ''}`,
file: result.filePath,
startLine: error.range.start.line + 1,
endLine: error.range.end.line + 1,
startColumn: error.range.start.character,
endColumn: error.range.end.character,
startLine: diag.range.start.line + 1,
endLine: diag.range.end.line + 1,
startColumn: diag.range.start.character,
endColumn: diag.range.end.character,
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion github-action/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = {
),
],
resolve: {
extensions: [ '.ts', '.js' ],
extensions: [ '.ts', '.js', '.json' ],
},
output: {
filename: 'index.js',
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@
"@actions/core": "^1.10.0",
"@types/glob": "^7.1.4",
"@types/jest": "^27.0.2",
"@types/marked-terminal": "^6.0.1",
"@types/node": "^16.9.4",
"jest": "^27.2.1",
"marked": "^11.1.1",
"marked-terminal": "^6.2.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.4.1",
"rimraf": "^3.0.2",
Expand Down
136 changes: 136 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 18e1187

Please sign in to comment.