@@ -3,17 +3,19 @@ import * as path from 'path';
33import * as fs from 'fs' ;
44import { createHash } from 'crypto' ;
55import { spawn } from 'child_process' ;
6- import { getJavaPath } from '../tla2tools' ;
6+ import { getJavaPath , TLA_CMODS_LIB_NAME } from '../tla2tools' ;
77import { moduleSearchPaths } from '../paths' ;
88
99const CFG_FORMATTER_ENABLED = 'tlaplus.formatter.enabled' ;
1010const 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 */
1820function makeFormatterTlaLibraryOpt ( documentDir ?: string ) : string {
1921 const allPaths : string [ ] = [ ] ;
@@ -47,6 +49,7 @@ function generateHash(input: string, algorithm: string): string {
4749
4850export 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
0 commit comments