Ver código fonte

add menu option for checking with chktex

Brian Gough 10 anos atrás
pai
commit
ef85f1014c

+ 7 - 1
services/web/app/views/project/editor/pdf.jade

@@ -36,6 +36,11 @@ div.full-size.pdf(ng-controller="PdfController")
 						i.fa.fa-fw(ng-class="{'fa-check': draft}")
 						|  #{translate("fast")} 
 						span.subdued [draft]
+				li.dropdown-header #{translate("file_checks")}
+				li
+					a(href, ng-click="recompile({check:true})")
+						i.fa.fa-fw()
+						|  #{translate("syntax check")}
 		a(
 			href
 			ng-click="stop()"
@@ -115,7 +120,8 @@ div.full-size.pdf(ng-controller="PdfController")
 					|  
 					span(ng-show="entry.file") {{ entry.file }}
 					span(ng-show="entry.line") , line {{ entry.line }}
-				p.entry-message(ng-show="entry.message") {{ entry.message }}
+				p.entry-message(ng-show="entry.message")
+					{{ entry.type }} {{ entry.message }}
 				.card.card-hint(
 					ng-if="entry.humanReadableHint"
 					stop-propagation="click"

+ 63 - 19
services/web/public/coffee/ide/pdf/controllers/PdfController.coffee

@@ -92,6 +92,9 @@ define [
 
 		parseCompileResponse = (response) ->		
 
+			# keep last url
+			last_pdf_url = $scope.pdf.url
+
 			# Reset everything
 			$scope.pdf.error      = false
 			$scope.pdf.timedout   = false
@@ -121,11 +124,17 @@ define [
 			if response.status == "timedout"
 				$scope.pdf.view = 'errors'
 				$scope.pdf.timedout = true
-				fetchLogs(fileByPath['output.log'], fileByPath['output.blg'])
+				fetchLogs(fileByPath)
 			else if response.status == "terminated"
 				$scope.pdf.view = 'errors'
 				$scope.pdf.compileTerminated = true
-				fetchLogs(fileByPath['output.log'], fileByPath['output.blg'])
+				fetchLogs(fileByPath)
+			else if response.status == "exited"
+				$scope.pdf.view = 'pdf'
+				$scope.pdf.compileExited = true
+				$scope.pdf.url = last_pdf_url
+				$scope.shouldShowLogs = true
+				fetchLogs(fileByPath)
 			else if response.status == "autocompile-backoff"
 				$scope.pdf.view = 'uncompiled'
 			else if response.status == "project-too-large"
@@ -135,7 +144,7 @@ define [
 				$scope.pdf.view = 'errors'
 				$scope.pdf.failure = true
 				$scope.shouldShowLogs = true
-				fetchLogs(fileByPath['output.log'], fileByPath['output.blg'])
+				fetchLogs(fileByPath)
 			else if response.status == 'clsi-maintenance'
 				$scope.pdf.view = 'errors'
 				$scope.pdf.clsiMaintenance = true
@@ -166,7 +175,7 @@ define [
 				qs.popupDownload = true
 				$scope.pdf.downloadUrl = "/project/#{$scope.project_id}/output/output.pdf" + createQueryString(qs)
 
-				fetchLogs(fileByPath['output.log'], fileByPath['output.blg'])
+				fetchLogs(fileByPath)
 
 			IGNORE_FILES = ["output.fls", "output.fdb_latexmk"]
 			$scope.pdf.outputFiles = []
@@ -187,7 +196,11 @@ define [
 					}
 
 
-		fetchLogs = (logFile, blgFile) ->
+		fetchLogs = (fileByPath) ->
+
+			logFile = fileByPath['output.log'];
+			blgFile = fileByPath['output.blg'];
+			chktexFile = fileByPath['output.chktex'];
 
 			getFile = (name, file) ->
 				opts =
@@ -214,6 +227,8 @@ define [
 
 			accumulateResults = (newEntries) ->
 				for key in ['all', 'errors', 'warnings']
+					if newEntries.type?
+						entry.type = newEntries.type for entry in newEntries[key]
 					logEntries[key] = logEntries[key].concat newEntries[key]
 
 			# use the parsers for each file type
@@ -223,10 +238,23 @@ define [
 				all = [].concat errors, warnings, typesetting
 				accumulateResults {all, errors, warnings}
 
+			processChkTex = (log) ->
+				errors = []
+				warnings = []
+				for line in log.split("\n")
+					if m = line.match /^(\S+):(\d+):(\d+): (Error|Warning): (.*)/
+						result = { file:m[1], line:m[2], column:m[3], level:m[4].toLowerCase(), message: "#{m[4]}: #{m[5]}"}
+						if result.level is 'error'
+							errors.push result
+						else
+							warnings.push result
+				all = [].concat errors, warnings
+				accumulateResults {type: "ChkTeX", all, errors, warnings}
+
 			processBiber = (log) ->
 				{errors, warnings} = BibLogParser.parse(log, {})
 				all = [].concat errors, warnings
-				accumulateResults {all, errors, warnings}
+				accumulateResults {type: "BibTeX", all, errors, warnings}
 
 			# output the results
 			handleError = () ->
@@ -249,19 +277,35 @@ define [
 							}
 
 			# retrieve the logfile and process it
-			response = getFile('output.log', logFile)
-				.success processLog
-				.error handleError
-
-			if blgFile?	# retrieve the blg file if present
-				response.success () ->
-					getFile('output.blg', blgFile)
-						# ignore errors in biber file
-						.success processBiber
-						# display the combined result
-						.then annotateFiles
-			else # otherwise just display the result
-				response.success annotateFiles
+			if logFile?
+				response = getFile('output.log', logFile)
+					.then	(response) -> processLog(response.data)
+
+				if blgFile?	# retrieve the blg file if present
+					response = response.then () ->
+						getFile('output.blg', blgFile)
+							.then(
+								(response) -> processBiber(response.data),
+								() ->	true # ignore errors in biber file
+							)
+
+			if response?
+				response.catch handleError
+			else
+				handleError()
+
+			if chktexFile?
+				getChkTex = () ->
+					getFile('output.chktex', chktexFile)
+						.then	(response) -> processChkTex(response.data)
+				# always retrieve the chktex file if present
+				if response?
+					response = response.then getChkTex, getChkTex
+				else
+					response = getChkTex()
+
+			# display the combined result
+			response.finally annotateFiles
 
 		getRootDocOverride_id = () ->
 			doc = ide.editorManager.getCurrentDocValue()