Skip to content

Commit

Permalink
Resolve #4338 Control showing over/underfull warning seperately by `m…
Browse files Browse the repository at this point in the history
…essage.badbox.show`
  • Loading branch information
James-Yu committed Aug 18, 2024
1 parent b703c65 commit b696954
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 38 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2044,8 +2044,9 @@
},
"latex-workshop.message.badbox.show": {
"scope": "window",
"type": "boolean",
"default": true,
"type": "string",
"enum": ["both", "overfull", "underfull", "none"],
"default": "both",
"markdownDescription": "Show badbox information in the problems panel."
},
"latex-workshop.message.biberlog.exclude": {
Expand Down
86 changes: 50 additions & 36 deletions src/parse/parser/latexlog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ import { type IParser, type LogEntry, showCompilerDiagnostics } from './parserut
const logger = lw.log('Parser', 'TexLog')

const latexError = /^(?:(.*):(\d+):|!)(?: (.+) Error:)? (.+?)$/
const latexBox = /^((?:Over|Under)full \\[vh]box \([^)]*\)) in paragraph at lines (\d+)--(\d+)$/
const latexBoxAlt = /^((?:Over|Under)full \\[vh]box \([^)]*\)) detected at line (\d+)$/
const latexBoxOutput = /^((?:Over|Under)full \\[vh]box \([^)]*\)) has occurred while \\output is active(?: \[(\d+)\])?/
const latexOverfullBox = /^(Overfull \\[vh]box \([^)]*\)) in paragraph at lines (\d+)--(\d+)$/
const latexOverfullBoxAlt = /^(Overfull \\[vh]box \([^)]*\)) detected at line (\d+)$/
const latexOverfullBoxOutput = /^(Overfull \\[vh]box \([^)]*\)) has occurred while \\output is active(?: \[(\d+)\])?/
const latexUnderfullBox = /^(Underfull \\[vh]box \([^)]*\)) in paragraph at lines (\d+)--(\d+)$/
const latexUnderfullBoxAlt = /^(Underfull \\[vh]box \([^)]*\)) detected at line (\d+)$/
const latexUnderfullBoxOutput = /^(Underfull \\[vh]box \([^)]*\)) has occurred while \\output is active(?: \[(\d+)\])?/
const latexWarn = /^((?:(?:Class|Package|Module) \S*)|LaTeX(?: \S*)?|LaTeX3) (Warning|Info):\s+(.*?)(?: on(?: input)? line (\d+))?(\.|\?|)$/
const latexPackageWarningExtraLines = /^\((.*)\)\s+(.*?)(?: +on input line (\d+))?(\.)?$/
const latexMissChar = /^\s*(Missing character:.*?!)/
Expand Down Expand Up @@ -141,41 +144,10 @@ function parseLine(line: string, state: ParserState) {
if (parseUndefinedReference(line, filename, state)) {
return
}
let result = line.match(latexBox)
if (!result) {
result = line.match(latexBoxAlt)
}
if (result && configuration.get('message.badbox.show')) {
if (state.currentResult.type !== '') {
buildLog.push(state.currentResult)
}
state.currentResult = {
type: 'typesetting',
file: filename,
line: parseInt(result[2], 10),
text: result[1]
}
state.searchEmptyLine = false
state.insideBoxWarn = true
parseLine(line.substring(result[0].length), state)
if (parseBadBox(line, filename, state, configuration.get('message.badbox.show'))) {
return
}
result = line.match(latexBoxOutput)
if (result && configuration.get('message.badbox.show')) {
if (state.currentResult.type !== '') {
buildLog.push(state.currentResult)
}
state.currentResult = {
type: 'typesetting',
file: filename,
line: 1,
text: result[2] ? `${result[1]} in page ${result[2]}` : result[1]
}
state.searchEmptyLine = false
parseLine(line.substring(result[0].length), state)
return
}
result = line.match(latexMissChar)
let result = line.match(latexMissChar)
if (result) {
if (state.currentResult.type !== '') {
buildLog.push(state.currentResult)
Expand Down Expand Up @@ -264,6 +236,48 @@ function parseUndefinedReference(line: string, filename: string, state: ParserSt
return true
}

function parseBadBox(line: string, filename: string, state: ParserState, type?: 'both' | 'overfull' | 'underfull' | 'none'): boolean {
if (type === undefined || type === 'none') {
return false
}
const regexs = []
if (['both', 'overfull'].includes(type)) {
regexs.push(latexOverfullBox, latexOverfullBoxAlt, latexOverfullBoxOutput)
}
if (['both', 'underfull'].includes(type)) {
regexs.push(latexUnderfullBox, latexUnderfullBoxAlt, latexUnderfullBoxOutput)
}
for (const regex of regexs) {
const result = line.match(regex)
if (result === null) {
continue
}
if (state.currentResult.type !== '') {
buildLog.push(state.currentResult)
}
if ([latexOverfullBoxOutput, latexUnderfullBoxOutput].includes(regex)) {
state.currentResult = {
type: 'typesetting',
file: filename,
line: 1,
text: result[2] ? `${result[1]} in page ${result[2]}` : result[1]
}
} else {
state.currentResult = {
type: 'typesetting',
file: filename,
line: parseInt(result[2], 10),
text: result[1]
}
state.insideBoxWarn = true
}
state.searchEmptyLine = false
parseLine(line.substring(result[0].length), state)
return true
}
return false
}

function parseLaTeXFileStack(line: string, fileStack: string[], nested: number): number {
const result = line.match(/(\(|\))/)
if (result && result.index !== undefined && result.index > -1) {
Expand Down

0 comments on commit b696954

Please sign in to comment.