Skip to content

Commit

Permalink
3.21.3 (#348)
Browse files Browse the repository at this point in the history
* Fix issues switching usernames in the Saved Usernames view

* Queue code coverage retrieval so it isn't called multiple times when refreshing modified files
daishi4u authored Dec 31, 2019

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent fb3afa3 commit d6d6777
Showing 13 changed files with 95 additions and 101 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Change Log

* 3.21.3
* Fix issues switching usernames in the Saved Usernames view
* Queue code coverage retrieval so it isn't called multiple times when refreshing modified files
* 3.21.2
* Fix issue deploying static resources
* Fix retrieval of static resource when working in the resource-bundles folder
46 changes: 20 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "forcecode",
"version": "3.21.2",
"version": "3.21.3",
"publisher": "JohnAaronNelson",
"displayName": "ForceCode",
"description": "Visual Studio Code extension for Salesforce (SFDC) development",
@@ -662,7 +662,7 @@
"@types/globule": "1.1.3",
"@types/klaw": "3.0.0",
"@types/mocha": "^5.2.7",
"@types/node": "^10.17.12",
"@types/node": "^10.17.13",
"@types/sinon": "^7.5.1",
"@types/universal-analytics": "0.4.3",
"@types/vscode": "1.41.0",
@@ -682,7 +682,7 @@
"remap-istanbul": "^0.13.0",
"request-light": "0.2.5",
"rimraf": "^3.0.0",
"sinon": "^8.0.1",
"sinon": "^8.0.2",
"tree-kill": "1.2.2",
"ts-loader": "^6.2.1",
"tslint": "^5.20.1",
@@ -691,7 +691,7 @@
"uuid": "3.3.3",
"vsce": "^1.71.0",
"vscode-test": "^1.3.0",
"webpack": "^4.41.4",
"webpack": "^4.41.5",
"webpack-cli": "^3.3.10",
"xml2js": "0.4.23"
}
11 changes: 8 additions & 3 deletions src/commands/apexTest.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import {
FCFile,
notifications,
getVSCodeSetting,
commandViewService,
} from '../services';
import { ForcecodeCommand } from '.';
import { updateDecorations } from '../decorators';
@@ -34,7 +35,11 @@ export class GetCodeCoverage extends ForcecodeCommand {
}

public command() {
return getApexTestResults().then(_res => getApexTestResults(true));
return getApexTestResults()
.then(_res => getApexTestResults(true))
.then((
_res2 // update the current editor
) => updateDecorations());
}
}

