Skip to content

Commit

Permalink
Don't reopen hidden error form on auto-parse
Browse files Browse the repository at this point in the history
Previously the automatic JSON schema validation on file opening and automatic parse after editing features
    would make the error form visible even if the user had hidden it.
I found this very annoying when working with documents with a lot of errors,
    so now those features only refresh the error form if it was already visible.
  • Loading branch information
molsonkiko committed Dec 13, 2024
1 parent 43f105c commit 34d3853
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

1. Use a different algorithm for representing decimal numbers to fix issues [83](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/83) and [81](https://github.com/molsonkiko/JsonToolsNppPlugin/issues/81) on computers where v8.2 had not fixed those issues.
- As an unfortunate consequence of this fix, a *very very small percentage of very high-precision decimal numbers will lose precision* using this new algorithm. The vast majority of numbers with 17 digits of precision (the maximum precision attainable by JsonTools) will not lose precision when reformatted by JsonTools. For example, JsonTools will pretty-print `-6553693.3617752995` as the lower-precision `-6553693.3617753`. However, note that [JsonTools still handles high-precision doubles *better than the JSON-Viewer plugin*](https://github.com/NPP-JSONViewer/JSON-Viewer/issues/196).
2. [Automatic parsing after editing](/docs/README.md#automatically-check-for-errors-after-editing) and [automatic JSON schema validation on opening a file](/docs/README.md#automatic-validation-of-json-against-json-schema) no longer makes the error form visible if the user had previously opened the error form and then hid it.

### Fixed

Expand Down
8 changes: 3 additions & 5 deletions JsonToolsNppPlugin/JSONTools/JNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -404,11 +404,9 @@ public static void StrToSb(StringBuilder sb, string s)
}

/// <summary>
/// Let <c>d17</c> = d.ToString("G17", <see cref="JNode.DOT_DECIMAL_SEP"/>) (which can always be parsed to regenerate a double equal to <c>d</c>)<br></br>
/// and let <c>d15</c> = d.ToString(<see cref="JNode.DOT_DECIMAL_SEP"/>) (which only keeps 15 digits of precision)<br></br>
/// Returns <c>d</c> formatted with up to 17 digits of precision, using '.' as the decimal separator.<br></br>
/// If <c>d17</c> includes 17 digits of precision, we will generate <c>d15</c>.<br></br>
/// If <c>d15</c> is shorter than <c>d17</c>, and if (<c>double.Parse(d15) == d</c>, we will prefer <c>d15</c> because <c>d17</c> was an unncessarily verbose representation of <c>d</c>.
/// Format a valid double as a string.<br></br>
/// This method should not be used on NaN or number greater than <see cref="double.MaxValue"/> or less than <see cref="double.MinValue"/>,<br></br>
/// so all code should handle those possibilities before invoking this method.
/// </summary>
/// <param name="d"></param>
/// <returns></returns>
Expand Down
16 changes: 10 additions & 6 deletions JsonToolsNppPlugin/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ public static void CheckJsonSyntaxNow()
string curFname = Npp.notepad.GetCurrentFilePath();
(ParserState parserState, _, _, _) = TryParseJson(Npp.FileExtension(curFname) == "jsonl" ? DocumentType.JSONL : DocumentType.JSON);
if (errorForm != null && errorForm.Visible && !settings.offer_to_show_lint)
RefreshErrorFormInOwnThread(curFname);
RefreshErrorFormInOwnThread(curFname, false);
}

/// <summary>
Expand Down Expand Up @@ -1367,13 +1367,17 @@ private static void DisplayErrorForm(ErrorForm form)
Npp.notepad.ShowDockingForm(form);
}

private static void RefreshErrorFormInOwnThread(string fname)
/// <summary>
/// If <paramref name="suppressIfFormNotVisible"/> and the errorForm is not visible, this is a no-op.<br></br>
/// Otherwise, make the error form visible and then refresh it.
/// </summary>
private static void RefreshErrorFormInOwnThread(string fname, bool suppressIfFormNotVisible)
{
if (errorForm == null)
return;
errorForm.Invoke(new Action(() =>
{
if (errorForm.IsDisposed || !TryGetInfoForFile(fname, out JsonFileInfo info) || info.lints == null)
if (errorForm.IsDisposed || (suppressIfFormNotVisible && !errorForm.Visible) || !TryGetInfoForFile(fname, out JsonFileInfo info) || info.lints == null)
return;
errorForm.Reload(fname, info.lints);
}));
Expand Down Expand Up @@ -1669,7 +1673,7 @@ public static void ValidateJson(string schemaPath = null, bool messageOnSuccess
string curFname = Npp.notepad.GetCurrentFilePath();
if (parserState == ParserState.FATAL || json == null)
{
RefreshErrorFormInOwnThread(curFname);
RefreshErrorFormInOwnThread(curFname, wasAutotriggered);
return;
}
if (schemaPath == null)
Expand Down Expand Up @@ -1705,7 +1709,7 @@ public static void ValidateJson(string schemaPath = null, bool messageOnSuccess
info.filenameOfMostRecentValidatingSchema = schemaPath;
info.lints = info.lints is null ? problems : info.lints.Concat(problems).ToList();
int lintCount = info.lints.Count;
RefreshErrorFormInOwnThread(curFname);
RefreshErrorFormInOwnThread(curFname, wasAutotriggered);
SetStatusBarSection(parserState, curFname, info, documentType, lintCount);
if (!validates && problems.Count > 0)
{
Expand Down Expand Up @@ -2140,7 +2144,7 @@ private static void DelayedParseAfterEditing(object s)
return;
// filename matches but it's not associated with a schema or being parsed as non-JSON/JSONL, so just parse normally
TryParseJson(ext == "jsonl" ? DocumentType.JSONL : DocumentType.JSON, true, ignoreSelections:true);
RefreshErrorFormInOwnThread(fname);
RefreshErrorFormInOwnThread(fname, true);
}
#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions JsonToolsNppPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("8.2.0.3")]
[assembly: AssemblyFileVersion("8.2.0.3")]
[assembly: AssemblyVersion("8.2.0.4")]
[assembly: AssemblyFileVersion("8.2.0.4")]

0 comments on commit 34d3853

Please sign in to comment.