Skip to content

Commit

Permalink
PDF Generation: feature parity with the toolbox
Browse files Browse the repository at this point in the history
Signed-off-by: Federico Ponzi <me@fponzi.me>
  • Loading branch information
FedericoPonzi committed Nov 1, 2024
1 parent 220a265 commit 77dd935
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 1.7.0

### Enhancements
* Generate PDF feature matching the toolbox by adding missing settings.


## 1.5.4 &ndash; 21st March, 2021

### Enhancements
Expand Down
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,31 @@
"maxLength": 1000,
"description": "Command to produce PDFs from .tex files."
},
"tlaplus.pdf.commentsShade": {
"default": true,
"type": "boolean",
"scope": "application",
"description": "If enabled, comments will have a gray background."
},
"tlaplus.pdf.commentsShadeColor": {
"default": 0.85,
"type": "number",
"scope": "application",
"maxLength": 10,
"description": "If comments are shaded in gray, this config changes the darkness of the shading. This must be a number between 0.0 (completely black) and 1.0 (no shading)."
},
"tlaplus.pdf.numberLines": {
"default": false,
"type": "boolean",
"scope": "application",
"description": "Show line numbers in PDFs."
},
"tlaplus.pdf.noPcalShade": {
"default": false,
"type": "boolean",
"scope": "application",
"description": "Causes a PlusCal algorithm (which appear in a comment) not to be shaded. (The algorithm's comments will be shaded.)"
},
"tlaplus.tlaps.enabled": {
"type": "boolean",
"default": false,
Expand Down Expand Up @@ -504,6 +529,7 @@
"vscode:prepublish": "npm run compile -- --production",
"compile": "node ./esbuild.js",
"lint": "eslint --ext .ts,.tsx src/ tests/",
"lint:fix": "eslint --fix --ext .ts,.tsx src/ tests/",
"watch": "npm run compile -- --watch",
"pretest": "tsc -p ./",
"test": "node ./out/tests/runTest.js",
Expand Down
35 changes: 34 additions & 1 deletion src/tla2tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ const CFG_JAVA_OPTIONS = 'tlaplus.java.options';
const CFG_TLC_OPTIONS = 'tlaplus.tlc.modelChecker.options';
const CFG_PLUSCAL_OPTIONS = 'tlaplus.pluscal.options';
const CFG_TLC_OPTIONS_PROMPT = 'tlaplus.tlc.modelChecker.optionsPrompt';
const CFG_TLA_PDF_NUMBER_LINES = 'tlaplus.pdf.numberLines';
const CFG_TLA_PDF_NO_PCAL_SHADE = 'tlaplus.pdf.noPcalShade';
const CFG_TLA_PDF_COMMENTS_SHADE = 'tlaplus.pdf.commentsShade';
const CFG_TLA_PDF_COMMENTS_SHADE_COLOR = 'tlaplus.pdf.commentsShadeColor';

const VAR_TLC_SPEC_NAME = /\$\{specName\}/g;
const VAR_TLC_MODEL_NAME = /\$\{modelName\}/g;
Expand Down Expand Up @@ -101,11 +105,38 @@ export async function runSany(tlaFilePath: string): Promise<ToolProcessInfo> {
);
}

function buildTexOptions(tlaFilePath: string, shadeComments: boolean, commentColor: number, numberLines: boolean, noPcalShade: boolean): string[] {

Check warning on line 108 in src/tla2tools.ts

View workflow job for this annotation

GitHub Actions / build (macOS-latest)

This line has a length of 147. Maximum allowed is 120

Check warning on line 108 in src/tla2tools.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-20.04)

This line has a length of 147. Maximum allowed is 120

Check warning on line 108 in src/tla2tools.ts

View workflow job for this annotation

GitHub Actions / build (windows-latest)

This line has a length of 147. Maximum allowed is 120
const toolArgs = [path.basename(tlaFilePath)];

if (shadeComments) {
toolArgs.unshift('-nops',
'-shade',
'-grayLevel',
commentColor.toString());
}

if (numberLines) {
toolArgs.unshift('-number');
}

if (noPcalShade) {
toolArgs.unshift('-noPcalShade');
}
return toolArgs;
}

export async function runTex(tlaFilePath: string): Promise<ToolProcessInfo> {
const shadeComments = vscode.workspace.getConfiguration().get<boolean>(CFG_TLA_PDF_COMMENTS_SHADE, true);
const commentColor = vscode.workspace.getConfiguration().get<number>(CFG_TLA_PDF_COMMENTS_SHADE_COLOR, 0.85);
const numberLines = vscode.workspace.getConfiguration().get<boolean>(CFG_TLA_PDF_NUMBER_LINES, false);
const noPcalShade = vscode.workspace.getConfiguration().get<boolean>(CFG_TLA_PDF_NO_PCAL_SHADE, false);

const options = buildTexOptions(tlaFilePath, shadeComments, commentColor, numberLines, noPcalShade);

return runTool(
TlaTool.TEX,
tlaFilePath,
[ path.basename(tlaFilePath) ],
options,
[]
);
}
Expand Down Expand Up @@ -148,6 +179,8 @@ async function runTool(
toolOptions: string[],
javaOptions: string[]
): Promise<ToolProcessInfo> {
// log the arugments:
//console.log(toolName + ': ' + filePath + ' ' + toolOptions.join(' ') + ' ' + javaOptions.join(' '));
const javaPath = await obtainJavaPath();
// TODO: Merge cfgOptions with javaOptions to avoid complete overrides.
const cfgOptions = getConfigOptions(CFG_JAVA_OPTIONS);
Expand Down
3 changes: 2 additions & 1 deletion src/webview/checkResultView/headerSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export const HeaderSection = React.memo(({checkResult}: HeaderSectionI) => {
<span hidden={checkResult.state !== 'R'}>
(<VSCodeLink onClick={vscode.stopProcess} href="#"> stop </VSCodeLink>)
</span>
<span hidden={ checkResult.statusDetails === undefined || checkResult.statusDetails === null}>: {' ' + checkResult.statusDetails} </span>
<span hidden={ checkResult.statusDetails === undefined
|| checkResult.statusDetails === null}>: {' ' + checkResult.statusDetails} </span>
</div>

<div className="timeInfo"> Start: {checkResult.startDateTimeStr}, end: {checkResult.endDateTimeStr} </div>
Expand Down

0 comments on commit 77dd935

Please sign in to comment.