@@ -67,8 +72,8 @@ export class ApexTest extends ForcecodeCommand {
return dxService
.runTest(context, selectedResource, this.cancellationToken)
.then((dxRes: ApexTestQueryResult) => {
return vscode.commands
.executeCommand('ForceCode.getCodeCoverage', undefined, undefined)
return commandViewService
.enqueueCodeCoverage()
.then(() => showResult(dxRes))
.then(showLog);
});
4 changes: 2 additions & 2 deletions src/commands/fcCommands.ts
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ import {
import { getFileName } from '../parsers';
import { readConfigFile, removeConfigFolder } from '../services';
import { Config } from '../forceCode';
import { editorUpdateApexCoverageDecorator } from '../decorators';
import { updateDecorations } from '../decorators';

export class ToolingQuery extends ForcecodeCommand {
constructor() {
@@ -190,7 +190,7 @@ export class ChangeCoverageDecoration extends ForcecodeCommand {
.then(doc => vscode.window.showTextDocument(doc, { preview: false }))
.then(_res => {
parent.setCoverageTestClass(newCoverage);
return editorUpdateApexCoverageDecorator(vscode.window.activeTextEditor);
return updateDecorations();
});
}
}
15 changes: 3 additions & 12 deletions src/commands/retrieve.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {
PXMLMember,
notifications,
getVSCodeSetting,
commandViewService,
} from '../services';
import { getToolingTypeFromExt, getAnyTTMetadataFromPath, outputToString } from '../parsers';
import { IWorkspaceMember, IMetadataObject, ICodeCoverage } from '../forceCode';
@@ -527,7 +528,6 @@ export function retrieve(
// =======================================================================================================================================
function finished(res: any): Promise<any> {
if (res.success) {
var getCodeCov: boolean = false;
notifications.writeLog('Done retrieving files');
// check the metadata and add the new members
return updateWSMems().then(() => {
@@ -554,7 +554,7 @@ export function retrieve(
return cur.type === 'ApexClass' || cur.type === 'ApexTrigger';
});
if (shouldGetCoverage) {
getCodeCov = true;
commandViewService.enqueueCodeCoverage();
}
return vscode.window.forceCode.conn.metadata.list(theTypes[curTypes]);
});
@@ -585,16 +585,7 @@ export function retrieve(
});
});
notifications.writeLog('Done updating/adding metadata');
if (getCodeCov) {
return vscode.commands
.executeCommand('ForceCode.getCodeCoverage', undefined, undefined)
.then(() => {
notifications.writeLog('Done retrieving code coverage');
return Promise.resolve();
});
} else {
return Promise.resolve();
}
return Promise.resolve();
}
} else {
notifications.showError('Retrieve Errors');
2 changes: 1 addition & 1 deletion src/decorators/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { updateDecorations, editorUpdateApexCoverageDecorator } from './testCoverageDecorator';
export { updateDecorations } from './testCoverageDecorator';
57 changes: 25 additions & 32 deletions src/decorators/testCoverageDecorator.ts
Original file line number Diff line number Diff line change
@@ -26,40 +26,30 @@ const acovLineStyle: vscode.TextEditorDecorationType = vscode.window.createTextE
{ backgroundColor: 'rgba(72,54,36,1)', isWholeLine: true }
);

// When this subscription is created (when the extension/Code boots), try to decorate the document
let activeEditor: vscode.TextEditor | undefined = vscode.window.activeTextEditor;
if (activeEditor) {
updateDecorations();
}
// Export Function used when the Editor changes
export function editorUpdateApexCoverageDecorator(editor: vscode.TextEditor | undefined) {
activeEditor = editor;
if (editor) {
updateDecorations();
}
}

