From e590fabce1d7ba25d8d6650a8cd7c5eb6fb00d54 Mon Sep 17 00:00:00 2001
From: andy bunce <bunce.andy@gmail.com>
Date: Fri, 24 Feb 2023 12:10:21 +0000
Subject: [PATCH] [mod] downgrade errors from current xqlint defects

---
 .vscode/settings.json                         |   3 +-
 CHANGELOG.md                                  |   6 +-
 package.json                                  | 111 +++++++++++-------
 scripts/spawn.js                              |  20 ++++
 snippets.jsonc                                |   2 +-
 src/@quodatum/xqlint.d.ts                     |  20 +++-
 src/common/configuration.ts                   |   4 +
 .../xquery-completion-item-provider.ts        |   2 +-
 src/linting/xquery-linter.ts                  |  18 ++-
 src/test/test-data/simple-execute.xq          |   2 +
 .../commands/executeXQuery.ts                 |   7 +-
 11 files changed, 129 insertions(+), 66 deletions(-)
 create mode 100644 scripts/spawn.js
 create mode 100644 src/test/test-data/simple-execute.xq

diff --git a/.vscode/settings.json b/.vscode/settings.json
index 254012f..d137133 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -5,6 +5,5 @@
     },
     "search.exclude": {
         "out": true // set this to false to include "out" folder in search results
-    },
-    "basexTools.xquery.showHovers": false
+    }
 }
\ No newline at end of file
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c535205..f689721 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,7 @@
-# 0.1.1 (2023-02-21)
-* Add Hover show option
+# 0.1.1 (2023-02-24)
+* Add setting to control "Hover show"
+* Add setting to filter out matching diagnostic messages
+
 # 0.1.0 (2023-02-19)
 * Update xqlint to 0.2.0
 
