@@ -7,6 +7,7 @@ import * as yaml from 'yaml';
77import { cwd } from 'process' ;
88import { Mutex } from 'async-mutex' ;
99import { spawnProblemsTool } from './problems' ;
10+ import { homedir } from 'os' ;
1011
1112export const crystalOutputChannel = window . createOutputChannel ( "Crystal" , "log" )
1213
@@ -27,6 +28,7 @@ export const compiler_mutex: Mutex = new Mutex();
2728function execWrapper (
2829 command : string ,
2930 cwd : string ,
31+ target : string | null ,
3032 callback ?: (
3133 error : ( ExecException & { stdout : string ; stderr : string } ) | { } ,
3234 stdout : string ,
@@ -40,6 +42,15 @@ function execWrapper(
4042 env [ 'GC_DONT_GC' ] = '1'
4143 }
4244
45+ // Don't want to interfere with the global cache
46+ if ( target ) {
47+ const cache_dir = env [ 'XDG_CACHE_HOME' ] ||
48+ ( homedir ( ) ? path . join ( homedir ( ) , '.cache' ) : undefined ) ||
49+ path . join ( cwd , '.crystal' ) ;
50+
51+ env [ 'CRYSTAL_CACHE_DIR' ] = path . join ( cache_dir , target )
52+ }
53+
4354 const response = exec ( command , { 'cwd' : cwd , env } , ( err , stdout , stderr ) => {
4455 if ( err ) {
4556 callback ( { ...err , stderr, stdout } , stdout , stderr ) ;
@@ -83,7 +94,7 @@ export async function getCompilerPath(): Promise<string> {
8394 const command =
8495 ( process . platform === 'win32' ? 'where' : 'which' ) + ' crystal' ;
8596
86- return ( await execAsync ( command , process . cwd ( ) ) ) . trim ( ) ;
97+ return ( await execAsync ( command , process . cwd ( ) , null ) ) . trim ( ) ;
8798}
8899
89100/**
@@ -103,7 +114,7 @@ export async function getShardsPath(): Promise<string> {
103114 const command =
104115 ( process . platform === 'win32' ? 'where' : 'which' ) + ' shards' ;
105116
106- return ( await execAsync ( command , process . cwd ( ) ) ) . trim ( ) ;
117+ return ( await execAsync ( command , process . cwd ( ) , null ) ) . trim ( ) ;
107118}
108119
109120/**
@@ -266,7 +277,7 @@ export async function getShardMainPath(document: TextDocument): Promise<string>
266277 */
267278export async function getCrystalLibPath ( ) : Promise < string > {
268279 const compiler = await getCompilerPath ( ) ;
269- const libpath = await execAsync ( `${ compiler } env CRYSTAL_PATH` , process . cwd ( ) ) ;
280+ const libpath = await execAsync ( `${ compiler } env CRYSTAL_PATH` , process . cwd ( ) , null ) ;
270281
271282 return libpath . replace ( / ^ l i b [: ; ] | (?: \r ) ? \n / g, '' ) ;
272283}
@@ -317,7 +328,7 @@ export interface SemVer {
317328export async function getCrystalVersion ( ) : Promise < SemVer > {
318329 const compiler = await getCompilerPath ( ) ;
319330 const cmd = `${ shellEscape ( compiler ) } --version`
320- const response = await execAsync ( cmd , cwd ( ) )
331+ const response = await execAsync ( cmd , cwd ( ) , null )
321332
322333 const match = response . match ( / C r y s t a l ( \d + ) \. ( \d + ) \. ( \d + ) / )
323334
@@ -501,7 +512,7 @@ export async function getShardTargetForFile(document: TextDocument): Promise<{ r
501512 crystalOutputChannel . appendLine ( `[Dependencies] ${ space . name } $ ${ cmd } ` )
502513 const targetDocument = await workspace . openTextDocument ( Uri . parse ( targetPath ) )
503514
504- const result = await execAsync ( cmd , space . uri . fsPath )
515+ const result = await execAsync ( cmd , space . uri . fsPath , null )
505516 . then ( ( resp ) => {
506517 return { response : resp , error : undefined } ;
507518 } )
0 commit comments