merge: Added lines and line numbers to syntax errors (!395)

View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/395

Approved-by: dakkar <dakkar@thenautilus.net>
This commit is contained in:
Leah 2024-02-03 16:05:33 +00:00
commit 441523b6d4
3 changed files with 22 additions and 1 deletions

View file

@ -58,6 +58,21 @@ watch(() => props.lang, (to) => {
</script>
<style scoped lang="scss">
.codeBlockRoot :deep(.shiki) > code {
counter-reset: step;
counter-increment: step 0;
}
.codeBlockRoot :deep(.shiki) > code > .line::before {
content: counter(step);
counter-increment: step;
width: 1rem;
margin-right: 1.5rem;
display: inline-block;
text-align: right;
color: rgba(115,138,148,.4)
}
.codeBlockRoot :deep(.shiki) {
padding: 1em;
margin: .5em 0;

View file

@ -204,6 +204,8 @@ watch(v, newValue => {
min-width: calc(100% - 24px);
height: 100%;
padding: 12px;
// the +2.5 rem is because of the line numbers
padding-left: calc(12px + 2.5rem);
line-height: 1.5em;
font-size: 1em;
font-family: Consolas, Monaco, Andale Mono, Ubuntu Mono, monospace;

View file

@ -64,7 +64,11 @@ export async function parsePluginMeta(code: string): Promise<AiScriptPluginMeta>
try {
ast = parser.parse(code);
} catch (err) {
throw new Error('Aiscript syntax error');
if (err instanceof Error) {
throw new Error(`Aiscript syntax error\n${(err as Error).message}`);
} else {
throw new Error('Aiscript syntax error');
}
}
const meta = Interpreter.collectMetadata(ast);