Skip to content

Commit

Permalink
Vscode-Plugin update 1.0.13.
Browse files Browse the repository at this point in the history
- FrontEndART#94: Fixed bug where declining a warning patch candidate would result the removal of the entire warning from the analysis output window.
- FrontEndART#73: Changed format of generated config.property file.
  • Loading branch information
searchlab-team committed Jul 4, 2022
1 parent 6c47a70 commit a224f6d
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 80 deletions.
Binary file added vscode-plugin/aifix4seccode-vscode-1.0.13.vsix
Binary file not shown.
100 changes: 52 additions & 48 deletions vscode-plugin/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export function init(

async function openUpFile(patchPath: string) {
logging.LogInfo("===== Executing openUpFile command. =====");

let project_folder = PROJECT_FOLDER;
let patch_folder = PATCH_FOLDER;
if (!PROJECT_FOLDER) {
Expand Down Expand Up @@ -366,7 +366,7 @@ export function init(

logging.LogInfo("Running diagnosis in opened file...");
vscode.workspace.openTextDocument(openFilePath).then((document) => {
vscode.window.showTextDocument(document).then(async() => {
vscode.window.showTextDocument(document).then(async () => {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
Expand All @@ -377,31 +377,36 @@ export function init(
vscode.window.activeTextEditor!.document,
analysisDiagnostics
);
// set selection of warning:
await setIssueSelectionInEditor(patchPath);
// set selection of warning:
await setIssueSelectionInEditor(patchPath);
}
);
});
});
logging.LogInfo("===== Finished openUpFile command. =====");
}

async function setIssueSelectionInEditor(patchPath: string){
async function setIssueSelectionInEditor(patchPath: string) {
await initIssues();
let targetTextRange : any = {};
let targetTextRange: any = {};

Object.values(issues).forEach((issueArrays: any) => {
issueArrays.forEach((issueArray: any) => {
if(issueArray['patches'].some((x: any) => x['path'] === patchPath)){
targetTextRange = issueArray['textRange'];
if (issueArray["patches"].some((x: any) => x["path"] === patchPath)) {
targetTextRange = issueArray["textRange"];
}
})
})
});
});

const editor = vscode.window.activeTextEditor;
const position = editor?.selection.active;

var newSelection = new vscode.Selection(targetTextRange['startLine'] - 1, targetTextRange['startColumn'], targetTextRange['endLine'] - 1, targetTextRange['endColumn']);
var newSelection = new vscode.Selection(
targetTextRange["startLine"] - 1,
targetTextRange["startColumn"],
targetTextRange["endLine"] - 1,
targetTextRange["endColumn"]
);
editor!.selection = newSelection;
}

Expand Down Expand Up @@ -598,7 +603,10 @@ export function init(

vscode.workspace.openTextDocument(openFilePath).then((document) => {
vscode.window.showTextDocument(document).then(() => {
if ("leftPath" in webview.params && "patchPath" in webview.params) {
if (
"leftPath" in webview.params &&
"patchPath" in webview.params
) {
filterOutIssues(webview.params.patchPath!).then(() => {
vscode.window.withProgress(
{
Expand Down Expand Up @@ -635,7 +643,6 @@ export function init(
if ("patchPath" in webview.params && webview.params.patchPath) {
patchPath = webview.params.patchPath;
}
testView.treeDataProvider?.refresh(patchPath);
} else if (ANALYZER_USE_DIFF_MODE == "view Patch files") {
// 1. Get the content of the original file
// 2. Apply the patch to it's content.
Expand Down Expand Up @@ -732,20 +739,18 @@ export function init(

vscode.workspace.openTextDocument(openFilePath).then((document) => {
vscode.window.showTextDocument(document).then(() => {
filterOutIssues(patchPath).then(() => {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Loading Diagnostics...",
},
async () => {
await refreshDiagnostics(
vscode.window.activeTextEditor!.document,
analysisDiagnostics
);
}
);
});
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Loading Diagnostics...",
},
async () => {
await refreshDiagnostics(
vscode.window.activeTextEditor!.document,
analysisDiagnostics
);
}
);
});
});
}
Expand Down Expand Up @@ -783,26 +788,25 @@ export function init(

vscode.commands.executeCommand("setContext", "patchApplyEnabled", false);

filterOutIssues(patchFilepath).then(() => {
testView.treeDataProvider?.refresh(patchFilepath);
vscode.workspace.openTextDocument(sourceFile).then((document) => {
vscode.window.showTextDocument(document).then(() => {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Loading Diagnostics...",
},
async () => {
// 4.
await refreshDiagnostics(
vscode.window.activeTextEditor!.document,
analysisDiagnostics
);
testView.treeDataProvider?.refresh(patchFilepath);

updateUserDecisions("declined", patchFilepath, sourceFile);
}
);
});
vscode.workspace.openTextDocument(sourceFile).then((document) => {
vscode.window.showTextDocument(document).then(() => {
vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: "Loading Diagnostics...",
},
async () => {
// 4.
await refreshDiagnostics(
vscode.window.activeTextEditor!.document,
analysisDiagnostics
);

updateUserDecisions("declined", patchFilepath, sourceFile);
}
);
});
});
}
Expand Down Expand Up @@ -887,7 +891,7 @@ export function init(
if ("leftPath" in activeWebview.params) {
origPath = activeWebview.params.leftPath!;
}
if ("patchPath" in activeWebview.params){
if ("patchPath" in activeWebview.params) {
patchPath = activeWebview.params.patchPath!;
}

Expand Down
24 changes: 19 additions & 5 deletions vscode-plugin/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,35 @@ import { ExecSyncOptionsWithStringEncoding } from 'child_process';
import { workspace } from 'vscode';
import { getRootPath } from './path';
var path = require("path");
var upath = require("upath");
var os = require('os');

export let PROJECT_FOLDER = workspace.getConfiguration().get<string>('aifix4seccode.analyzer.subjectProjectPath');
export var PROJECT_FOLDER = workspace.getConfiguration().get<string>('aifix4seccode.analyzer.subjectProjectPath');

export function SetProjectFolder(path: string){
PROJECT_FOLDER = path;
PROJECT_FOLDER = upath.normalize(path);
PROJECT_FOLDER_LOG = 'plugin.subject_project_path' + '=' + PROJECT_FOLDER + os.EOL;
}

export const PATCH_FOLDER = path.normalize(workspace.getConfiguration().get<string>('aifix4seccode.analyzer.generatedPatchesPath'));
export const ANALYZER_EXE_PATH = path.normalize(workspace.getConfiguration().get<string>('aifix4seccode.analyzer.executablePath'));
// EXTENSION SETTINGS:
export const PATCH_FOLDER = upath.normalize(workspace.getConfiguration().get<string>('aifix4seccode.analyzer.generatedPatchesPath'));
export const ANALYZER_EXE_PATH = upath.normalize(workspace.getConfiguration().get<string>('aifix4seccode.analyzer.executablePath'));
export const ANALYZER_PARAMETERS = workspace.getConfiguration().get<string>('aifix4seccode.analyzer.executableParameters')
export const ANALYZER_USE_DIFF_MODE = workspace.getConfiguration().get<string>('aifix4seccode.analyzer.useDiffMode')
export const ISSUES_PATH = workspace.getConfiguration().get<string>('aifix4seccode.analyzer.issuesPath');
export const ISSUES_PATH = upath.normalize(workspace.getConfiguration().get<string>('aifix4seccode.analyzer.issuesPath'));
export const ANALYZER_MENTION = 'analyzer_mention';
export const ISSUE = 'issue';

// lOGS:
export const LOG_HEADING = '# Vscode-Plugin settings' + os.EOL + os.EOL;
export const ANALYZER_PARAMETERS_LOG = 'plugin.executing_parameters' + '=' + ANALYZER_PARAMETERS + os.EOL;
export const ANALYZER_EXE_PATH_LOG = 'plugin.executable_path' + '=' + ANALYZER_EXE_PATH + os.EOL;
export const PATCH_FOLDER_LOG = 'plugin.generated_patches_path' + '=' + PATCH_FOLDER + os.EOL;
export const ISSUES_PATH_LOG = 'plugin.issues_path' + '=' + ISSUES_PATH + os.EOL;
export var PROJECT_FOLDER_LOG = 'plugin.subject_project_path' + '=' + PROJECT_FOLDER + os.EOL;
export const ANALYZER_USE_DIFF_MODE_LOG = 'plugin.use_diff_mode' + '=' + ANALYZER_USE_DIFF_MODE + os.EOL;


export const UNSAVED_SYMBOL = ' •';
export const fileNotSupported = `The file is not displayed in the editor because it is either binary, uses an unsupported text encoding or it's an empty file`;
export const utf8Stream: ExecSyncOptionsWithStringEncoding = {
Expand Down
26 changes: 16 additions & 10 deletions vscode-plugin/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,18 @@ import { JsonOutlineProvider } from './providers/jsonOutline';
import { initActionCommands } from './language/codeActions';
import * as logging from './services/logging';
import * as constants from './constants';
var fs = require('fs');

var upath = require("upath");
var path = require("path");

var propertiesReader = require('properties-reader');
var properties = propertiesReader(upath.join(path.resolve(__dirname, '..'), 'config.properties'), {writer: { saveSections: true }});

export let analysisDiagnostics = vscode.languages.createDiagnosticCollection('aifix4seccode');

let analysisStatusBarItem : vscode.StatusBarItem;
let redoFixStatusBarItem : vscode.StatusBarItem;

export function activate(context: vscode.ExtensionContext) {

const jsonOutlineProvider = new JsonOutlineProvider(context);
vscode.window.registerTreeDataProvider('jsonOutline', jsonOutlineProvider);

Expand Down Expand Up @@ -73,12 +72,19 @@ export function activate(context: vscode.ExtensionContext) {
}

function saveConfigParameters(){
properties.set('config.executing_parameters', constants.ANALYZER_PARAMETERS);
properties.set('config.executable_path', constants.ANALYZER_EXE_PATH);
properties.set('config.generated_patches_path', constants.PATCH_FOLDER);
properties.set('config.issues_path', constants.ISSUES_PATH);
properties.set('config.subject_project_path', constants.PROJECT_FOLDER);
properties.set('config.use_diff_mode', constants.ANALYZER_USE_DIFF_MODE);
var logger = fs.createWriteStream(upath.normalize(upath.join(constants.ANALYZER_EXE_PATH, 'config.properties')), {flags: 'w'})

logger.write(constants.LOG_HEADING);

logger.write(constants.ANALYZER_PARAMETERS_LOG);
logger.write(constants.ANALYZER_EXE_PATH_LOG);
logger.write(constants.PATCH_FOLDER_LOG);
logger.write(constants.ISSUES_PATH_LOG);

if(!constants.PROJECT_FOLDER || constants.PROJECT_FOLDER === ""){
constants.SetProjectFolder(vscode.workspace.workspaceFolders![0].uri.path);
}

properties.save(upath.join(constants.ANALYZER_EXE_PATH, 'config.properties'));
logger.write(constants.PROJECT_FOLDER_LOG);
logger.write(constants.ANALYZER_USE_DIFF_MODE_LOG);
}
3 changes: 0 additions & 3 deletions vscode-plugin/src/language/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ export async function refreshDiagnostics(
try {
const diagnostics: vscode.Diagnostic[] = [];
initIssues().then(() => {
logging.LogInfo(
"Got issues from analyzer: " + JSON.stringify(issueGroups)
);
// for each issue we create a diagnosctic.
if (issueGroups) {
Object.values(issueGroups).forEach((issues) => {
Expand Down
3 changes: 0 additions & 3 deletions vscode-plugin/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ export function applyPatchToFile(leftPath: string, rightContent: string, patchPa
}
writeFileSync(issuesPath!, issuesStr, utf8Stream);

// refresh:
testView.treeDataProvider?.refresh(patchPath);

// 3.
workspace.openTextDocument(leftPath).then(document => {
window.showTextDocument(document).then(() => {
Expand Down
35 changes: 24 additions & 11 deletions vscode-plugin/src/providers/testView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import * as path from "path";
import { getIssues } from "../services/fakeAiFixCode";
import { objectify } from "tslint/lib/utils";
import { isObjectLiteralExpression } from "typescript";
import { writeFileSync } from "fs";
import { utf8Stream } from "../constants";
var stringify = require("json-stringify");

let tree: any;

Expand Down Expand Up @@ -261,24 +264,34 @@ function getNode(key: any): { key: string } {

function filterTree(patchPath: string) {
Object.keys(tree).forEach((key) => {
// if (tree[key].patches.some((x: any) => x.path === patchPath || patchPath.includes(x.path))) {
// delete tree[key];
// }
//tree[key].patches = tree[key].patches.filter((x) => x.path !== patchPath || !patchPath.includes(x.path));
tree[key].forEach((issue: any) => {
issue.patches.forEach((patch: any) => {
if(patch.path === patchPath || patchPath.includes(patch.path))
{
tree[key].splice(tree[key].indexOf(issue), 1);
if(!tree[key].length){
delete tree[key];
}
issue.patches.splice(issue.patches.indexOf(patch), 1);
if(!issue.patches.length){
tree[key].splice(tree[key].indexOf(issue), 1);
if(!tree[key].length){
delete tree[key];
}
}
}
})
})
// if (!tree[key].patches.length) {
// delete tree[key];
// }
let issuesStr = stringify(tree);
console.log(issuesStr);

let issuesPath: string | undefined = "";
if (
vscode.workspace
.getConfiguration()
.get<string>("aifix4seccode.analyzer.issuesPath")
) {
issuesPath = vscode.workspace
.getConfiguration()
.get<string>("aifix4seccode.analyzer.issuesPath");
}
writeFileSync(issuesPath!, issuesStr, utf8Stream);
});
console.log(tree);
}
Expand Down

0 comments on commit a224f6d

Please sign in to comment.