export function updateDecorations() {
if (!activeEditor) {
return;
}
var uncoveredLineOptions: vscode.DecorationOptions[] = [];
var lineOpts: vscode.TextEditorDecorationType = uncoveredLineStyle;
if (activeEditor.document.languageId === 'apexCodeCoverage') {
lineOpts = acovLineStyle;
for (var i: number = 2; i < activeEditor.document.lineCount; i += 2) {
let decorationRange: vscode.DecorationOptions = {
range: activeEditor.document.lineAt(i).range,
};
uncoveredLineOptions.push(decorationRange);
vscode.window.visibleTextEditors.forEach(editor => {
var uncoveredLineOptions: vscode.DecorationOptions[] = [];
var lineOpts: vscode.TextEditorDecorationType = uncoveredLineStyle;
if (editor.document.languageId === 'apexCodeCoverage') {
lineOpts = acovLineStyle;
for (var i: number = 2; i < editor.document.lineCount; i += 2) {
let decorationRange: vscode.DecorationOptions = {
range: editor.document.lineAt(i).range,
};
uncoveredLineOptions.push(decorationRange);
}
} else if (vscode.window.forceCode?.config?.showTestCoverage) {
uncoveredLineOptions = getUncoveredLineOptions(editor);
}
} else if (vscode.window.forceCode?.config?.showTestCoverage) {
uncoveredLineOptions = getUncoveredLineOptions(activeEditor.document);
editor.setDecorations(lineOpts, uncoveredLineOptions);
});

if (vscode.window.activeTextEditor) {
}
activeEditor.setDecorations(lineOpts, uncoveredLineOptions);
}

function getUncoveredLineOptions(document: vscode.TextDocument) {
function getUncoveredLineOptions(editor: vscode.TextEditor) {
const document = editor.document;
var uncoveredLineDec: vscode.DecorationOptions[] = [];
const fcfile: FCFile | undefined = codeCovViewService.findByPath(document.fileName);
if (fcfile) {
@@ -86,9 +76,12 @@ function getUncoveredLineOptions(document: vscode.TextDocument) {
uncoveredLineDecorations.push(decorationRange);
// Add output to output channel
});
var total: number = fileCoverage.NumLinesCovered + fileCoverage.NumLinesUncovered;
var percent = ((fileCoverage.NumLinesCovered / total) * 100).toFixed(2) + '% covered';
notifications.showStatus(fileCoverage.ApexClassOrTrigger.Name + ' ' + percent);

if (editor === vscode.window.activeTextEditor) {
var total: number = fileCoverage.NumLinesCovered + fileCoverage.NumLinesUncovered;
var percent = ((fileCoverage.NumLinesCovered / total) * 100).toFixed(2) + '% covered';
notifications.showStatus(fileCoverage.ApexClassOrTrigger.Name + ' ' + percent);
}
}
return uncoveredLineDecorations;
}
6 changes: 2 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ import {
FCTimer,
} from './services';
import { ApexTestLinkProvider, ForceCodeContentProvider, ForceCodeLogProvider } from './providers';
import { editorUpdateApexCoverageDecorator, updateDecorations } from './decorators';
import { updateDecorations } from './decorators';
import { fcCommands, createProject } from './commands';
import * as path from 'path';
import * as fs from 'fs-extra';
@@ -112,9 +112,7 @@ export function activate(context: vscode.ExtensionContext): any {
);

// Text Coverage Decorators
context.subscriptions.push(
vscode.window.onDidChangeActiveTextEditor(editorUpdateApexCoverageDecorator)
);
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(updateDecorations));

// watch for config file changes
context.subscriptions.push(
3 changes: 0 additions & 3 deletions src/services/apexTestResults.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as vscode from 'vscode';
import * as forceCode from '../forceCode';
import { editorUpdateApexCoverageDecorator } from '../decorators';
import { codeCovViewService, FCFile, getVSCodeSetting } from '.';
import { QueryResult } from 'jsforce';

@@ -39,8 +38,6 @@ export function getApexTestResults(singleClass?: boolean): Promise<QueryResult>
}
}
});
// update the current editor
editorUpdateApexCoverageDecorator(vscode.window.activeTextEditor);

