提交 ff22654e 编写于 作者: D Dirk Baeumer

Merge branch 'dbaeumer/3849'

{
"name": "tasks",
"description": "Extension to add support for tasks.json files",
"displayName": "Tasks.json support for VSCode",
"version": "0.10.1",
"author": "Microsoft Corporation",
"license": "MIT",
"publisher": "vscode",
"engines": {
"vscode": "*"
},
"dependencies": {
"vscode-nls": "^1.0.4"
},
"scripts": {
"vscode:prepublish": "node ../../node_modules/gulp/bin/gulp.js --gulpfile ../../build/gulpfile.extensions.js compile-extension:tasks ./src/tsconfig.json"
},
"activationEvents": [
"onLanguage:json"
],
"main": "./out/tasksMain",
"contributes": {
}
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as path from 'path';
import { env, languages, workspace, ExtensionContext, TextDocument, Position, CancellationToken, CompletionItem, CompletionItemKind, DocumentFilter } from 'vscode';
import * as nls from 'vscode-nls';
let localize = nls.config({ locale: env.language })();
export function activate(context: ExtensionContext): void {
// We can't use a pattern here since it disables the normal json code complete
// which we don't want. Do the filtering in the actual suggest
let selector: DocumentFilter = { language: 'json' };
let taskFileName = workspace.rootPath ? path.join(workspace.rootPath, '.vscode/tasks.json') : null;
let items = taskFileName ? createCompletionItems() : [];
languages.registerCompletionItemProvider(selector, {
provideCompletionItems: (document: TextDocument, position: Position, token: CancellationToken): CompletionItem[] => {
if (document.fileName === taskFileName) {
return items;
} else {
return [];
}
}
});
}
function createCompletionItems(): CompletionItem[] {
let result: CompletionItem[] = [];
let item: CompletionItem;
item = new CompletionItem('tsc - specific file');
item.kind = CompletionItemKind.Snippet;
item.detail = localize('tscFile','Use the tsc compiler on a specific file.');
item.insertText = [
'"version": "0.1.0",',
'"command": "tsc",',
'"isShellCommand": true,',
'"showOutput": "silent",',
'"args": ["{{file}}"],',
'"problemMatcher": "$tsc"'
].join('\n');
result.push(item);
item = new CompletionItem('tsc - tsconfig.json');
item.kind = CompletionItemKind.Snippet;
item.detail = localize('tscConfig', 'Use the tsc compiler with a tsconfig.json file.');
item.insertText = [
'"version": "0.1.0",',
'"command": "tsc",',
'"isShellCommand": true,',
'"showOutput": "silent",',
'"args": ["-p", "."],',
'"problemMatcher": "$tsc"'
].join('\n');
result.push(item);
item = new CompletionItem('tsc - watch');
item.kind = CompletionItemKind.Snippet;
item.detail = localize('tscWatch', 'Use the tsc compiler in watch mode.');
item.insertText = [
'"version": "0.1.0",',
'"command": "tsc",',
'"isShellCommand": true,',
'"showOutput": "silent",',
'"args": ["-w", "-p", "."],',
'"problemMatcher": "$tsc-watch"'
].join('\n');
result.push(item);
item = new CompletionItem('tsc - open file');
item.kind = CompletionItemKind.Snippet;
item.detail = localize('tscOpenFile', 'Use the tsc compiler on the currently opened file.');
item.insertText = [
'"version": "0.1.0",',
'"command": "tsc",',
'"isShellCommand": true,',
'"showOutput": "silent",',
'"args": ["${file}"],',
'"problemMatcher": {',
'\t"base": "$tsc",',
'\t"fileLocation": "absolute"',
'}'
].join('\n');
result.push(item);
item = new CompletionItem('dotnet build');
item.kind = CompletionItemKind.Snippet;
item.detail = localize('dotnet', 'Use dotnet build.');
item.insertText = [
'"version": "0.1.0",',
'"command": "dotnet build",',
'"showOutput": "always"'
].join('\n');
result.push(item);
item = new CompletionItem('msbuild');
item.kind = CompletionItemKind.Snippet;
item.detail = localize('msbuild', 'Use msbuild to compile your project.');
item.insertText = [
'"version": "0.1.0",',
'"command": "msbuild",',
'"args": [',
'\t// Ask msbuild to generate full paths for file names.',
'\t"/property:GenerateFullPaths=true"',
'],',
'"taskSelector": "/t:",',
'"showOutput": "silent",',
'"tasks": [',
'\t{',
'\t\t"taskName": "build",',
'\t\t// Show the output window only if unrecognized errors occur.',
'\t\t"showOutput": "silent",',
'\t\t// Use the standard MS compiler pattern to detect errors, warnings and infos',
'\t\t"problemMatcher": "$msCompile"',
'\t}',
']'
].join('\n');
result.push(item);
return result;
}
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer;
declare function clearTimeout(timeoutId: NodeJS.Timer): void;
declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer;
declare function clearInterval(intervalId: NodeJS.Timer): void;
declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any;
declare function clearImmediate(immediateId: any): void;
interface Console {
assert(test?: boolean, message?: string, ...optionalParams: any[]): void;
dir(value?: any, ...optionalParams: any[]): void;
error(message?: any, ...optionalParams: any[]): void;
info(message?: any, ...optionalParams: any[]): void;
log(message?: any, ...optionalParams: any[]): void;
time(timerName?: string): void;
timeEnd(timerName?: string): void;
trace(message?: any, ...optionalParams: any[]): void;
warn(message?: any, ...optionalParams: any[]): void;
}
declare var Console: {
prototype: Console;
new(): Console;
};
\ No newline at end of file
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
/// <reference path='../../../../src/vs/vscode.d.ts'/>
/// <reference path='../../../../src/typings/mocha.d.ts'/>
/// <reference path='../../../../extensions/node.d.ts'/>
/// <reference path='../../../../extensions/lib.core.d.ts'/>
\ No newline at end of file
{
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"noLib": true,
"sourceMap": true,
"outDir": "../out"
}
}
\ No newline at end of file
......@@ -13,7 +13,7 @@
"scripts": {
"test": "mocha",
"preinstall": "node build/npm/preinstall.js",
"postinstall": "npm --prefix extensions/vscode-api-tests/ install extensions/vscode-api-tests/ && npm --prefix extensions/json/ install extensions/json/ && npm --prefix extensions/typescript/ install extensions/typescript/ && npm --prefix extensions/php/ install extensions/php/ && npm --prefix extensions/tasks/ install extensions/tasks/",
"postinstall": "npm --prefix extensions/vscode-api-tests/ install extensions/vscode-api-tests/ && npm --prefix extensions/json/ install extensions/json/ && npm --prefix extensions/typescript/ install extensions/typescript/ && npm --prefix extensions/php/ install extensions/php/",
"watch": "gulp watch"
},
"dependencies": {
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as nls from 'vs/nls';
import { IPickOpenEntry } from 'vs/workbench/services/quickopen/common/quickOpenService';
export interface TaskEntry extends IPickOpenEntry {
autoDetect: boolean;
content: string;
}
const gulp: TaskEntry = {
id: 'gulp',
label: 'Gulp',
autoDetect: true,
description: nls.localize('gulp', 'Creates a tasks.json file for gulp. If a gulp file is present tasks will be auto-detected.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "gulp",',
'\t"isShellCommand": true,',
'\t"args": ["--no-color"],',
'\t"showOutput": "silent"',
'}'
].join('\n')
};
const jake: TaskEntry = {
id: 'jake',
label: 'Jake',
autoDetect: true,
description: nls.localize('jake', 'Creates a tasks.json file for Jake. If a jake file is present tasks will be auto-detected.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "jake",',
'\t"isShellCommand": true,',
'\t"showOutput": "silent"',
'}'
].join('\n')
};
const grunt: TaskEntry = {
id: 'grunt',
label: 'Grunt',
autoDetect: true,
description: nls.localize('grunt', 'Creates a tasks.json file for Grunt. If a jake file is present tasks will be auto-detected.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "grunt",',
'\t"isShellCommand": true,',
'\t"args": ["--no-color"],',
'\t"showOutput": "silent"',
'}'
].join('\n')
};
const tscSpecificFile: TaskEntry = {
id: 'tsc.specificFile',
label: 'TypeScript - Specific File',
autoDetect: false,
description: nls.localize('tsc.specificFile', 'Creates a tasks.json that compiles a specific TypeScript file.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "tsc",',
'\t"isShellCommand": true,',
'\t"args": ["file.ts"],',
'\t"showOutput": "silent",',
'\t"problemMatcher": "$tsc"',
'}'
].join('\n')
};
const tscConfig: TaskEntry = {
id: 'tsc.config',
label: 'TypeScript - tsconfig.json',
autoDetect: false,
description: nls.localize('tsc.config', 'Creates a tasks.json that compiles a TypeScript project.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "tsc",',
'\t"isShellCommand": true,',
'\t"args": ["-p", "."],',
'\t"showOutput": "silent",',
'\t"problemMatcher": "$tsc"',
'}'
].join('\n')
};
const tscWatch: TaskEntry = {
id: 'tsc.watch',
label: 'TypeScript - Watch Mode',
autoDetect: false,
description: nls.localize('tsc.watch', 'Creates a tasks.json that compiles a TypeScript project in watch mode.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "tsc",',
'\t"isShellCommand": true,',
'\t"args": ["-w", "-p", "."],',
'\t"showOutput": "silent",',
'\t"problemMatcher": "$tsc-watch"',
'}'
].join('\n')
};
const tscOpenFile: TaskEntry = {
id: 'tsc.openFile',
label: 'TypeScript - Open File',
autoDetect: false,
description: nls.localize('tsc.openFile', 'Creates a tasks.json that compiles the currently open TypeScript file.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "tsc",',
'\t"isShellCommand": true,',
'\t"args": ["${file}"],',
'\t"showOutput": "silent",',
'\t"problemMatcher": {',
'\t\t"base": "$tsc",',
'\t\t"fileLocation": "absolute"',
'\t}',
'}'
].join('\n')
};
const dotnetBuild: TaskEntry = {
id: 'dotnetBuild',
label: '.Net build',
autoDetect: false,
description: nls.localize('dotnetBuild', 'Creates a tasks.json that compiles using dotnet build.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "dotnet build",',
'\t"showOutput": "always"',
'}'
].join('\n')
};
const msbuild: TaskEntry = {
id: 'msbuild',
label: 'MSBuild',
autoDetect: false,
description: nls.localize('msbuild', 'Creates a tasks.json that compiles using msbuild.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "msbuild",',
'\t"args": [',
'\t\t// Ask msbuild to generate full paths for file names.',
'\t\t"/property:GenerateFullPaths=true"',
'\t],',
'\t"taskSelector": "/t:",',
'\t"showOutput": "silent",',
'\t"tasks": [',
'\t\t{',
'\t\t\t"taskName": "build",',
'\t\t\t// Show the output window only if unrecognized errors occur.',
'\t\t\t"showOutput": "silent",',
'\t\t\t// Use the standard MS compiler pattern to detect errors, warnings and infos',
'\t\t\t"problemMatcher": "$msCompile"',
'\t\t}',
'\t]',
'}'
].join('\n')
};
const command: TaskEntry = {
id: 'externalCommand',
label: 'External Command',
autoDetect: false,
description: nls.localize('externalCommand', 'Creates a tasks.json for an external command to run.'),
content: [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
'\t"version": "0.1.0",',
'\t"command": "echo",',
'\t"isShellCommand": true,',
'\t"args": ["Hello World"],',
'\t"showOutput": "always"',
'}'
].join('\n')
};
export const templates: TaskEntry[] = [gulp, jake, grunt, tscConfig, tscSpecificFile, tscOpenFile, tscWatch, dotnetBuild, msbuild, command];
\ No newline at end of file
......@@ -20,7 +20,6 @@ import * as Dom from 'vs/base/browser/dom';
import { IDisposable, disposeAll } from 'vs/base/common/lifecycle';
import { EventEmitter, ListenerUnbind } from 'vs/base/common/eventEmitter';
import * as Builder from 'vs/base/browser/builder';
import URI from 'vs/base/common/uri';
import * as Types from 'vs/base/common/types';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { match } from 'vs/base/common/glob';
......@@ -39,16 +38,10 @@ import { IConfigurationService, ConfigurationServiceEventTypes } from 'vs/platfo
import { IFileService, FileChangesEvent, FileChangeType, EventType as FileEventType } from 'vs/platform/files/common/files';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybindingService';
import { IModeService } from 'vs/editor/common/services/modeService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
import { ISuggestSupport } from 'vs/editor/common/modes';
import { SuggestController } from 'vs/editor/contrib/suggest/browser/suggest';
import { SuggestRegistry } from 'vs/editor/contrib/suggest/common/suggest';
import jsonContributionRegistry = require('vs/platform/jsonschemas/common/jsonContributionRegistry');
import { IJSONSchema } from 'vs/base/common/jsonSchema';
......@@ -68,6 +61,7 @@ import { IOutputService, IOutputChannelRegistry, Extensions as OutputExt } from
import { ITaskSystem, ITaskSummary, ITaskRunResult, TaskError, TaskErrors, TaskConfiguration, TaskDescription, TaskSystemEvents } from 'vs/workbench/parts/tasks/common/taskSystem';
import { ITaskService, TaskServiceEvents } from 'vs/workbench/parts/tasks/common/taskService';
import { templates as taskTemplates } from 'vs/workbench/parts/tasks/common/taskTemplates';
import { LanguageServiceTaskSystem, LanguageServiceTaskConfiguration } from 'vs/workbench/parts/tasks/common/languageServiceTaskSystem';
import * as FileConfig from 'vs/workbench/parts/tasks/node/processRunnerConfiguration';
......@@ -154,12 +148,12 @@ class ConfigureTaskRunnerAction extends Action {
private contextService: IWorkspaceContextService;
private outputService: IOutputService;
private messageService: IMessageService;
private keybindingService: IKeybindingService;
private quickOpenService: IQuickOpenService;
constructor(id: string, label: string, @IConfigurationService configurationService: IConfigurationService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService, @IFileService fileService: IFileService,
@IWorkspaceContextService contextService: IWorkspaceContextService, @IOutputService outputService: IOutputService,
@IMessageService messageService: IMessageService, @IKeybindingService keybindingService: IKeybindingService) {
@IMessageService messageService: IMessageService, @IQuickOpenService quickOpenService: IQuickOpenService) {
super(id, label);
this.configurationService = configurationService;
......@@ -168,81 +162,59 @@ class ConfigureTaskRunnerAction extends Action {
this.contextService = contextService;
this.outputService = outputService;
this.messageService = messageService;
this.keybindingService = keybindingService;
this.quickOpenService = quickOpenService;
}
public run(event?:any): Promise {
let sideBySide = !!(event && (event.ctrlKey || event.metaKey));
let autoDetectFailed = false;
let useTaskSampleConfig = false;
let fileCreated = false;
return this.fileService.resolveFile(this.contextService.toResource('.vscode/tasks.json')).then((success) => {
return success;
}, (err:any) => {
let detector = new ProcessRunnerDetector(this.fileService, this.contextService, new SystemVariables(this.editorService, this.contextService));
return detector.detect(false).then((value) => {
let config = value.config;
if (value.stderr && value.stderr.length > 0) {
value.stderr.forEach((line) => {
this.outputService.append(TaskService.OutputChannel, line + '\n');
});
autoDetectFailed = true;
this.messageService.show(Severity.Error, nls.localize('ConfigureTaskRunnerAction.autoDetect', 'Auto detecting the task system failed. Consult the task output for details'));
return this.quickOpenService.pick(taskTemplates, { placeHolder: 'Pick a task template'}).then(selection => {
if (!selection) {
return undefined;
}
let contentPromise: TPromise<string>;
if (config) {
contentPromise = TPromise.as<string>(JSON.stringify(config, null, 4));
} else {
// TODO@Dirk: Converting double time here to get a wrong uri that is compatible with the rest of the system
let configSampleUri = URI.parse(require.toUrl('vs/workbench/parts/tasks/common/taskSampleConfig.json'));
contentPromise = this.fileService.resolveContent(configSampleUri, { encoding: 'utf8' /* make sure to keep sample file encoding as we stored it! */}).then(content => {
useTaskSampleConfig = true;
return content.value;
}, (err:any) => {
let config: FileConfig.ExternalTaskRunnerConfiguration = {
version: '0.1.0',
command: 'msbuild.exe',
args: [ '/property:GenerateFullPaths=true' ],
problemMatcher : '$msCompile'
};
return JSON.stringify(config, null, 4);
if (selection.autoDetect) {
let detector = new ProcessRunnerDetector(this.fileService, this.contextService, new SystemVariables(this.editorService, this.contextService));
contentPromise = detector.detect(false, selection.id).then((value) => {
let config = value.config;
if (value.stderr && value.stderr.length > 0) {
value.stderr.forEach((line) => {
this.outputService.append(TaskService.OutputChannel, line + '\n');
});
this.messageService.show(Severity.Error, nls.localize('ConfigureTaskRunnerAction.autoDetect', 'Auto detecting the task system failed. Using default template. Consult the task output for details.'));
return selection.content;
} else if (config) {
let content = JSON.stringify(config, null, '\t');
content = [
'{',
'\t// See http://go.microsoft.com/fwlink/?LinkId=733558',
'\t// for the documentation about the tasks.json format',
].join('\n') + content.substr(1);
return content;
} else {
return selection.content;
}
});
} else {
contentPromise = TPromise.as(selection.content);
}
return contentPromise.then((content) => {
return this.fileService.createFile(this.contextService.toResource('.vscode/tasks.json'), content).then((value) => {
fileCreated = true;
return value;
});
return contentPromise.then(content => {
return this.fileService.createFile(this.contextService.toResource('.vscode/tasks.json'), content);
});
});
}).then((stat) => {
// (2) Open editor with configuration file
if (!stat) {
return undefined;
}
// // (2) Open editor with configuration file
return this.editorService.openEditor({
resource: stat.resource,
options: {
forceOpen: true
}
}, sideBySide).then((editor) => {
if (useTaskSampleConfig && fileCreated) {
let codeEditor: ICodeEditor = editor.getControl() as ICodeEditor;
let position = { lineNumber: 5, column: 2 };
codeEditor.revealPosition(position);
codeEditor.setPosition(position);
// Workaround for: https://github.com/Microsoft/vscode/issues/3121
setTimeout(() => {
let groups: ISuggestSupport[][] = SuggestRegistry.orderedGroups(codeEditor.getModel());
let newGroups: ISuggestSupport[][];
if (groups.length > 1 && groups[0].length > 1) {
newGroups = [[groups[0][1]], groups[1]];
} else {
newGroups = groups;
}
SuggestController.getSuggestController(codeEditor).triggerSuggest(undefined, newGroups);
}, 300);
}
this.outputService.showOutput(TaskService.OutputChannel, true);
return editor;
});
}, sideBySide);
}, (error) => {
throw new Error(nls.localize('ConfigureTaskRunnerAction.failed', "Unable to create the 'tasks.json' file inside the '.vscode' folder. Consult the task output for details."));
});
......@@ -484,7 +456,7 @@ class TaskService extends EventEmitter implements ITaskService {
private eventService: IEventService;
private modelService: IModelService;
private extensionService: IExtensionService;
private keybindingService: IKeybindingService;
private quickOpenService: IQuickOpenService;
private _taskSystemPromise: TPromise<ITaskSystem>;
private _taskSystem: ITaskSystem;
......@@ -500,7 +472,7 @@ class TaskService extends EventEmitter implements ITaskService {
@ITelemetryService telemetryService: ITelemetryService, @ITextFileService textFileService:ITextFileService,
@ILifecycleService lifecycleService: ILifecycleService, @IEventService eventService: IEventService,
@IModelService modelService: IModelService, @IExtensionService extensionService: IExtensionService,
@IKeybindingService keybindingService: IKeybindingService) {
@IQuickOpenService quickOpenService: IQuickOpenService) {
super();
this.modeService = modeService;
......@@ -516,7 +488,7 @@ class TaskService extends EventEmitter implements ITaskService {
this.eventService = eventService;
this.modelService = modelService;
this.extensionService = extensionService;
this.keybindingService = keybindingService;
this.quickOpenService = quickOpenService;
this.taskSystemListeners = [];
this.clearTaskSystemPromise = false;
......@@ -655,7 +627,7 @@ class TaskService extends EventEmitter implements ITaskService {
public configureAction(): Action {
return new ConfigureTaskRunnerAction(ConfigureTaskRunnerAction.ID, ConfigureTaskRunnerAction.TEXT,
this.configurationService, this.editorService, this.fileService, this.contextService,
this.outputService, this.messageService, this.keybindingService);
this.outputService, this.messageService, this.quickOpenService);
}
public build(): TPromise<ITaskSummary> {
......@@ -1205,7 +1177,15 @@ if (Env.enableTasks) {
'$ref': '#/definitions/problemMatcherType',
'description': nls.localize('JsonSchema.tasks.matchers', 'The problem matcher(s) to use. Can either be a string or a problem matcher definition or an array of strings and problem matchers.')
}
}
},
'defaultSnippets': [
{
'label': 'Empty task',
'body': {
'taskName': '{{taskName}}'
}
}
]
}
},
'allOf': [
......
......@@ -5,7 +5,7 @@
'use strict';
import nls = require('vs/nls');
import WinJS = require('vs/base/common/winjs.base');
import { TPromise } from 'vs/base/common/winjs.base';
import Strings = require('vs/base/common/strings');
import Collections = require('vs/base/common/collections');
......@@ -148,7 +148,7 @@ export class ProcessRunnerDetector {
return this._stderr;
}
public detect(list: boolean = false): WinJS.TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
public detect(list: boolean = false, detectSpecific?: string): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
if (this.taskConfiguration && this.taskConfiguration.command && ProcessRunnerDetector.supports(this.taskConfiguration.command)) {
let config = ProcessRunnerDetector.detectorConfig(this.taskConfiguration.command);
let args = (this.taskConfiguration.args || []).concat(config.arg);
......@@ -158,26 +158,44 @@ export class ProcessRunnerDetector {
new LineProcess(this.taskConfiguration.command, this.variables.resolve(args), isShellCommand, options),
this.taskConfiguration.command, isShellCommand, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
} else {
return this.tryDetectGulp(list).then((value) => {
if (value) {
return value;
if (detectSpecific) {
let detectorPromise: TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }>;
if ('gulp' === detectSpecific) {
detectorPromise = this.tryDetectGulp(list);
} else if ('jake' === detectSpecific) {
detectorPromise = this.tryDetectJake(list);
} else if ('grunt' === detectSpecific) {
detectorPromise = this.tryDetectGrunt(list);
}
return this.tryDetectJake(list).then((value) => {
return detectorPromise.then((value) => {
if (value) {
return value;
} else {
return { config: null, stderr: this.stderr };
}
return this.tryDetectGrunt(list).then((value) => {
});
} else {
return this.tryDetectGulp(list).then((value) => {
if (value) {
return value;
}
return this.tryDetectJake(list).then((value) => {
if (value) {
return value;
}
return { config: null, stderr: this.stderr };
return this.tryDetectGrunt(list).then((value) => {
if (value) {
return value;
}
return { config: null, stderr: this.stderr };
});
});
});
});
}
}
}
private tryDetectGulp(list:boolean):WinJS.TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
private tryDetectGulp(list:boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
return this.fileService.resolveFile(this.contextService.toResource('gulpfile.js')).then((stat) => {
let config = ProcessRunnerDetector.detectorConfig('gulp');
let process = new LineProcess('gulp', [config.arg, '--no-color'], true, {cwd: this.variables.workspaceRoot});
......@@ -187,7 +205,7 @@ export class ProcessRunnerDetector {
});
}
private tryDetectGrunt(list:boolean):WinJS.TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
private tryDetectGrunt(list:boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
return this.fileService.resolveFile(this.contextService.toResource('Gruntfile.js')).then((stat) => {
let config = ProcessRunnerDetector.detectorConfig('grunt');
let process = new LineProcess('grunt', [config.arg, '--no-color'], true, {cwd: this.variables.workspaceRoot});
......@@ -197,17 +215,24 @@ export class ProcessRunnerDetector {
});
}
private tryDetectJake(list:boolean):WinJS.TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
return this.fileService.resolveFile(this.contextService.toResource('Jakefile')).then((stat) => {
private tryDetectJake(list:boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
let run = () => {
let config = ProcessRunnerDetector.detectorConfig('jake');
let process = new LineProcess('jake', [config.arg], true, {cwd: this.variables.workspaceRoot});
return this.runDetection(process, 'jake', true, config.matcher, ProcessRunnerDetector.DefaultProblemMatchers, list);
}, (err: any): FileConfig.ExternalTaskRunnerConfiguration => {
return null;
};
return this.fileService.resolveFile(this.contextService.toResource('Jakefile')).then((stat) => {
return run();
}, (err: any) => {
return this.fileService.resolveFile(this.contextService.toResource('Jakefile.js')).then((stat) => {
return run();
}, (err: any): FileConfig.ExternalTaskRunnerConfiguration => {
return null;
});
});
}
private runDetection(process: LineProcess, command: string, isShellCommand: boolean, matcher: TaskDetectorMatcher, problemMatchers: string[], list: boolean):WinJS.TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
private runDetection(process: LineProcess, command: string, isShellCommand: boolean, matcher: TaskDetectorMatcher, problemMatchers: string[], list: boolean): TPromise<{ config: FileConfig.ExternalTaskRunnerConfiguration; stderr: string[]; }> {
let tasks:string[] = [];
matcher.init();
return process.start().then((success) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册