From 2d99af938977574c25988e91b841b2ec41e34575 Mon Sep 17 00:00:00 2001 From: Andy Bunce Date: Sun, 17 Aug 2025 19:52:52 +0100 Subject: [PATCH] [fix] severities --- webapp/lsp/etc/capabilities.json | 2 +- webapp/lsp/lsp-diags.xqm | 30 ++++++++++++++++----- webapp/static/clients/ace/script.js | 2 +- webapp/static/clients/codemirror/index.html | 3 +++ webapp/static/clients/codemirror/script.js | 12 +++++++-- 5 files changed, 38 insertions(+), 11 deletions(-) diff --git a/webapp/lsp/etc/capabilities.json b/webapp/lsp/etc/capabilities.json index 055451b..497e119 100644 --- a/webapp/lsp/etc/capabilities.json +++ b/webapp/lsp/etc/capabilities.json @@ -6,7 +6,7 @@ "triggerCharacters": [ "\"", ":" ], "documentSelector": [{ "language": "xquery" }] }, - "hoverProvider": false, + "hoverProvider": true, "documentSymbolProvider": false, "documentRangeFormattingProvider": false, "colorProvider": {}, diff --git a/webapp/lsp/lsp-diags.xqm b/webapp/lsp/lsp-diags.xqm index 4b91dee..5507639 100644 --- a/webapp/lsp/lsp-diags.xqm +++ b/webapp/lsp/lsp-diags.xqm @@ -21,9 +21,9 @@ declare record lsp-diags:nostic( declare variable $lsp-diags:severities:={ 'error':1, - 'hint':2, + 'hint':4, 'info':3, - 'warning':4 + 'warning':2 }; declare function lsp-diags:publish( @@ -33,7 +33,7 @@ declare function lsp-diags:publish( as map(*){ let $diagnostics:=if($xml/self::ERROR) then array{lsp-diags:parse-error($text, $xml)} - else [] + else array{lsp-diags:parse-xquery($text,$xml)} return {"jsonrpc": "2.0", "method":"textDocument/publishDiagnostics", @@ -47,13 +47,29 @@ as map(*){ declare function lsp-diags:parse-error($text as xs:string, $xml as element(ERROR)) as map(*)*{ -lsp-diags:nostic(pos:Range(pos:toPosition($text=>trace("EXML "), $xml/@b), +lsp-diags:nostic(pos:Range(pos:toPosition($text, $xml/@b), pos:toPosition($text, $xml/@e)), - 1, + $lsp-diags:severities('error'), $xml/string()), lsp-diags:nostic(pos:Range(pos:toPosition($text, $xml/@e +1 ), pos:toPosition($text, string-length($text)-1)), - 2, + $lsp-diags:severities('warning'), "Previous parse error") -}; \ No newline at end of file +}; + +(: test data :) +declare function lsp-diags:parse-xquery($text as xs:string, $xml as element(Module)) +as map(*)*{ + lsp-diags:nostic(pos:Range(pos:Position(0,0), pos:Position(0, 5)), + $lsp-diags:severities('error'),"111"), + +lsp-diags:nostic(pos:Range(pos:Position(1,0), pos:Position(1,5)), + $lsp-diags:severities('warning'),"2222"), + +lsp-diags:nostic(pos:Range(pos:Position(2,0), pos:Position(2, 5)), + $lsp-diags:severities('info'),"333"), + +lsp-diags:nostic(pos:Range(pos:Position(3,0), pos:Position(3, 12)), + $lsp-diags:severities('hint'), "44") +}; diff --git a/webapp/static/clients/ace/script.js b/webapp/static/clients/ace/script.js index efd045d..54eae22 100644 --- a/webapp/static/clients/ace/script.js +++ b/webapp/static/clients/ace/script.js @@ -9,7 +9,7 @@ var editor = ace.edit("editor", { useWorker: false // Disable web worker for this simple demo }); -//ace.require('ace/ext/settings_menu'); +ace.require('ace/ext/settings_menu'); editor.setTheme("ace/theme/github"); //editor.session.setMode("ace/mode/html"); editor.commands.addCommands([ diff --git a/webapp/static/clients/codemirror/index.html b/webapp/static/clients/codemirror/index.html index aa140ce..07def1f 100644 --- a/webapp/static/clients/codemirror/index.html +++ b/webapp/static/clients/codemirror/index.html @@ -61,6 +61,9 @@ +
diff --git a/webapp/static/clients/codemirror/script.js b/webapp/static/clients/codemirror/script.js index 637b2b6..8461bd7 100644 --- a/webapp/static/clients/codemirror/script.js +++ b/webapp/static/clients/codemirror/script.js @@ -76,7 +76,8 @@ function connect() { }; function incoming(msg) { - const rpc=JSON.parse(msg) + const rpc=JSON.parse(msg); + log(rpc.method); switch (rpc.method) { case "textDocument/publishDiagnostics": diags(rpc.params); @@ -87,10 +88,17 @@ function incoming(msg) { } }; +function log(msg){ + const li = document.createElement("li"); + + li.appendChild(document.createTextNode(msg)); + const ol=document.getElementById("msg"); + ol.insertBefore(li,ol.firstChild) +}; function diags(params){ console.log("--",params) let plugin= lsp.LSPPlugin.get(view); - const severities=["error" , "hint" ,"info" ,"warning"] + const severities=["error","warning" ,"info","hint" ] // const diagnostics = params.diagnostics .map(({ range, message, severity }) => ({