本文整理汇总了TypeScript中vscode.commands类的典型用法代码示例。如果您正苦于以下问题:TypeScript commands类的具体用法?TypeScript commands怎么用?TypeScript commands使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了commands类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: showNodeMCUToolbox
/**
*
*/
function showNodeMCUToolbox() {
vscode.commands.executeCommand('vscode.previewHtml', DeviceInfoContentProvider.uri, vscode.ViewColumn.One, 'NodeMCU Toolbox').then((success) => {}, (reason) => {
vscode.window.showErrorMessage(reason);
});
}
示例2: assert
}).then(editor => {
assert(vscode.window.activeTextEditor, 'No active editor');
textEditor = editor;
return vscode.commands.executeCommand('python.sortImports');
}).then(() => {
示例3: activate
export function activate(context: vscode.ExtensionContext) {
// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
var openurl = require('open');
var fs = require('fs');
var GitHubApi = require("github4");
var github = new GitHubApi({
version: "3.0.0"
});
var disposable = vscode.commands.registerCommand('extension.updateSettings', async () => {
var en: envir.Environment = new envir.Environment(context);
var common: commons.Commons = new commons.Commons(en);
var myGi: myGit.GithubService = null;
async function Init() {
vscode.window.setStatusBarMessage("Checking for Github Token and GIST.", 2000);
var syncSetting: Setting = await common.InitSettings();
if (syncSetting.Token == null || syncSetting.Token == "") {
openurl("https://github.com/settings/tokens");
await common.GetTokenAndSave(syncSetting).then(function (saved: boolean) {
if (saved) {
Init();
return;
}
else {
vscode.window.showErrorMessage("TOKEN NOT SAVED");
return;
}
}, function (err: any) {
console.error(err);
vscode.window.showErrorMessage(common.ERROR_MESSAGE);
return;
});
}
else {
myGi = new myGit.GithubService(syncSetting.Token);
vscode.window.setStatusBarMessage("Uploading / Updating Your Settings In Github.", 3000);
await startGitProcess(syncSetting);
return;
}
}
async function startGitProcess(sett: Setting) {
if (sett.Token != null) {
var allSettingFiles = new Array<File>();
vscode.window.setStatusBarMessage("Reading Settings and Extensions.", 1000);
await fileManager.FileManager.FileExists(en.FILE_SETTING).then(async function (fileExists: boolean) {
if (fileExists) {
await fileManager.FileManager.ReadFile(en.FILE_SETTING).then(function (settings: string) {
if (settings) {
var fileName = en.FILE_SETTING_NAME;
var filePath = en.FILE_SETTING;
var fileContent = settings;
var file: File = new File(fileName, fileContent, filePath);
allSettingFiles.push(file);
}
});
}
});
await fileManager.FileManager.FileExists(en.FILE_LAUNCH).then(async function (fileExists: boolean) {
if (fileExists) {
await fileManager.FileManager.ReadFile(en.FILE_LAUNCH).then(function (launch: string) {
if (launch) {
var fileName = en.FILE_LAUNCH_NAME;
var filePath = en.FILE_LAUNCH;
var fileContent = launch;
var file: File = new File(fileName, fileContent, filePath);
allSettingFiles.push(file);
}
});
}
});
var destinationKeyBinding : string = "";
if (en.OsType == OsType.Mac) {
destinationKeyBinding = en.FILE_KEYBINDING_MAC;
}
else{
destinationKeyBinding = en.FILE_KEYBINDING_DEFAULT;
}
await fileManager.FileManager.FileExists(en.FILE_KEYBINDING).then(async function (fileExists: boolean) {
if (fileExists) {
await fileManager.FileManager.ReadFile(en.FILE_KEYBINDING).then(function (keybinding: string) {
if (keybinding) {
var fileName = destinationKeyBinding;
var filePath = en.FILE_KEYBINDING;
//.........这里部分代码省略.........
示例4: constructor
constructor(context: vs.ExtensionContext, analyzer: Analyzer) {
context.subscriptions.push(vs.commands.registerCommand("dart.openAnalyzerDiagnostics", async () => {
const res = await analyzer.diagnosticGetServerPort();
openInBrowser(`http://localhost:${res.port}/`);
}));
}
示例5: test
test('showQuickPick, accept first', async function () {
const pick = window.showQuickPick(['eins', 'zwei', 'drei']);
await new Promise(resolve => setTimeout(resolve, 10)); // Allow UI to update.
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
assert.equal(await pick, 'eins');
});
示例6: create
export function create(client: ITypescriptServiceClient, isOpen: (path: string) => Promise<boolean>, memento: vscode.Memento) {
const toDispose: vscode.Disposable[] = [];
const projectHinted: { [k: string]: boolean } = Object.create(null);
const projectHintIgnoreList = memento.get<string[]>('projectHintIgnoreList', []);
for (let path of projectHintIgnoreList) {
if (path === null) {
path = undefined;
}
projectHinted[path] = true;
}
let currentHint: Hint;
let item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, Number.MIN_VALUE);
item.command = 'js.projectStatus.command';
toDispose.push(vscode.commands.registerCommand('js.projectStatus.command', () => {
let {message, options} = currentHint;
return vscode.window.showInformationMessage(message, ...options).then(selection => {
if (selection) {
return selection.execute();
}
});
}));
toDispose.push(vscode.workspace.onDidChangeTextDocument(e => {
delete projectHinted[e.document.fileName];
}));
function onEditor(editor: vscode.TextEditor): void {
if (!editor
|| !vscode.languages.match(selector, editor.document)
|| !client.asAbsolutePath(editor.document.uri)) {
item.hide();
return;
}
const file = client.asAbsolutePath(editor.document.uri);
isOpen(file).then(value => {
if (!value) {
return;
}
return client.execute('projectInfo', { file, needFileNameList: true }).then(res => {
let {configFileName, fileNames} = res.body;
if (projectHinted[configFileName] === true) {
return;
}
if (!configFileName && vscode.workspace.rootPath) {
exists(join(vscode.workspace.rootPath, 'jsconfig.json'), exists => {
// don't hint if there is a global jsconfig-file. We can get here due
// to TypeScript bugs or jsconfig configurations
if (exists) {
return;
}
currentHint = {
message: localize('hintCreate', "Create a jsconfig.json to enable richer IntelliSense and code navigation across the entire workspace."),
options: [{
title: localize('ignore.cmdCreate', 'Ignore'),
execute: () => {
client.logTelemetry('js.hintProjectCreation.ignored');
projectHinted[configFileName] = true;
projectHintIgnoreList.push(configFileName);
memento.update('projectHintIgnoreList', projectHintIgnoreList);
item.hide();
}
}, {
title: localize('cmdCreate', "Create jsconfig.json"),
execute: () => {
client.logTelemetry('js.hintProjectCreation.accepted');
projectHinted[configFileName] = true;
item.hide();
return vscode.workspace.openTextDocument(vscode.Uri.parse('untitled:' + encodeURIComponent(join(vscode.workspace.rootPath, 'jsconfig.json'))))
.then(doc => vscode.window.showTextDocument(doc, vscode.ViewColumn.Three))
.then(editor => editor.edit(builder => builder.insert(new vscode.Position(0, 0), defaultConfig)));
}
}]
};
item.text = '$(light-bulb)';
item.tooltip = localize('hintCreate.tooltip', "Create a jsconfig.json to enable richer IntelliSense and code navigation across the entire workspace.");
item.color = '#A5DF3B';
item.show();
client.logTelemetry('js.hintProjectCreation');
});
} else if (fileNames.length > fileLimit) {
let largeRoots = computeLargeRoots(configFileName, fileNames).map(f => `'/${f}/'`).join(', ');
currentHint = {
message: largeRoots.length > 0
? localize('hintExclude', "For better performance exclude folders with many files, like: {0}", largeRoots)
: localize('hintExclude.generic', "For better performance exclude folders with many files."),
options: [{
title: localize('open', "Configure Excludes"),
//.........这里部分代码省略.........
示例7: executeCommandWithCount
private executeCommandWithCount(count: number, command: string) {
for (let i = 0; i < count; i++) {
vscode.commands.executeCommand(command);
}
}
示例8: before
before("run 'flutter clean'", () => vs.commands.executeCommand("_flutter.clean", fsPath(flutterHelloWorldFolder)));
示例9: activate
export function activate(context: vscode.ExtensionContext): void {
const outputChannel: vscode.OutputChannel = null;
// Supported languages
const supportedDocuments: vscode.DocumentSelector = [
{ language: 'css', scheme: 'file' },
{ language: 'postcss', scheme: 'file' },
{ language: 'scss', scheme: 'file' },
{ language: 'less', scheme: 'file' }
];
// For plugin command: "postcssSorting.execute"
const command = vscode.commands.registerTextEditorCommand('postcssSorting.execute', (textEditor) => {
// Prevent run command without active TextEditor
if (!vscode.window.activeTextEditor) {
return null;
}
const document = textEditor.document;
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
const workspaceUri = workspaceFolder ? workspaceFolder.uri : null;
const settings = settingsManager.getSettings(workspaceUri);
use(settings, document, null)
.then((result) => {
if (!result) {
return;
}
textEditor.edit((editBuilder) => {
editBuilder.replace(result.range, result.css);
});
})
.catch((err) => utils.output(outputChannel, err, settings.showErrorMessages));
});
// For commands: "Format Document" and "Format Selection"
const format = vscode.languages.registerDocumentRangeFormattingEditProvider(supportedDocuments, {
provideDocumentRangeFormattingEdits(document: vscode.TextDocument, range: vscode.Range): vscode.ProviderResult<vscode.TextEdit[]> {
// Prevent run command without active TextEditor
if (!vscode.window.activeTextEditor) {
return null;
}
const workspaceFolder = vscode.workspace.getWorkspaceFolder(document.uri);
const workspaceUri = workspaceFolder ? workspaceFolder.uri : null;
const settings = settingsManager.getSettings(workspaceUri);
return use(settings, document, range)
.catch((err) => utils.output(outputChannel, err, settings.showErrorMessages))
.then((result) => {
if (!result) {
return;
}
return [vscode.TextEdit.replace(result.range, result.css)];
});
}
});
// Subscriptions
context.subscriptions.push(command);
context.subscriptions.push(format);
}
示例10: activate
export function activate(context: vscode.ExtensionContext) {
ExtensionServer.getInstance().start();
performVersionsCheck(context);
let runCommand = (project: ns.NSProject, options: string[]) => {
if (vscode.workspace.rootPath === undefined) {
vscode.window.showErrorMessage('No workspace opened.');
return;
}
vscode.window.showQuickPick(options)
.then(target => {
if(target == undefined) {
return; // e.g. if the user presses escape button
}
// Move the selected option to be the first element in order to keep the last selected option at the top of the list
options.splice(options.indexOf(target), 1);
options.unshift(target);
// Show output channel
let runChannel: vscode.OutputChannel = vscode.window.createOutputChannel(`Run on ${project.platform()}`);
runChannel.clear();
runChannel.show(vscode.ViewColumn.Two);
// Execute run command
let emulator: boolean = (target === 'emulator');
AnalyticsService.getInstance().runRunCommand(project.platform(), emulator);
return project.run(emulator)
.then(tnsProcess => {
tnsProcess.on('error', err => {
vscode.window.showErrorMessage('Unexpected error executing NativeScript Run command.');
});
tnsProcess.stderr.on('data', data => {
runChannel.append(data);
});
tnsProcess.stdout.on('data', data => {
runChannel.append(data);
});
tnsProcess.on('exit', exitCode => {
tnsProcess.stdout.removeAllListeners('data');
tnsProcess.stderr.removeAllListeners('data');
});
tnsProcess.on('close', exitCode => {
runChannel.hide();
});
});
});
};
let iosRunOptions = ['device', 'emulator'];
let runIosCommand = vscode.commands.registerCommand('nativescript.runIos', () => {
return runCommand(new ns.IosProject(vscode.workspace.rootPath), iosRunOptions);
});
let androidRunOptions = ['device', 'emulator'];
let runAndroidCommand = vscode.commands.registerCommand('nativescript.runAndroid', () => {
return runCommand(new ns.AndroidProject(vscode.workspace.rootPath), androidRunOptions);
});
context.subscriptions.push(runIosCommand);
context.subscriptions.push(runAndroidCommand);
}