Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public async refresh (): Promise {
this.checkingForUpdates = true;
this._onDidChangeTreeData.fire();
try {
this.updates = await updates.checkAllUpdates();
} catch (error) {
let message = 'Failed to check for updates';
// Need to check in string as titaniumlib currently returns a string as the error
if (error.code === 'ENOTFOUND' || /ENOTFOUND/.test(error)) {
message = `${message} as you are offline`;
}
await vscode.window.showErrorMessage(message);
}
this.checkingForUpdates = false;
this._onDidChangeTreeData.fire();
if (this.updates.length) {
ExtensionContainer.context.globalState.update(GlobalState.HasUpdates, true);
vscode.commands.executeCommand('setContext', GlobalState.HasUpdates, true);
}
}
if (error instanceof InteractionError) {
await handleInteractionError(error);
}
return;
}
try {
const sdkInfo = appc.sdkInfo(sdkVersion);
if (!sdkInfo) {
// TODO
return;
}
const sdkPath = sdkInfo.path;
// Generate the completions
const [ alloy, sdk ] = await Promise.all([
completion.generateAlloyCompletions(force, completion.CompletionsFormat.v2),
completion.generateSDKCompletions(force, sdkVersion, sdkPath, completion.CompletionsFormat.v2)
]);
if (sdk || alloy) {
let message = 'Autocomplete suggestions generated for';
if (sdk) {
message = `${message} Titanium ${sdk}`;
}
if (alloy) {
message = `${message} Alloy ${alloy}`;
}
vscode.window.showInformationMessage(message);
}
} catch (error) {
const actions: InteractionChoice[] = [];
if (error.code === 'ESDKNOTINSTALLED') {
actions.push({
title: 'Install',
async generateAutoCompleteSuggestions({ force = false } = {}) {
const sdkVersion = Project.sdk()[0];
const sdkPath = Appc.sdkInfo(sdkVersion).path;
try {
// Generate the completions
const [ alloy, sdk ] = await Promise.all([
completion.generateAlloyCompletions(force, completion.CompletionsFormat.v2),
completion.generateSDKCompletions(force, sdkVersion, sdkPath, completion.CompletionsFormat.v2)
]);
if (sdk || alloy) {
let message = 'Autocomplete suggestions generated for';
if (sdk) {
message = `${message} Titanium ${sdk}`;
}
if (alloy) {
message = `${message} Alloy ${alloy}`;
}
atom.notifications.addSuccess(message);
}
} catch (error) {
atom.notifications.addError(`Error generating autocomplete suggestions. ${error.message}`);
}
} catch (error) {
if (error instanceof InteractionError) {
await handleInteractionError(error);
}
return;
}
try {
const sdkInfo = appc.sdkInfo(sdkVersion);
if (!sdkInfo) {
// TODO
return;
}
const sdkPath = sdkInfo.path;
// Generate the completions
const [ alloy, sdk ] = await Promise.all([
completion.generateAlloyCompletions(force, completion.CompletionsFormat.v2),
completion.generateSDKCompletions(force, sdkVersion, sdkPath, completion.CompletionsFormat.v2)
]);
if (sdk || alloy) {
let message = 'Autocomplete suggestions generated for';
if (sdk) {
message = `${message} Titanium ${sdk}`;
}
if (alloy) {
message = `${message} Alloy ${alloy}`;
}
vscode.window.showInformationMessage(message);
}
} catch (error) {
const actions: InteractionChoice[] = [];
if (error.code === 'ESDKNOTINSTALLED') {
actions.push({
async generateAutoCompleteSuggestions({ force = false } = {}) {
const sdkVersion = Project.sdk()[0];
const sdkPath = Appc.sdkInfo(sdkVersion).path;
try {
// Generate the completions
const [ alloy, sdk ] = await Promise.all([
completion.generateAlloyCompletions(force, completion.CompletionsFormat.v2),
completion.generateSDKCompletions(force, sdkVersion, sdkPath, completion.CompletionsFormat.v2)
]);
if (sdk || alloy) {
let message = 'Autocomplete suggestions generated for';
if (sdk) {
message = `${message} Titanium ${sdk}`;
}
if (alloy) {
message = `${message} Alloy ${alloy}`;
}
atom.notifications.addSuccess(message);
}
} catch (error) {
atom.notifications.addError(`Error generating autocomplete suggestions. ${error.message}`);
}
this.loadCompletions(sdkVersion);
progress.report({
increment: 100 / totalUpdates
});
}
} catch (error) {
progress.report({
message: `Failed to install ${label} (${counter}/${totalUpdates})`
});
if (incrementProgress) {
progress.report({
increment: 100 / totalUpdates
});
}
if (error.metadata) {
const { metadata } = error;
if (update.productName === updates.ProductNames.AppcInstaller && metadata.errorCode === 'EACCES') {
const runWithSudo = await vscode.window.showErrorMessage(`Failed to update to ${label} as it must be ran with sudo`, {
title: 'Install with Sudo',
run: () => {
ExtensionContainer.terminal.executeCommand(`sudo ${metadata.command}`);
}
});
if (runWithSudo) {
runWithSudo.run();
}
}
} else {
// TODO should we show the error that we got passed?
await vscode.window.showErrorMessage(`Failed to update to ${label}`);
}
}
counter++;
it('Should provide suggestions', async function () {
Project.isTitaniumApp = true;
sandbox.stub(tce.completion, 'loadCompletions').resolves(completions);
initTextEditor('Alloy.');
const suggestions = await getSuggestions('Alloy.');
expect(suggestions.length).to.equal(16);
expect(suggestions[0].type).to.equal('method');
expect(suggestions[0].displayText).to.equal('Alloy');
expect(suggestions[0].text).to.equal('Alloy');
expect(suggestions[0].api).to.equal('Alloy');
expect(suggestions[0].replacementPrefix).to.equal('Alloy.');
expect(suggestions[1].type).to.equal('properties');
expect(suggestions[1].displayText).to.equal('Alloy.CFG');
expect(suggestions[1].rightLabel).to.equal('Alloy');
expect(suggestions[1].snippet).to.equal('CFG');
it('Should provide suggestions', async function () {
Project.isTitaniumApp = true;
sandbox.stub(tce.completion, 'loadCompletions').resolves(completions);
initTextEditor('Ti.');
const suggestions = await getSuggestions('Ti.');
expect(suggestions.length).to.equal(202);
expect(suggestions[0].type).to.equal('method');
expect(suggestions[0].text).to.equal('Ti.UI');
expect(suggestions[0].api).to.equal('Ti');
expect(suggestions[0].replacementPrefix).to.equal('Ti.');
expect(suggestions[1].type).to.equal('method');
expect(suggestions[1].text).to.equal('Ti.XML');
expect(suggestions[1].api).to.equal('Ti');
expect(suggestions[1].replacementPrefix).to.equal('Ti.');
it('should provide tag suggestions', async function () {
Project.isTitaniumApp = true;
sandbox.stub(tce.completion, 'loadCompletions').resolves(completions);
initTextEditor('$2');
expect(suggestions[0].rightLabel).to.equal('Alloy.Widget');
expect(suggestions[0].description).to.equal('Alloy.Widget');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Widget');
expect(suggestions[1].type).to.equal('tag');
expect(suggestions[1].displayText).to.equal('Window');
expect(suggestions[1].snippet).to.equal('Window$1>$2');
it('should provide tag suggestions', async function () {
Project.isTitaniumApp = true;
sandbox.stub(tce.completion, 'loadCompletions').resolves(completions);
initTextEditor('"W');
const suggestions = await getSuggestions('W');
expect(suggestions.length).to.equal(4);
expect(suggestions[0].type).to.equal('tag');
expect(suggestions[0].text).to.equal('Widget');
expect(suggestions[0].rightLabel).to.equal('Alloy.Widget');
expect(suggestions[0].description).to.equal('Alloy.Widget');
expect(suggestions[0].descriptionMoreURL).to.equal('http://docs.appcelerator.com/platform/latest/#!/api/Alloy.Widget');
expect(suggestions[1].type).to.equal('tag');
expect(suggestions[1].text).to.equal('Window');
expect(suggestions[1].rightLabel).to.equal('Ti.UI.Window');
expect(suggestions[1].description).to.equal('Ti.UI.Window: The Window is an empty drawing surface or container.');