if (singleClass && highestClass && getVSCodeSetting('revealTestedClass')) {
// reveal the tested class
21 changes: 18 additions & 3 deletions src/services/commandView.ts
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ export class CommandViewService implements vscode.TreeDataProvider<Task> {
private static instance: CommandViewService;
private readonly tasks: Task[];
private fileModCommands: number = 0;
private getCodeCoverage: boolean = false;
private _onDidChangeTreeData: vscode.EventEmitter<Task | undefined> = new vscode.EventEmitter<
Task | undefined
>();
@@ -40,6 +41,11 @@ export class CommandViewService implements vscode.TreeDataProvider<Task> {
return CommandViewService.instance;
}

public enqueueCodeCoverage() {
this.getCodeCoverage = true;
return Promise.resolve(false);
}

public addCommandExecution(execution: ForcecodeCommand, context: any, selectedResource?: any) {
if (
['ForceCode.compile', 'ForceCode.refresh'].find(c => {
@@ -68,10 +74,10 @@ export class CommandViewService implements vscode.TreeDataProvider<Task> {
}

if (execution.commandName === 'ForceCode.fileModified') {
this.fileModCommands++;
if (this.fileModCommands > getVSCodeSetting('maxFileChangeNotifications')) {
if (this.fileModCommands >= getVSCodeSetting('maxFileChangeNotifications')) {
return Promise.resolve();
}
this.fileModCommands++;
}

var theTask: Task = new Task(this, execution, context, selectedResource);
@@ -91,7 +97,7 @@ export class CommandViewService implements vscode.TreeDataProvider<Task> {
public removeTask(task: Task): boolean {
const index = this.tasks.indexOf(task);
if (index !== -1) {
if (this.tasks[index].execution.commandName === 'ForceCode.fileModified') {
if (task.execution.commandName === 'ForceCode.fileModified') {
this.fileModCommands--;
}
this.tasks.splice(index, 1);
@@ -101,6 +107,15 @@ export class CommandViewService implements vscode.TreeDataProvider<Task> {
'$(loading~spin) ForceCode: Executing ' + this.getChildren().length + ' Tasks';
} else {
this.runningTasksStatus.hide();
// when code coverage is enqueued, it will only be retrieved when no other visible tasks are running
if (this.getCodeCoverage) {
this.getCodeCoverage = false;
vscode.commands
.executeCommand('ForceCode.getCodeCoverage', undefined, undefined)
.then(() => {
notifications.writeLog('Done retrieving code coverage');
});
}
}

this._onDidChangeTreeData.fire();
12 changes: 7 additions & 5 deletions src/services/fcConnectionService.ts
Original file line number Diff line number Diff line change
@@ -74,7 +74,9 @@ export class FCConnectionService implements vscode.TreeDataProvider<FCConnection

public isLoggedIn(): boolean {
const loggedIn: boolean =
vscode.window.forceCode.conn && this.currentConnection?.isLoggedIn === true;
vscode.window.forceCode.conn !== undefined &&
this.currentConnection?.connection !== undefined &&
this.currentConnection?.isLoggedIn === true;
if (loggedIn) {
vscode.commands.executeCommand('setContext', 'ForceCodeLoggedIn', true);
} else {
@@ -213,7 +215,7 @@ export class FCConnectionService implements vscode.TreeDataProvider<FCConnection
function setOrgInfo(orgInf: FCOauth | SFDX): Promise<Connection | undefined> {
service.currentConnection = service.addConnection(orgInf, true);
if (!service.currentConnection) {
return Promise.reject('Error setting up connection');
return Promise.reject('Error setting up connection: setOrgInfo');
}
vscode.window.forceCode.config = readConfigFile(orgInf.username);

@@ -237,15 +239,15 @@ export class FCConnectionService implements vscode.TreeDataProvider<FCConnection
if (connection) {
return connection.identity().then((res: any) => {
if (!service.currentConnection) {
return Promise.reject('Error setting up connection');
return Promise.reject('Error setting up connection: getUserId1');
}
service.currentConnection.orgInfo.userId = res.user_id;
service.currentConnection.isLoggedIn = true;
vscode.commands.executeCommand('setContext', 'ForceCodeLoggedIn', true);
return Promise.resolve(false);
});
} else {
return Promise.reject('Error setting up connection');
return Promise.reject('Error setting up connection: getUserId2');
}
}

@@ -254,7 +256,7 @@ export class FCConnectionService implements vscode.TreeDataProvider<FCConnection
return checkConfig(vscode.window.forceCode.config).then(config => {
saveConfigFile(config.username, config);
if (!service.currentConnection || !service.currentConnection.connection) {
return Promise.reject('Error setting up connection');
return Promise.reject('Error setting up connection: login');
}
vscode.window.forceCode.conn = service.currentConnection.connection;

8 changes: 2 additions & 6 deletions src/services/forceService.ts
Original file line number Diff line number Diff line change
@@ -10,6 +10,7 @@ import {
defaultOptions,
readForceJson,
getVSCodeSetting,
commandViewService,
} from '.';
import * as path from 'path';
import { getToolingTypeFromExt } from '../parsers';
@@ -177,12 +178,7 @@ export class ForceService implements forceCode.IForceService {
}
});
notifications.writeLog('Done getting workspace info');
return vscode.commands
.executeCommand('ForceCode.getCodeCoverage', undefined, undefined)
.then(() => {
notifications.writeLog('Done retrieving code coverage');
return Promise.resolve();
});
return commandViewService.enqueueCodeCoverage();
}
}

0 comments on commit d6d6777

Please sign in to comment.