1+ import * as path from 'path' ;
12import * as vscode from 'vscode' ;
23import * as nls from 'vscode-nls' ;
34import * as getPort from 'get-port' ;
@@ -361,9 +362,9 @@ export function isWorkspaceFolder(value: any): value is vscode.WorkspaceFolder {
361362export function getGradleTasksServerCommand ( ) : string {
362363 const platform = process . platform ;
363364 if ( platform === 'win32' ) {
364- return '.\\ tasks-server.bat' ;
365+ return 'tasks-server.bat' ;
365366 } else if ( platform === 'linux' || platform === 'darwin' ) {
366- return './ tasks-server' ;
367+ return 'tasks-server' ;
367368 } else {
368369 throw new Error ( 'Unsupported platform' ) ;
369370 }
@@ -553,12 +554,26 @@ export function cloneTask(
553554
554555export function buildGradleServerTask (
555556 taskName : string ,
556- cwd : string ,
557+ executableDir : string ,
557558 args : string [ ] = [ ]
558- ) : vscode . Task {
559- const cmd = `"${ getGradleTasksServerCommand ( ) } "` ;
559+ ) : vscode . Task | undefined {
560+ const workspaceFolders = vscode . workspace . workspaceFolders ;
561+ if ( ! workspaceFolders ) {
562+ return ;
563+ }
564+
565+ // Quotes are needed to prevent vscode from "normalising" paths
566+ // (eg back-slashes are removed if using git bash on Windows)
567+ const cmd = `"${ path . join ( executableDir , getGradleTasksServerCommand ( ) ) } "` ;
568+
569+ // cwd is set to the workspace root to support relative paths
570+ // This means we can only support relative paths for 1 workspace folder
571+ // and breaks multi-root workspaces. What to do?
572+ const cwd = workspaceFolders [ 0 ] . uri . fsPath ;
573+
560574 logger . debug ( `Gradle Tasks Server dir: ${ cwd } ` ) ;
561575 logger . debug ( `Gradle Tasks Server cmd: ${ cmd } ${ args } ` ) ;
576+
562577 const taskType = 'gradle' ;
563578 const definition = {
564579 type : taskType ,
@@ -577,12 +592,16 @@ export function buildGradleServerTask(
577592 taskType ,
578593 new vscode . ShellExecution ( cmd , args , { cwd, env } )
579594 ) ;
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+
581599 task . source = taskType ;
582600 task . presentationOptions = {
583601 reveal : vscode . TaskRevealKind . Never ,
584602 focus : false ,
585- echo : true ,
603+ // The command is an absolute path and not very useful to echo
604+ echo : false ,
586605 clear : false ,
587606 panel : vscode . TaskPanelKind . Shared ,
588607 } ;
0 commit comments