mirror of
https://github.com/Microsoft/vscode
synced 2024-09-13 21:55:38 +00:00
added config option whether the explorer should be enabled.
This commit is contained in:
parent
bb1119e0b1
commit
48b0ec47da
|
@ -14,3 +14,4 @@ For more information about auto detection of Tasks pls see the [documentation](h
|
|||
- `npm.runSilent` run npm script with the `--silent` option, the default is `false`.
|
||||
- `npm.packageManager` the package manager used to run the scripts: `npm` or `yarn`, the default is `npm`.
|
||||
- `npm.exclude` glob patterns for folders that should be excluded from automatic script detection. The pattern is matched against the **absolute path** of the package.json. For example, to exclude all test folders use '**/test/**'.
|
||||
- `npm.enableScriptExplorer` enable an explorer view for npm scripts when the workspace contains a 'package.json' file.
|
||||
|
|
|
@ -96,7 +96,6 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
|
||||
"configuration": {
|
||||
"id": "npm",
|
||||
"type": "object",
|
||||
|
@ -138,6 +137,12 @@
|
|||
},
|
||||
"description": "%config.npm.exclude%",
|
||||
"scope": "resource"
|
||||
},
|
||||
"npm.enableScriptExplorer": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"scope": "resource",
|
||||
"description": "%config.npm.enableScriptExplorer%"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"config.npm.runSilent": "Run npm commands with the `--silent` option.",
|
||||
"config.npm.packageManager": "The package manager used to run scripts.",
|
||||
"config.npm.exclude": "Configure glob patterns for folders that should be excluded from automatic script detection.",
|
||||
"config.npm.enableScriptExplorer": "Enable an explorer view for npm scripts, when the workspace contains a 'package.json' file.",
|
||||
"npm.parseError": "Npm task detection: failed to parse the file {0}",
|
||||
"taskdef.script": "The npm script to customize.",
|
||||
"taskdef.path": "The path to the folder of the package.json file that provides the script. Can be ommitted.",
|
||||
|
|
|
@ -12,12 +12,18 @@ const localize = nls.loadMessageBundle();
|
|||
|
||||
import { addJSONProviders } from './features/jsonContributions';
|
||||
import { NpmScriptsTreeDataProvider } from './npmView';
|
||||
import { provideNpmScripts, hasNpmScripts } from './tasks';
|
||||
import { provideNpmScripts, hasNpmScripts, explorerIsEnabled } from './tasks';
|
||||
|
||||
let taskProvider: vscode.Disposable | undefined;
|
||||
|
||||
export async function activate(context: vscode.ExtensionContext): Promise<void> {
|
||||
taskProvider = registerTaskProvider(context);
|
||||
configureHttpRequest();
|
||||
vscode.workspace.onDidChangeConfiguration(() => configureHttpRequest());
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
||||
}
|
||||
|
||||
function registerTaskProvider(context: vscode.ExtensionContext): vscode.Disposable | undefined {
|
||||
if (vscode.workspace.workspaceFolders) {
|
||||
let provider: vscode.TaskProvider = {
|
||||
provideTasks: () => {
|
||||
|
@ -27,19 +33,21 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
|
|||
return undefined;
|
||||
}
|
||||
};
|
||||
taskProvider = vscode.workspace.registerTaskProvider('npm', provider);
|
||||
let disposable = vscode.workspace.registerTaskProvider('npm', provider);
|
||||
registerExplorer(context, provider);
|
||||
return disposable;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
async function registerExplorer(context: vscode.ExtensionContext, provider: vscode.TaskProvider) {
|
||||
if (explorerIsEnabled()) {
|
||||
let treeDataProvider = vscode.window.registerTreeDataProvider('npm', new NpmScriptsTreeDataProvider(context, provider, localize));
|
||||
context.subscriptions.push(treeDataProvider);
|
||||
|
||||
if (await hasNpmScripts()) {
|
||||
vscode.commands.executeCommand('setContext', 'hasNpmScripts', true);
|
||||
}
|
||||
}
|
||||
|
||||
configureHttpRequest();
|
||||
vscode.workspace.onDidChangeConfiguration(() => configureHttpRequest());
|
||||
|
||||
context.subscriptions.push(addJSONProviders(httpRequest.xhr));
|
||||
}
|
||||
|
||||
function configureHttpRequest() {
|
||||
|
|
|
@ -48,6 +48,20 @@ export function getPackageManager(folder: WorkspaceFolder): string {
|
|||
return workspace.getConfiguration('npm', folder.uri).get<string>('packageManager', 'npm');
|
||||
}
|
||||
|
||||
export function explorerIsEnabled(): boolean {
|
||||
let folders = workspace.workspaceFolders;
|
||||
if (!folders) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
let folder = folders[i];
|
||||
if (workspace.getConfiguration('npm', folder.uri).get<boolean>('enableScriptExplorer') === true) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export async function hasNpmScripts(): Promise<boolean> {
|
||||
let folders = workspace.workspaceFolders;
|
||||
if (!folders) {
|
||||
|
@ -56,7 +70,7 @@ export async function hasNpmScripts(): Promise<boolean> {
|
|||
try {
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
let folder = folders[i];
|
||||
if (isEnabled(folder)) {
|
||||
if (isAutoDetectionEnabled(folder)) {
|
||||
let relativePattern = new RelativePattern(folder, '**/package.json');
|
||||
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
||||
if (paths.length > 0) {
|
||||
|
@ -81,7 +95,7 @@ export async function provideNpmScripts(localize: any): Promise<Task[]> {
|
|||
try {
|
||||
for (let i = 0; i < folders.length; i++) {
|
||||
let folder = folders[i];
|
||||
if (isEnabled(folder)) {
|
||||
if (isAutoDetectionEnabled(folder)) {
|
||||
let relativePattern = new RelativePattern(folder, '**/package.json');
|
||||
let paths = await workspace.findFiles(relativePattern, '**/node_modules/**');
|
||||
for (let j = 0; j < paths.length; j++) {
|
||||
|
@ -98,7 +112,7 @@ export async function provideNpmScripts(localize: any): Promise<Task[]> {
|
|||
}
|
||||
}
|
||||
|
||||
function isEnabled(folder: WorkspaceFolder): boolean {
|
||||
function isAutoDetectionEnabled(folder: WorkspaceFolder): boolean {
|
||||
return workspace.getConfiguration('npm', folder.uri).get<AutoDetect>('autoDetect') === 'on';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue