mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-26 18:22:13 +00:00
First pass at parsing and showing decent biber errors.
This commit is contained in:
parent
e814dfa7a8
commit
f6d02090d2
2 changed files with 102 additions and 25 deletions
|
@ -1,7 +1,8 @@
|
|||
define [
|
||||
"base"
|
||||
"libs/latex-log-parser"
|
||||
], (App, LogParser) ->
|
||||
"libs/biber-log-parser"
|
||||
], (App, LogParser, BiberLogParser) ->
|
||||
App.controller "PdfController", ($scope, $http, ide, $modal, synctex, event_tracking, localStorage) ->
|
||||
autoCompile = true
|
||||
$scope.$on "project:joined", () ->
|
||||
|
@ -12,7 +13,7 @@ define [
|
|||
|
||||
$scope.$on "pdf:error:display", () ->
|
||||
$scope.pdf.error = true
|
||||
|
||||
|
||||
$scope.draft = localStorage("draft:#{$scope.project_id}") or false
|
||||
$scope.$watch "draft", (new_value, old_value) ->
|
||||
if new_value? and old_value != new_value
|
||||
|
@ -82,25 +83,45 @@ define [
|
|||
qs = if outputFile?.build? then "?build=#{outputFile.build}" else ""
|
||||
$http.get "/project/#{$scope.project_id}/output/output.log" + qs
|
||||
.success (log) ->
|
||||
#console.log ">>", log
|
||||
$scope.pdf.rawLog = log
|
||||
logEntries = LogParser.parse(log, ignoreDuplicates: true)
|
||||
#console.log ">>", logEntries
|
||||
$scope.pdf.logEntries = logEntries
|
||||
$scope.pdf.logEntries.all = logEntries.errors.concat(logEntries.warnings).concat(logEntries.typesetting)
|
||||
# # # #
|
||||
forward = () ->
|
||||
$scope.pdf.logEntryAnnotations = {}
|
||||
for entry in logEntries.all
|
||||
if entry.file?
|
||||
entry.file = normalizeFilePath(entry.file)
|
||||
|
||||
$scope.pdf.logEntryAnnotations = {}
|
||||
for entry in logEntries.all
|
||||
if entry.file?
|
||||
entry.file = normalizeFilePath(entry.file)
|
||||
|
||||
entity = ide.fileTreeManager.findEntityByPath(entry.file)
|
||||
if entity?
|
||||
$scope.pdf.logEntryAnnotations[entity.id] ||= []
|
||||
$scope.pdf.logEntryAnnotations[entity.id].push {
|
||||
row: entry.line - 1
|
||||
type: if entry.level == "error" then "error" else "warning"
|
||||
text: entry.message
|
||||
}
|
||||
|
||||
entity = ide.fileTreeManager.findEntityByPath(entry.file)
|
||||
if entity?
|
||||
$scope.pdf.logEntryAnnotations[entity.id] ||= []
|
||||
$scope.pdf.logEntryAnnotations[entity.id].push {
|
||||
row: entry.line - 1
|
||||
type: if entry.level == "error" then "error" else "warning"
|
||||
text: entry.message
|
||||
}
|
||||
$http.get "/project/#{$scope.project_id}/output/output.blg" + qs
|
||||
.success (log) ->
|
||||
window._s = $scope
|
||||
console.log ">> yay"
|
||||
console.log log
|
||||
biberLogEntries = BiberLogParser.parse(log, {})
|
||||
console.log biberLogEntries
|
||||
if $scope.pdf.logEntries
|
||||
entries = $scope.pdf.logEntries
|
||||
all = biberLogEntries.errors.concat(biberLogEntries.warnings)
|
||||
entries.all = entries.all.concat(all)
|
||||
entries.errors = entries.errors.concat(biberLogEntries.errors)
|
||||
entries.warnings = entries.warnings.concat(biberLogEntries.warnings)
|
||||
forward()
|
||||
.error (e) ->
|
||||
console.log ">> error", e
|
||||
forward()
|
||||
# # # #
|
||||
.error () ->
|
||||
$scope.pdf.logEntries = []
|
||||
$scope.pdf.rawLog = ""
|
||||
|
@ -127,7 +148,7 @@ define [
|
|||
$scope.recompile = (options = {}) ->
|
||||
return if $scope.pdf.compiling
|
||||
$scope.pdf.compiling = true
|
||||
|
||||
|
||||
ide.$scope.$broadcast("flush-changes")
|
||||
|
||||
options.rootDocOverride_id = getRootDocOverride_id()
|
||||
|
@ -140,7 +161,7 @@ define [
|
|||
.error () ->
|
||||
$scope.pdf.compiling = false
|
||||
$scope.pdf.error = true
|
||||
|
||||
|
||||
# This needs to be public.
|
||||
ide.$scope.recompile = $scope.recompile
|
||||
|
||||
|
@ -177,17 +198,17 @@ define [
|
|||
.then (data) ->
|
||||
{doc, line} = data
|
||||
ide.editorManager.openDoc(doc, gotoLine: line)
|
||||
|
||||
|
||||
$scope.switchToFlatLayout = () ->
|
||||
$scope.ui.pdfLayout = 'flat'
|
||||
$scope.ui.view = 'pdf'
|
||||
ide.localStorage "pdf.layout", "flat"
|
||||
|
||||
|
||||
$scope.switchToSideBySideLayout = () ->
|
||||
$scope.ui.pdfLayout = 'sideBySide'
|
||||
$scope.ui.view = 'editor'
|
||||
localStorage "pdf.layout", "split"
|
||||
|
||||
|
||||
if pdfLayout = localStorage("pdf.layout")
|
||||
$scope.switchToSideBySideLayout() if pdfLayout == "split"
|
||||
$scope.switchToFlatLayout() if pdfLayout == "flat"
|
||||
|
@ -216,7 +237,7 @@ define [
|
|||
if !path?
|
||||
deferred.reject()
|
||||
return deferred.promise
|
||||
|
||||
|
||||
# If the root file is folder/main.tex, then synctex sees the
|
||||
# path as folder/./main.tex
|
||||
rootDocDirname = ide.fileTreeManager.getRootDocDirname()
|
||||
|
@ -226,7 +247,7 @@ define [
|
|||
{row, column} = cursorPosition
|
||||
|
||||
$http({
|
||||
url: "/project/#{ide.project_id}/sync/code",
|
||||
url: "/project/#{ide.project_id}/sync/code",
|
||||
method: "GET",
|
||||
params: {
|
||||
file: path
|
||||
|
@ -253,7 +274,7 @@ define [
|
|||
position.offset.top = position.offset.top + 80
|
||||
|
||||
$http({
|
||||
url: "/project/#{ide.project_id}/sync/pdf",
|
||||
url: "/project/#{ide.project_id}/sync/pdf",
|
||||
method: "GET",
|
||||
params: {
|
||||
page: position.page + 1
|
||||
|
@ -316,4 +337,4 @@ define [
|
|||
|
||||
$scope.cancel = () ->
|
||||
$modalInstance.dismiss('cancel')
|
||||
]
|
||||
]
|
||||
|
|
56
services/web/public/js/libs/biber-log-parser.js
Normal file
56
services/web/public/js/libs/biber-log-parser.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Generated by CoffeeScript 1.10.0
|
||||
define(function() {
|
||||
var BiberLogParser, LINE_SPLITTER_REGEX, MESSAGE_LEVELS;
|
||||
LINE_SPLITTER_REGEX = /^\[(\d+)].*>\s(INFO|WARN|ERROR)\s-\s(.*)$/;
|
||||
MESSAGE_LEVELS = {
|
||||
"INFO": "info",
|
||||
"WARN": "warning",
|
||||
"ERROR": "error"
|
||||
};
|
||||
BiberLogParser = function(text, options) {
|
||||
if (typeof text !== 'string') {
|
||||
throw new Error("BiberLogParser Error: text parameter must be a string");
|
||||
}
|
||||
this.text = text.replace(/(\r\n)|\r/g, '\n');
|
||||
this.options = options;
|
||||
this.lines = text.split('\n');
|
||||
};
|
||||
(function() {
|
||||
return this.parse = function() {
|
||||
var result;
|
||||
result = {
|
||||
all: [],
|
||||
errors: [],
|
||||
warnings: [],
|
||||
files: [],
|
||||
typesetting: []
|
||||
};
|
||||
this.lines.forEach(function(line) {
|
||||
var fullLine, lineNumber, match, message, messageType, newEntry;
|
||||
match = line.match(LINE_SPLITTER_REGEX);
|
||||
if (match) {
|
||||
fullLine = match[0], lineNumber = match[1], messageType = match[2], message = match[3];
|
||||
newEntry = {
|
||||
file: null,
|
||||
level: MESSAGE_LEVELS[messageType] || "INFO",
|
||||
message: message,
|
||||
line: null,
|
||||
raw: fullLine
|
||||
};
|
||||
result.all.push(newEntry);
|
||||
switch (newEntry.level) {
|
||||
case 'error':
|
||||
return result.errors.push(newEntry);
|
||||
case 'warning':
|
||||
return result.warnings.push(newEntry);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
};
|
||||
}).call(BiberLogParser.prototype);
|
||||
BiberLogParser.parse = function(text, options) {
|
||||
return new BiberLogParser(text, options).parse();
|
||||
};
|
||||
return BiberLogParser;
|
||||
});
|
Loading…
Add table
Reference in a new issue