Skip to content

Commit

Permalink
error form prompt default on; fix error form bugs
Browse files Browse the repository at this point in the history
now the prompt asking whether to show error form is on by default.
also fixed a bunch of bugs having to do with opening the error form
  • Loading branch information
molsonkiko committed Nov 28, 2023
1 parent c8e44c8 commit 783a114
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

1. The way object keys are represented internally has been changed (*this has no effect on the GUI-based API, but only for developers*). Previously, when pretty-printing and compressing JSON, object keys would be output as is (without escaping special characters), meaning that *prior to v6.0, some strings were not valid object keys (again, this did not affect parsing of JSON, but only some programmatic applications that constructed JOBjects directly without parsing).* Now all strings are valid object keys.
2. When using the JSON-to-CSV form to create CSV files, newline characters will no longer be escaped in strings. Instead, strings containing newlines will be wrapped in quotes, which should be sufficient to allow most CSV parsers to handle them correctly.
3. Made [`offer_to_show_lint` setting](/docs/README.md#parser-settings) (which controls whether a prompt is shown when errors are found) true by default, so that a fresh installation will show the prompt.

### Fixed

Expand All @@ -62,6 +63,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3. Fix issues where running a RemesPath query with a projection that referenced a variable indexing on a compile-time constant would cause an error. For example, `var x = @; 1->x` should return `@` (the input to the query), but prior to this fix, it would instead cause an error.
4. Running tests would previously cause clipboard data to be lost irreversably. Now, if the user's clipboard contained text before running tests, the contents of the clipboard are restored to their pre-test values rather than being hijacked. __Non-text data that was copied to the clipboard is still lost when running tests, and I may try to fix that in the future.__
5. `dict` function in RemesPath previously had a bug that could create invalid JSON if the strings to be turned into keys contained special characters (e.g., literal quote chars, `\r`, `\n`).
6. access violations when loading [error form](/docs/README.md#error-form-and-status-bar)
7. unnecessary prompt when manually reloading [error form](/docs/README.md#error-form-and-status-bar)
8. issue with trying to view error form when the error form was already open

## [5.8.0] - 2023-10-09

Expand Down
17 changes: 11 additions & 6 deletions JsonToolsNppPlugin/Forms/ErrorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace JSON_Tools.Forms
public partial class ErrorForm : Form
{
public const int SLOW_RELOAD_THRESHOLD = 300; // completely arbitrary
public const int LINT_ROW_COUNT = 5000;
public const int LINT_MAX_ROW_COUNT = 5000;
public string fname;
public List<JsonLint> lints;

Expand All @@ -28,7 +28,7 @@ public ErrorForm(string fname, List<JsonLint> lints)
FormStyle.ApplyStyle(this, Main.settings.use_npp_styling);
}

public bool SlowReloadExpected(IList<JsonLint> lints) { return lints.Count >= SLOW_RELOAD_THRESHOLD; }
public bool SlowReloadExpected(IList<JsonLint> lints) { return lints is null || lints.Count >= SLOW_RELOAD_THRESHOLD; }

public void Reload(string fname, List<JsonLint> lints, bool onStartup = false)
{
Expand All @@ -50,18 +50,19 @@ public void Reload(string fname, List<JsonLint> lints, bool onStartup = false)
Text = "JSON errors in current file";
ErrorGrid.Rows.Clear();
int interval = 1;
int lintCount = lints is null ? 0 : lints.Count;
// add a row that warns not all rows are shown
if (LINT_ROW_COUNT < lints.Count)
if (LINT_MAX_ROW_COUNT < lintCount)
{
interval = lints.Count / LINT_ROW_COUNT;
interval = lintCount / LINT_MAX_ROW_COUNT;
var warningNotAllRowsShown = new DataGridViewRow();
warningNotAllRowsShown.CreateCells(ErrorGrid);
warningNotAllRowsShown.Cells[1].Value = $"Showing approximately {LINT_ROW_COUNT} of {lints.Count} rows";
warningNotAllRowsShown.Cells[1].Value = $"Showing approximately {LINT_MAX_ROW_COUNT} of {lintCount} rows";
ErrorGrid.Rows.Add(warningNotAllRowsShown);
}
int ii = 0;
int cycler = 0;
while (ii < lints.Count)
while (ii < lintCount)
{
var lint = lints[ii];
var row = new DataGridViewRow();
Expand Down Expand Up @@ -148,7 +149,11 @@ private void ErrorForm_KeyDown(object sender, KeyEventArgs e)
{
// refresh error form based on current contents of current file
e.Handled = true;
// temporarily turn off offer_to_show_lint prompt, because the user obviously wants to see it
bool previousOfferToShowLint = Main.settings.offer_to_show_lint;
Main.settings.offer_to_show_lint = false;
Main.TryParseJson();
Main.settings.offer_to_show_lint = previousOfferToShowLint;
if (Main.TryGetInfoForFile(Main.activeFname, out JsonFileInfo info)
&& info.lints != null)
Reload(Main.activeFname, info.lints);
Expand Down
8 changes: 5 additions & 3 deletions JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,24 +576,26 @@ public static (bool fatal, JNode node, bool usesSelections, DocumentType Documen
SelectionManager.SetSelectionsFromStartEnds(oldSelections);
return TryParseJson(documentType, wasAutotriggered, true);
}
int lintCount = lints.Count;
int lintCount = lints is null ? 0 : lints.Count;
info = AddJsonForFile(fname, json);
bool fatal = errorMessage != null;
info.documentType = fatal ? DocumentType.NONE : documentType;
if (stopUsingSelections)
info.usesSelections = false;
else
info.usesSelections |= !noTextSelected;
info.lints = lints;
if (lintCount > 0 && settings.offer_to_show_lint)
{
string msg = $"There were {lintCount} syntax errors in the document. Would you like to see them?";
string msg = $"There were {lintCount} syntax errors in the document. Would you like to see them?\r\n(You can turn off these prompts in the settings (offer_to_show_lint setting))";
if (MessageBox.Show(msg, "View syntax errors in document?", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
== DialogResult.Yes)
{
if (errorForm != null)
Npp.notepad.HideDockingForm(errorForm);
OpenErrorForm(activeFname, true);
}
}
info.lints = lints;
if (fatal)
{
// unacceptable error, show message box
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("5.8.0.10")]
[assembly: AssemblyFileVersion("5.8.0.10")]
[assembly: AssemblyVersion("5.8.0.11")]
[assembly: AssemblyFileVersion("5.8.0.11")]
3 changes: 3 additions & 0 deletions JsonToolsNppPlugin/Tests/UserInterfaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ public static bool Test()
int previousMaxTrackedJsonSelections = Main.settings.max_tracked_json_selections;
bool previousRememberComments = Main.settings.remember_comments;
bool previousHasWarnedSelectionsForgotten = Main.hasWarnedSelectionsForgotten;
bool previousOfferToShowLint = Main.settings.offer_to_show_lint;
// remember what the user's clipboard was before tests start, because the tests hijack the clipboard and that's not nice
string clipboardValueBeforeTests = Clipboard.GetText();
// require these settings for the UI tests alone
Expand All @@ -619,6 +620,7 @@ public static bool Test()
Main.settings.minimal_whitespace_compression = true;
Main.settings.max_tracked_json_selections = 1000;
Main.settings.remember_comments = false;
Main.settings.offer_to_show_lint = false;
// if this is false, a message-box will pop up at some point.
// this message box doesn't block the main thread, but it introduces some asynchronous behavior
// that was probably responsible for crashing the UI tests
Expand Down Expand Up @@ -686,6 +688,7 @@ public static bool Test()
Main.settings.max_tracked_json_selections = previousMaxTrackedJsonSelections;
Main.settings.remember_comments = previousRememberComments;
Main.hasWarnedSelectionsForgotten = previousHasWarnedSelectionsForgotten;
Main.settings.offer_to_show_lint = previousOfferToShowLint;
// if the user's clipboard is still set to whatever we most recently hijacked it with, reset it to whatever it was before the tests
// this won't work if their clipboard contained non-text data beforehand, but it's better than nothing
if (Clipboard.GetText() == lastClipboardValue && !(clipboardValueBeforeTests is null) && clipboardValueBeforeTests.Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion JsonToolsNppPlugin/Utils/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class Settings : SettingsBase
public LoggerLevel logger_level { get; set; }

[Description("When the document is parsed, show a prompt to see syntax errors in the document."),
Category("JSON Parser"), DefaultValue(false)]
Category("JSON Parser"), DefaultValue(true)]
public bool offer_to_show_lint { get; set; }

[Description("Parse \"yyyy-mm-dd dates\" and \"yyyy-MM-dd hh:mm:ss.sss\" datetimes as the appropriate type."),
Expand Down

0 comments on commit 783a114

Please sign in to comment.