1
+ import * as path from 'path' ;
1
2
import * as vscode from 'vscode' ;
2
3
import * as nls from 'vscode-nls' ;
3
4
import * as getPort from 'get-port' ;
@@ -361,9 +362,9 @@ export function isWorkspaceFolder(value: any): value is vscode.WorkspaceFolder {
361
362
export function getGradleTasksServerCommand ( ) : string {
362
363
const platform = process . platform ;
363
364
if ( platform === 'win32' ) {
364
- return '.\\ tasks-server.bat' ;
365
+ return 'tasks-server.bat' ;
365
366
} else if ( platform === 'linux' || platform === 'darwin' ) {
366
- return './ tasks-server' ;
367
+ return 'tasks-server' ;
367
368
} else {
368
369
throw new Error ( 'Unsupported platform' ) ;
369
370
}
@@ -553,12 +554,26 @@ export function cloneTask(
553
554
554
555
export function buildGradleServerTask (
555
556
taskName : string ,
556
- cwd : string ,
557
+ executableDir : string ,
557
558
args : string [ ] = [ ]
558
- ) : vscode . Task {
559
- const cmd = `"${ getGradleTasksServerCommand ( ) } "` ;
559
+ ) : vscode . Task | undefined {
560
+ // This means we can only support relative paths for 1 workspace folder
561
+ // and breaks multi-root workspaces. What to do?
562
+ const workspaceFolders = vscode . workspace . workspaceFolders ;
563
+ if ( ! workspaceFolders ) {
564
+ return ;
565
+ }
566
+
567
+ // Quotes are needed to prevent vscode from "normalising" paths
568
+ // (eg back-slashes are removed if using git bash on Windows)
569
+ const cmd = `"${ path . join ( executableDir , getGradleTasksServerCommand ( ) ) } "` ;
570
+
571
+ // cwd is set to the workspace root to support relative paths
572
+ const cwd = workspaceFolders [ 0 ] . uri . fsPath ;
573
+
560
574
logger . debug ( `Gradle Tasks Server dir: ${ cwd } ` ) ;
561
575
logger . debug ( `Gradle Tasks Server cmd: ${ cmd } ${ args } ` ) ;
576
+
562
577
const taskType = 'gradle' ;
563
578
const definition = {
564
579
type : taskType ,
@@ -577,12 +592,16 @@ export function buildGradleServerTask(
577
592
taskType ,
578
593
new vscode . ShellExecution ( cmd , args , { cwd, env } )
579
594
) ;
580
- // task.isBackground = true; // this hides errors on task start
595
+
596
+ // Allow the user to see stdout/stderr messages for this task in the terminal panel
597
+ task . isBackground = false ;
598
+
581
599
task . source = taskType ;
582
600
task . presentationOptions = {
583
601
reveal : vscode . TaskRevealKind . Never ,
584
602
focus : false ,
585
- echo : true ,
603
+ // The command is an absolute path and not very useful to echo
604
+ echo : false ,
586
605
clear : false ,
587
606
panel : vscode . TaskPanelKind . Shared ,
588
607
} ;
0 commit comments