Skip to content

Commit

Permalink
add message for custom python binary path
Browse files Browse the repository at this point in the history
  • Loading branch information
dmca-glasgow committed May 16, 2022
1 parent a8430c4 commit 9729c6a
Showing 1 changed file with 38 additions and 10 deletions.
48 changes: 38 additions & 10 deletions compiler/src/knitr/knitr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { VFile } from 'vfile';

import { Context } from '../context';
import { Unit } from '../course/types';
import { warnMessage } from '../utils/message';
import { infoMessage, warnMessage } from '../utils/message';
import { mkdir, rmFile, writeFile } from '../utils/utils';

// bypass knitr for debugging
Expand Down Expand Up @@ -133,22 +133,50 @@ function getKnitrFileDir() {
}

function reportErrors(response: string, file: VFile) {
response.split(EOL).forEach((line, idx) => {
const trimmed = line.trim();
if (trimmed.startsWith('WARNING -')) {
warnMessage(file, trimmed.replace('WARNING - ', ''), {
const lines = response
.split(EOL)
.filter((s) => !s.startsWith(':directory'));

const trimmed = lines.join(EOL).trim();

// Warning at the start of a document
if (trimmed.startsWith('WARNING -')) {
const match = trimmed.match(/^WARNING - (.+?)[\r\n]{2,}/ms);
if (match !== null) {
warnMessage(file, match[1], {
start: {
line: idx + 1,
line: 1,
column: 0,
},
end: {
line: idx + 1,
column: line.length,
line: 1,
column: lines[0].length,
},
});
}
if (trimmed.startsWith('## Error')) {
warnMessage(file, trimmed.replace('## ', ''), {

// Python binary path
} else if (trimmed.startsWith('$python [1]')) {
const match = trimmed.match(/^\$python\s\[1\]\s("\S+")/);
if (match !== null) {
infoMessage(file, match[1], {
start: {
line: 1,
column: 0,
},
end: {
line: 1,
column: lines[0].length,
},
});
}
}

// Errors throughout document
lines.forEach((line, idx) => {
const trimmedLine = line.trim();
if (trimmedLine.startsWith('## Error')) {
warnMessage(file, trimmedLine.replace('## ', ''), {
start: {
line: idx + 1,
column: 0,
Expand Down

0 comments on commit 9729c6a

Please sign in to comment.