Skip to content

Commit

Permalink
show multi JSON schema val problems in error form
Browse files Browse the repository at this point in the history
JSON Schema validation now can find multiple validation problems.
In addition, the error form now displays validation problems
    alongside syntax errors.
Hitting Enter while the error form is focused now re-validates
    the file according the the last used JSON schema
    after re-parsing it.
  • Loading branch information
molsonkiko committed Feb 1, 2024
1 parent 839c124 commit cce38a5
Show file tree
Hide file tree
Showing 14 changed files with 500 additions and 366 deletions.
16 changes: 9 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### To Be Added

1. Show multiple schema validation problems.
2. Add configurable startup actions for grepper form. Might look like
```json
// grepperFormStartupActions.json
Expand Down Expand Up @@ -40,6 +39,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### To Be Fixed

- Make sure there aren't any easily-triggered race conditions induced by [automatic parsing and validation after editing](/docs/README.md#automatically-check-for-errors-after-editing).
- It seems like there may be a bug (haven't been able to reproduce it recently) where under some conditions, [automatic validation after editing](/docs/README.md#automatically-check-for-errors-after-editing) causes an endless loop where the document is re-validated over and over again for no apparent reason.
- Fix issue where pretty-printing or compressing causes tree view position tracking to be out of sync with the document until a query is issued or the `Refresh` button is hit.
- Improve Alt-key accelerators *in forms*. They don't seem to work right for some reason.
- When a tree viewer is refreshed using JSON from a file with a different name, the title of the docking form that the user sees doesn't change to reflect the new file. For example, a tree viewer is opened up for `foo.json` and then refreshed with a buffer named `bar.json`, and the title of the docking form still reads `Json Tree View for foo.json`.
Expand All @@ -64,12 +65,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

1. The [`ifelse` vectorized function in RemesPath](/docs/RemesPath.md#vectorized-functions) now uses conditional execution.
2. Default value for [`sort_keys` setting](/docs/README.md#sort_keys) is now `false`, meaning keys are left in their original order by default. This will not change existing settings.
3. Add optional arguments [to `stringify` non-vectorized function in RemesPath](/docs/RemesPath.md#non-vectorized-functions), so that users can control the format of the output.
4. Make dark mode icons darker.
5. *This change only affects the code base, not the public API:* changed almost all snake_case variable names to camelCase. [RemesPath functions still use snake_case](/JsonToolsNppPlugin/JSONTools/RemesPathFunctions.cs) (e.g., `s_mul` and `group_by` still have those names), and all the settings in [Settings.cs](/JsonToolsNppPlugin/Utils/Settings.cs) (e.g., `use_npp_styling`) that were previously snake_case are still snake_case.
6. __All [RemesPath regular expressions](/docs/RemesPath.md#regular-expressions) are now multiline__, meaning that `^` and `$` now match the start and end of *lines* respectively, rather than the start and end of the *document.*
1. __Support for multiple [JSON schema validation problems](/docs/README.md#validating-json-against-json-schema)__
2. __All [RemesPath regular expressions](/docs/RemesPath.md#regular-expressions) are now multiline__, meaning that `^` and `$` now match the start and end of *lines* respectively, rather than the start and end of the *document.*
3. The [`ifelse` vectorized function in RemesPath](/docs/RemesPath.md#vectorized-functions) now uses conditional execution.
4. Default value for [`sort_keys` setting](/docs/README.md#sort_keys) is now `false`, meaning keys are left in their original order by default. This will not change existing settings.
5. Add optional arguments [to `stringify` non-vectorized function in RemesPath](/docs/RemesPath.md#non-vectorized-functions), so that users can control the format of the output.
5. Make dark mode icons darker.
6. *This change only affects the code base, not the public API:* changed almost all snake_case variable names to camelCase. [RemesPath functions still use snake_case](/JsonToolsNppPlugin/JSONTools/RemesPathFunctions.cs) (e.g., `s_mul` and `group_by` still have those names), and all the settings in [Settings.cs](/JsonToolsNppPlugin/Utils/Settings.cs) (e.g., `use_npp_styling`) that were previously snake_case are still snake_case.

### Fixed

Expand Down
11 changes: 9 additions & 2 deletions JsonToolsNppPlugin/Forms/ErrorForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void ExportLintsToJsonMenuItem_Click(object sender, EventArgs e)
}

/// <summary>
/// hitting enter refreshes<br></br>
/// hitting enter re-parses the current file (and re-validates using JSON schema if it had been validated) refreshes<br></br>
/// Hitting escape moves focus to the Notepad++ editor<br></br>
/// hitting the first letter of any error description goes to that error description
/// </summary>
Expand All @@ -181,14 +181,21 @@ private void ErrorForm_KeyDown(object sender, KeyEventArgs e)
{
// refresh error form based on current contents of current file
e.Handled = true;
if (Main.parseTimerIsWorking)
return; // avoid race conditions
// 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(preferPreviousDocumentType:true);
Main.settings.offer_to_show_lint = previousOfferToShowLint;
if (Main.TryGetInfoForFile(Main.activeFname, out JsonFileInfo info)
&& info.lints != null)
Reload(Main.activeFname, info.lints);
{
if (info.filenameOfMostRecentValidatingSchema is null)
Reload(Main.activeFname, info.lints);
else
Main.ValidateJson(info.filenameOfMostRecentValidatingSchema, false);
}
return;
}
else if (e.KeyCode == Keys.Escape)
Expand Down
10 changes: 5 additions & 5 deletions JsonToolsNppPlugin/Forms/RegexSearchForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public RegexSearchForm()
"\t\t\t}\r\n" +
"\t\t}\r\n" +
"\t]\r\n" +
"}")
);
"}"),
0);
}

public void GrabFocus()
Expand Down Expand Up @@ -174,11 +174,11 @@ public void ParseAsCsvCheckBox_CheckedChanged(object sender, EventArgs e)
/// <param name="wasCalledByUser">was this invoked by a user (if true, show a message box if there's an issue)</param>
public bool SetFieldsFromJson(JNode settingsNode, bool wasCalledByUser, out string errorMessage)
{
var vp = settingsValidator(settingsNode);
bool validates = settingsValidator(settingsNode, out List<JsonLint> lints);
errorMessage = null;
if (vp != null)
if (!validates)
{
errorMessage = $"invalid settings {settingsNode.ToString()}, got validation problem {vp}";
errorMessage = $"invalid settings {settingsNode.ToString()}, got validation problem(s) {JsonSchemaValidator.LintsAsJArrayString(lints)}";
if (wasCalledByUser)
MessageBox.Show(errorMessage,
"invalid settings",
Expand Down
13 changes: 13 additions & 0 deletions JsonToolsNppPlugin/JSONTools/JsonParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,23 @@ public override string ToString()
public struct JsonLint
{
public string message;
/// <summary>
/// the position of the error in the UTF-8 encoding of the document
/// </summary>
public int pos;
/// <summary>
/// the UTF-16 character where the error began
/// </summary>
public char curChar;
public ParserState severity;

/// <summary>
///
/// </summary>
/// <param name="message"></param>
/// <param name="pos">the position of the error in the UTF8 encoding of the JSON document</param>
/// <param name="curChar">the UTF-16 character where the error began</param>
/// <param name="severity"></param>
public JsonLint(string message, int pos, char curChar, ParserState severity)
{
this.message = message;
Expand Down
Loading

0 comments on commit cce38a5

Please sign in to comment.