diff --git a/package.json b/package.json
index eb4cef3..05b49ec 100644
--- a/package.json
+++ b/package.json
@@ -70,57 +70,32 @@
       }
     ],
     "configuration": [
+
       {
-        "id": "xmltree",
-        "title": "XML tree view ",
-        "properties": {
-          "basexTools.xmlTree.enableTreeView": {
-            "type": "boolean",
-            "default": false,
-            "description": "Enables the XML Document view in the explorer for XML documents.",
-            "scope": "window"
-          },
-          "basexTools.xmlTree.enableViewMetadata": {
-            "type": "boolean",
-            "default": true,
-            "description": "Enables attribute and child element counts in the XML Document view.",
-            "scope": "window"
-          },
-          "basexTools.xmlTree.enableViewCursorSync": {
-            "type": "boolean",
-            "default": false,
-            "description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
-            "scope": "window"
-          }
-        }
-      },
-      {
-        "id": "xpath",
-        "title": "XPath ",
-        "properties": {
-          "basexTools.xpath.ignoreDefaultNamespace": {
-            "type": "boolean",
-            "default": true,
-            "description": "Ignore default xmlns attributes when evaluating XPath.",
-            "scope": "window"
-          },
-          "basexTools.xpath.persistXPathQuery": {
-            "type": "boolean",
-            "default": true,
-            "description": "Remember the last XPath query used.",
-            "scope": "window"
-          }
-        }
-      },
-      {
-        "id": "xquery",
-        "title": "XQuery ",
+        "id": "xqueryui",
+        "order": 1,
+        "title": "XQuery UI",
         "properties": {
           "basexTools.xquery.showHovers": {
               "type": "boolean",
               "default": false,
-              "description": "Show hovers in xquery."
+              "description": "Show hovers in xquery. Currently these show just Diagnostic info"
           },
+          "basexTools.xquery.suppressErrors": {
+            "type": "array",
+            "default": [
+              "[XQST0059]",
+              "[XPST0008]"
+            ],
+            "description": "Error messages including these strings are marked as info rather than error. TEMP HACK! "
+        }
+        }
+      },
+      {
+        "id": "xqueryexec",
+        "order": 2,
+        "title": "XQuery Execute",
+        "properties": {
           "basexTools.xquery.executionArguments": {
             "type": "array",
             "default": [
@@ -154,8 +129,29 @@
           }
         }
       },
+      {
+        "id": "xpath",
+        "order": 3,
+        "title": "XPath ",
+        "properties": {
+          "basexTools.xpath.ignoreDefaultNamespace": {
+            "type": "boolean",
+            "default": true,
+            "description": "Ignore default xmlns attributes when evaluating XPath.",
+            "scope": "window"
+          },
+          "basexTools.xpath.persistXPathQuery": {
+            "type": "boolean",
+            "default": true,
+            "description": "Remember the last XPath query used.",
+            "scope": "window"
+          }
+        }
+      },
+
       {
         "title": "XML edit ",
+        "order": 4,
         "type": "object",
         "properties": {
           "basexTools.xml.enforcePrettySelfClosingTagOnFormat": {
@@ -193,6 +189,31 @@
             "scope": "window"
           }
         }
+      },
+      {
+        "id": "xmltree",
+        "order": 5,
+        "title": "XML tree view ",
+        "properties": {
+          "basexTools.xmlTree.enableTreeView": {
+            "type": "boolean",
+            "default": false,
+            "description": "Enables the XML Document view in the explorer for XML documents.",
+            "scope": "window"
+          },
+          "basexTools.xmlTree.enableViewMetadata": {
+            "type": "boolean",
+            "default": true,
+            "description": "Enables attribute and child element counts in the XML Document view.",
+            "scope": "window"
+          },
+          "basexTools.xmlTree.enableViewCursorSync": {
+            "type": "boolean",
+            "default": false,
+            "description": "Enables auto-reveal of elements in the XML Document view when a start tag is clicked in the editor.",
+            "scope": "window"
+          }
+        }
       }
     ],
     "grammars": [
diff --git a/scripts/spawn.js b/scripts/spawn.js
new file mode 100644
index 0000000..3cae00d
--- /dev/null
+++ b/scripts/spawn.js
@@ -0,0 +1,20 @@
+function Process() {
+    // eslint-disable-next-line @typescript-eslint/no-var-requires
+    const process = require('child_process'); 
+    var output='';  
+    var ls = process.spawn('basex.bat',["current-dateTime()"]);
+    ls.stdout.on('data', function (data) {
+      output+=data;
+    });
+    ls.stderr.on('data', function (data) {
+      console.log(data);
+    });
+    ls.on('close', function (code) {
+       if (code == 0)
+            console.log(output);
+       else
+            console.log('Error',code);
+    });
+}
+
+Process();
diff --git a/snippets.jsonc b/snippets.jsonc
index 2149379..0967cfd 100644
--- a/snippets.jsonc
+++ b/snippets.jsonc
@@ -33,7 +33,7 @@
 			"${3:expr}",
 			"};"
 		],
-		"description": "declare a function"
+		"description": "declare  function"
 	},
 	"declare variable": {
 		"prefix": "dv",
diff --git a/src/@quodatum/xqlint.d.ts b/src/@quodatum/xqlint.d.ts
index c492d7d..73130d9 100644
--- a/src/@quodatum/xqlint.d.ts
+++ b/src/@quodatum/xqlint.d.ts
@@ -1,20 +1,28 @@
 
 declare module '@quodatum/xqlint'{
-  import { Position } from "vscode";
+  import { Position, Range } from "vscode";
     export class  XQLint{
         constructor(source :string, opts? :object);
-        public getCompletions(pos :object): [object];
+        public getCompletions(pos :Position): [object];
         public getXQDoc() :XQDoc;
         public getAST(pos? :Position) :any;
         public getSctx(pos? :Position) :any;
         public getErrors() :[Marker];
         public getWarnings() :[Marker];   
     }
+// 
     export class Marker{
-      pos: Position;
-      type: string;
-      level: string;
-      message: string;
+      pos: LintRange;
+      type: string; // error,warning
+      level: string; //same as type??
+      message: string; // '[code] ...'
+    }
+  
+    export class  LintRange{
+      sl: number;
+      sc: number;
+      el: number;
+      ec: number;
     }
     export class  XQDoc{
       moduleNamespace: string;
diff --git a/src/common/configuration.ts b/src/common/configuration.ts
index e6c3ffb..bf52f50 100644
--- a/src/common/configuration.ts
+++ b/src/common/configuration.ts
@@ -31,6 +31,10 @@ export class Configuration {
         return this._getForWindow<string[]>("xquery.executionArguments");
     }
 
+    static get xquerySuppressErrors(): string[] {
+        return this._getForWindow<string[]>("xquery.suppressErrors");
+    }
+    
     static get xqueryExecutionEngine(): string {
         return this._getForWindow<string>("xquery.executionEngine");
     }
diff --git a/src/completion/xquery-completion-item-provider.ts b/src/completion/xquery-completion-item-provider.ts
index aff265a..12b6a5e 100644
--- a/src/completion/xquery-completion-item-provider.ts
+++ b/src/completion/xquery-completion-item-provider.ts
@@ -8,7 +8,7 @@ export class XQueryCompletionItemProvider implements CompletionItemProvider {
         const completionItems = new Array<CompletionItem>();
         const linter = new XQLint(document.getText());
 
-        linter.getCompletions({ line: position.line, col: position.character }).forEach((x: any) => {
+        linter.getCompletions(position).forEach((x: any) => {
             completionItems.push(this._getCompletionItem(x));
         });
 
diff --git a/src/linting/xquery-linter.ts b/src/linting/xquery-linter.ts
index ff4dc42..4486a15 100644
--- a/src/linting/xquery-linter.ts
+++ b/src/linting/xquery-linter.ts
@@ -1,23 +1,29 @@
+// convert xqlint markers 
 import { Diagnostic, DiagnosticSeverity, Position, Range } from "vscode";
-import { XQLint} from "@quodatum/xqlint";
+import { Marker, XQLint } from "@quodatum/xqlint";
+import { Configuration } from "../common";
 
+// [XQST0059] module "http://www.rave-tech.com/bloomsbury/config" not found
+// [XPST0008] "list-details#0": undeclared function
+function isSuppressed(msg: string): boolean {
+    const errs = Configuration.xquerySuppressErrors;
+    return errs.some((x) => msg.includes(x));
+}
 
 export class XQueryLinter {
-    static SEVERITY_WARNING = 1;
-    static SEVERITY_ERROR = 2;
 
     lint(text: string): Diagnostic[] {
         const linter = new XQLint(text);
         const diagnostics = new Array<Diagnostic>();
 
-        linter.getErrors().forEach((error: any) => {
+        linter.getErrors().forEach((error: Marker) => {
             diagnostics.push(new Diagnostic(
                 new Range(
                     new Position(error.pos.sl, error.pos.sc),
                     new Position(error.pos.el, error.pos.ec)
                 ),
                 error.message,
-                DiagnosticSeverity.Error
+                isSuppressed(error.message) ? DiagnosticSeverity.Information : DiagnosticSeverity.Error
             ));
         });
 
@@ -31,7 +37,7 @@ export class XQueryLinter {
                 DiagnosticSeverity.Warning
             ));
         });
-
         return diagnostics;
+
     }
 }
diff --git a/src/test/test-data/simple-execute.xq b/src/test/test-data/simple-execute.xq
new file mode 100644
index 0000000..ff6c4cc
--- /dev/null
+++ b/src/test/test-data/simple-execute.xq
@@ -0,0 +1,2 @@
+(: https://stackoverflow.com/questions/21557461/execute-a-batch-file-from-nodejs :)
+fn:current-dateTime()
\ No newline at end of file
diff --git a/src/xquery-execution/commands/executeXQuery.ts b/src/xquery-execution/commands/executeXQuery.ts
index 8897db1..a5064af 100644
--- a/src/xquery-execution/commands/executeXQuery.ts
+++ b/src/xquery-execution/commands/executeXQuery.ts
@@ -2,14 +2,14 @@ import { window, workspace } from "vscode";
 import { Disposable, Range, TextEditor, TextEditorEdit, Uri } from "vscode";
 
 import * as constants from "../../constants";
-
+import { channel } from "../../common/logger";
 import { ChildProcess } from "../child-process";
 import { Configuration, NativeCommands } from "../../common";
 
 export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): Promise<void> {
     // this disposable will be used for creating status bar messages
     let disposable: Disposable;
-
+    channel.log("executeXQuery");
     if (editor.document.languageId !== constants.languageIds.xquery) {
         window.showErrorMessage("This action can only be performed on an XQuery file.");
         return;
@@ -103,7 +103,8 @@ export async function executeXQuery(editor: TextEditor, edit: TextEditorEdit): P
             .replace("$(input)", inputFile.fsPath)
             .replace("$(project)", (workspace.workspaceFolders) ? workspace.workspaceFolders[0].uri.fsPath : "");
     });
-
+    channel.log(executable);
+    channel.log(args.toString());
     try {
         await ChildProcess.spawn(executable, args);
     }