Skip to content

Commit

Permalink
Removed Newtonsoft.Json dependency and some fixes. (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmahend1 authored Jan 31, 2024
1 parent 32480e8 commit 61fdf43
Show file tree
Hide file tree
Showing 15 changed files with 83 additions and 67 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## Stable

### 4.0.0: 31-Jan-2024

- Removed Newtonsoft.Json dependency.
- Yarn upgrades.
- Fixed an issue where errors where not shown to users.

### 3.8.0: 21-Dec-2023

- Yarn upgrades
Expand Down
Binary file removed lib/Newtonsoft.Json.dll
Binary file not shown.
16 changes: 0 additions & 16 deletions lib/XmlFormatter.CommandLine.deps.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,12 @@
".NETCoreApp,Version=v6.0": {
"XmlFormatter.CommandLine/1.0.0": {
"dependencies": {
"Newtonsoft.Json": "13.0.3",
"XmlFormatter": "1.0.0"
},
"runtime": {
"XmlFormatter.CommandLine.dll": {}
}
},
"Newtonsoft.Json/13.0.3": {
"runtime": {
"lib/net6.0/Newtonsoft.Json.dll": {
"assemblyVersion": "13.0.0.0",
"fileVersion": "13.0.3.27908"
}
}
},
"XmlFormatter/1.0.0": {
"runtime": {
"XmlFormatter.dll": {}
Expand All @@ -36,13 +27,6 @@
"serviceable": false,
"sha512": ""
},
"Newtonsoft.Json/13.0.3": {
"type": "package",
"serviceable": true,
"sha512": "sha512-HrC5BXdl00IP9zeV+0Z848QWPAoCr9P3bDEZguI+gkLcBKAOxix/tLEAAHC+UvDNPv4a2d18lOReHMOagPa+zQ==",
"path": "newtonsoft.json/13.0.3",
"hashPath": "newtonsoft.json.13.0.3.nupkg.sha512"
},
"XmlFormatter/1.0.0": {
"type": "project",
"serviceable": false,
Expand Down
Binary file modified lib/XmlFormatter.CommandLine.dll
Binary file not shown.
Binary file added lib/XmlFormatter.CommandLine.exe
Binary file not shown.
Binary file modified lib/XmlFormatter.CommandLine.pdb
Binary file not shown.
Binary file modified lib/XmlFormatter.dll
Binary file not shown.
Binary file modified lib/XmlFormatter.pdb
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"readme": "https://github.com/pmahend1/PrettyXML/blob/main/README.md",
"description": "XML formatter extension for Visual Studio Code. Formats XML documents just like Visual Studio.",
"version": "3.8.0",
"version": "4.0.0",
"publisher": "PrateekMahendrakar",
"repository": {
"url": "https://github.com/pmahend1/prettyxml.git"
Expand Down
26 changes: 16 additions & 10 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ export function activate(context: vscode.ExtensionContext): void {
Logger.instance.warning("Invalid languageId");
}
}
catch (exception) {
let errorMessage = (exception as Error)?.message;
Logger.instance.error(exception as Error);
vscode.window.showErrorMessage(errorMessage);
console.error(exception);
catch (error) {
if (error instanceof Error) {
Logger.instance.error(error);
vscode.window.showErrorMessage(error.message);
console.error(error);
}
}
Logger.instance.info("vscode.workspace.onWillSaveTextDocument end");
});
Expand All @@ -70,11 +71,16 @@ export function activate(context: vscode.ExtensionContext): void {
minimizeXmlCommand,
languageProvider);
}
catch (exception) {
let errorMessage = (exception as Error)?.message;
vscode.window.showErrorMessage(errorMessage);
Logger.instance.error(exception as Error);
console.error(exception);
catch (error) {
if (error instanceof Error) {
vscode.window.showErrorMessage(error.message);
Logger.instance.error(error);
}
else if (typeof error === "string") {
vscode.window.showErrorMessage(error);
Logger.instance.warning(error);
}
console.error(error);
}
}

Expand Down
18 changes: 12 additions & 6 deletions src/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ export class Formatter {
Logger.instance.info(`dllPath : ${this.dllPath}`);
}
catch (error) {
Logger.instance.error(error as Error);
throw error;
if (error instanceof Error) {
Logger.instance.error(error);
throw error;
}
}
}

Expand Down Expand Up @@ -134,11 +136,11 @@ export class Formatter {
let promise = new Promise<string>((resolve, reject) => {
cli.on("close", (exitCode: Number) => {
if (exitCode !== 0) {
Logger.instance.warning(`childProcess errored with exitCode ${ exitCode }`);
Logger.instance.warning(`childProcess errored with exitCode ${exitCode}`);
reject(stdErrData);
}
else {
Logger.instance.info(`childProcess stdOutData: ${ stdOutData }`);
Logger.instance.info(`childProcess stdOutData: ${stdOutData}`);
resolve(stdOutData);
}
});
Expand All @@ -148,8 +150,12 @@ export class Formatter {
return promise;
}
catch (error) {
let err = error as Error;
Logger.instance.error(err);
if (error instanceof Error) {
Logger.instance.error(error);
}
else if (typeof error === "string") {
Logger.instance.warning(error);
}
Logger.instance.warning("Error formatting with command line. Make sure you have dotnet 6+ installed and it is added to PATH.");
throw new Error('Error formatting with command line. Make sure you have dotnet 6+ installed and it is added to PATH.');
}
Expand Down
35 changes: 18 additions & 17 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,44 @@ import * as vscode from "vscode";
import { DocumentHelper } from "./documentHelper";
import { Logger } from "./logger";

export function replaceDocumentTextWithProgressForCallback(progressText: string, task: Thenable<string>): Thenable<void>
{
export function replaceDocumentTextWithProgressForCallback(progressText: string, task: Thenable<string>): Thenable<void> {
Logger.instance.info("replaceDocumentTextWithProgressForCallback start");
var progressOptions = {
location: vscode.ProgressLocation.Notification,
title: "Pretty XML",
cancellable: false,
};

var progressPromise = vscode.window.withProgress(progressOptions, (progress) =>
{
var promise = new Promise<void>((resolve, reject) =>
{
var progressPromise = vscode.window.withProgress(progressOptions, (progress) => {
var promise = new Promise<void>((resolve, reject) => {
progress.report({ message: progressText, increment: 0 });

setTimeout(() =>
{
setTimeout(() => {
progress.report({ message: progressText, increment: 25 });
}, 100);
}, 50);

setTimeout(async () =>
{
try
{
setTimeout(async () => {
try {
var newText = await task;
progress.report({ message: progressText, increment: 75 });

DocumentHelper.replaceDocumentText(newText);
progress.report({ message: progressText, increment: 100 });
resolve();
}
catch (error)
{
Logger.instance.error(error as Error);
catch (error) {
if (typeof error === "string") {
Logger.instance.warning(`Errored with ${error}`);
if (error.includes("System.Xml.XmlException: Unexpected end of file has occurred.")) {
var userReadableErrorMessage = error.replace("System.Xml.XmlException: Unexpected end of file has occurred.","").replace("Unhandled exception. System.Xml.XmlException: ","").replace("Unhandled exception. ", "");
vscode.window.showErrorMessage(userReadableErrorMessage);
} else {
vscode.window.showErrorMessage(error);
}
}
reject(error);
}
}, 250);
}, 100);
});

return promise;
Expand Down
20 changes: 13 additions & 7 deletions src/notificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export class NotificationService {
}
}
catch (error) {
Logger.instance.error(error as Error);
console.error(error);
if (error instanceof Error) {
Logger.instance.error(error);
console.error(error);
}
}
Logger.instance.info("checkIfEligibleToShowUpdateNote end");
return shouldDisplay;
Expand All @@ -52,8 +54,10 @@ export class NotificationService {
}
}
catch (error) {
Logger.instance.error(error as Error);
console.error(error);
if (error instanceof Error) {
Logger.instance.error(error);
console.error(error);
}
}
Logger.instance.info("notifyWhatsNewInUpdateAsync end");
}
Expand Down Expand Up @@ -97,8 +101,10 @@ export class NotificationService {
}
}
catch (error) {
Logger.instance.error(error as Error);
console.error(error);
if (error instanceof Error) {
Logger.instance.error(error);
console.error(error);
}
}
Logger.instance.info("promptForReviewAsync end");
}
Expand Down Expand Up @@ -127,7 +133,7 @@ export class NotificationService {
let lastUsedDate = this.context.globalState.get(lastUsedDateKey) as Date;

if (lastUsedDate) {
var delayedLastDate = lastUsedDate;
var delayedLastDate = new Date(lastUsedDate);
delayedLastDate.setHours(delayedLastDate.getHours() + 2);
if (new Date() >= delayedLastDate) {
await this.promptForReviewAsync();
Expand Down
21 changes: 14 additions & 7 deletions src/prettyXmlFormattingEditProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class PrettyXmlFormattingEditProvider implements DocumentFormattingEditPr
setTimeout(() => {
progress.report({ message: "Formatting...", increment: 25 });

}, 100);
}, 50);

setTimeout(async () => {
try {
Expand All @@ -67,10 +67,9 @@ export class PrettyXmlFormattingEditProvider implements DocumentFormattingEditPr
progress.report({ message: "Formatting...", increment: 100 });
}
catch (error) {
Logger.instance.error(error as Error);
return reject(error);
reject(error); //log in outer catch block
}
}, 250);
}, 100);
});

return promise;
Expand All @@ -80,9 +79,17 @@ export class PrettyXmlFormattingEditProvider implements DocumentFormattingEditPr
return resolve([replacer]);
}
catch (error) {
Logger.instance.error(error as Error);
console.error(error);
Logger.instance.info("provideDocumentFormattingEdits start");
var errorMessage: string = "";
if (typeof error === "string") {
errorMessage = error;
Logger.instance.warning(errorMessage);
}
else if (error instanceof Error) {
Logger.instance.error(error);
errorMessage = error.message;
}
vscode.window.showErrorMessage(errorMessage);

return resolve([]);
}
});
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@
integrity sha512-wANk6fBrUwdpY4isjWrKTufkrXdu1D2YHCot2fD/DfWxF5sMrVSA+KN7ydckvaTCh0HiqX9IVl0L5/ZoXg5M7w==

"@types/node@^16.4.13":
version "16.18.68"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.68.tgz#3155f64a961b3d8d10246c80657f9a7292e3421a"
integrity sha512-sG3hPIQwJLoewrN7cr0dwEy+yF5nD4D/4FxtQpFciRD/xwUzgD+G05uxZHv5mhfXo4F9Jkp13jjn0CC2q325sg==
version "16.18.77"
resolved "https://registry.yarnpkg.com/@types/node/-/node-16.18.77.tgz#85b3b0a7026d9c9caea0e201c78b4433b876ae55"
integrity sha512-zwqAbRkHjGlxH9PBv8i9dmeaDpBRgfQDSFuREMF2Z+WUi8uc13gfRquMV/8LxBqwm+7jBz+doTVkEEA1CIWOnQ==

"@types/vscode@^1.59.0":
version "1.85.0"
Expand Down

0 comments on commit 61fdf43

Please sign in to comment.