Skip to content

Commit 75a6466

Browse files
Fix formatter failing on specs that EXTENDS CommunityModules (#496)
Switch from -jar to -cp so CommunityModules-deps.jar is on the classpath. Signed-off-by: Federico Ponzi <me@fponzi.me>
1 parent 0c78f9f commit 75a6466

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/formatters/tlaFormatter.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ import * as path from 'path';
33
import * as fs from 'fs';
44
import { createHash } from 'crypto';
55
import { spawn } from 'child_process';
6-
import { getJavaPath } from '../tla2tools';
6+
import { getJavaPath, TLA_CMODS_LIB_NAME } from '../tla2tools';
77
import { moduleSearchPaths } from '../paths';
88

99
const CFG_FORMATTER_ENABLED = 'tlaplus.formatter.enabled';
1010
const FORMATTER_JAR_NAME = 'tlaplus-formatter.jar';
11+
const FORMATTER_MAIN_CLASS = 'me.fponzi.tlaplusformatter.Main';
1112

1213
/**
1314
* Builds `-DTLA-Library=...` with all module search paths (user-configured,
14-
* TLC standard/community modules, TLAPS) so the formatter's SANY can resolve
15-
* any EXTENDS'd modules. Paths using the `jarfile:` scheme are dropped because
16-
* Java's SANY resolves those from its own classpath.
15+
* TLAPS, etc.) so the formatter's SANY can resolve any EXTENDS'd modules.
16+
* Paths using the `jarfile:` scheme are dropped because those modules live
17+
* inside JARs that are placed on the classpath instead (see the `-cp` args
18+
* in registerDocumentFormatter).
1719
*/
1820
function makeFormatterTlaLibraryOpt(documentDir?: string): string {
1921
const allPaths: string[] = [];
@@ -47,6 +49,7 @@ function generateHash(input: string, algorithm: string): string {
4749

4850
export function registerDocumentFormatter(context: vscode.ExtensionContext): void {
4951
const formatterJarPath = path.join(context.extensionPath, 'tools', FORMATTER_JAR_NAME);
52+
const cmodsJarPath = path.join(context.extensionPath, 'tools', TLA_CMODS_LIB_NAME);
5053

5154
context.subscriptions.push(
5255
vscode.languages.registerDocumentFormattingEditProvider('tlaplus', {
@@ -97,9 +100,11 @@ export function registerDocumentFormatter(context: vscode.ExtensionContext): voi
97100

98101
const javaPath = getJavaPath();
99102
const stderrChunks: string[] = [];
103+
const classPath = formatterJarPath + path.delimiter + cmodsJarPath;
100104
const spawnArgs = [
101105
makeFormatterTlaLibraryOpt(documentDir),
102-
'-jar', formatterJarPath,
106+
'-cp', classPath,
107+
FORMATTER_MAIN_CLASS,
103108
'-v', 'ERROR',
104109
tempInputPath,
105110
tempOutputPath

src/tla2tools.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const NO_ERROR = 0;
3131
const MIN_TLA_ERROR = 10; // Exit codes not related to tooling start from this number
3232
const LOWEST_JAVA_VERSION = 8;
3333
const DEFAULT_GC_OPTION = '-XX:+UseParallelGC';
34-
const TLA_CMODS_LIB_NAME = 'CommunityModules-deps.jar';
34+
export const TLA_CMODS_LIB_NAME = 'CommunityModules-deps.jar';
3535
const TLA_TOOLS_LIB_NAME = 'tla2tools.jar';
3636
const TLA_TOOLS_LIB_NAME_END_UNIX = '/' + TLA_TOOLS_LIB_NAME;
3737
const TLA_TOOLS_LIB_NAME_END_WIN = '\\' + TLA_TOOLS_LIB_NAME;

0 commit comments

Comments
 (0)