[fix] diag msg
This commit is contained in:
parent
ba9a3594b0
commit
6829f17673
4 changed files with 36 additions and 28 deletions
|
@ -1 +1 @@
|
||||||
{"cells":[{"kind":2,"language":"xquery","value":"(:<:)\r\n\r\nimport module namespace docs=\"lsp/docs\" at \"/srv/basex/webapp/lsp/docs.xqm\";"},{"kind":2,"language":"xquery","value":"ws:ids()"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn map:put($t,\"text\",substring($t?text,1,15))"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"parse\")\r\nreturn $t/self::ERROR"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t"}]}
|
{"cells":[{"kind":2,"language":"xquery","value":"(:<:)\r\n\r\nimport module namespace docs=\"lsp/docs\" at \"/srv/basex/webapp/lsp/docs.xqm\";"},{"kind":2,"language":"xquery","value":"ws:ids()"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"parse\")\r\nreturn $t/self::ERROR"},{"kind":2,"language":"xquery","value":"let $sock:=foot(ws:ids())\r\nlet $f:=docs:list($sock)\r\nlet $t:=docs:get($sock,$f,\"textDocument\")\r\nreturn $t"}]}
|
|
@ -17,7 +17,7 @@ declare record lsp-diags:nostic(
|
||||||
range as pos:Range,
|
range as pos:Range,
|
||||||
severity as xs:integer, (: enum('error', 'hint', 'info', 'warning') :)
|
severity as xs:integer, (: enum('error', 'hint', 'info', 'warning') :)
|
||||||
message as xs:string,
|
message as xs:string,
|
||||||
code as xs:string,
|
code? as xs:string,
|
||||||
source as xs:string:="xquery"
|
source as xs:string:="xquery"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,11 +33,11 @@ declare function lsp-diags:publish(
|
||||||
$text as xs:string,
|
$text as xs:string,
|
||||||
$xml as lsp-diags:ParseResult)
|
$xml as lsp-diags:ParseResult)
|
||||||
as map(*){
|
as map(*){
|
||||||
let $_:=trace($xml,"PABLISH ")
|
|
||||||
let $diagnostics:=if($xml/self::ERROR)
|
let $diagnostics:=if($xml/self::ERROR)
|
||||||
then array{lsp-diags:parse-error($text, $xml)}
|
then array{lsp-diags:parse-error($text, $xml)}
|
||||||
else array{ lsp-diags:parse-xquery($text,$xml)}
|
else array{ lsp-diags:parse-xquery($text,$xml)}
|
||||||
let $_:=trace($diagnostics,"PIBLISH ")
|
|
||||||
return {"jsonrpc": "2.0",
|
return {"jsonrpc": "2.0",
|
||||||
"method":"textDocument/publishDiagnostics",
|
"method":"textDocument/publishDiagnostics",
|
||||||
"params":{"uri": $uri, "diagnostics": $diagnostics}
|
"params":{"uri": $uri, "diagnostics": $diagnostics}
|
||||||
|
@ -50,25 +50,30 @@ let $_:=trace($diagnostics,"PIBLISH ")
|
||||||
:)
|
:)
|
||||||
declare function lsp-diags:parse-error($text as xs:string, $xml as element(ERROR))
|
declare function lsp-diags:parse-error($text as xs:string, $xml as element(ERROR))
|
||||||
as map(*)*{
|
as map(*)*{
|
||||||
let $dmesg:=$xml/string()=>trace("parse-error")
|
|
||||||
let $dmesg:=translate($dmesg," ",";")
|
|
||||||
let $b:=number($xml/@b)-1
|
|
||||||
let $e:= number($xml/@e)-1
|
|
||||||
let $last:= string-length($text)-1
|
|
||||||
return (
|
|
||||||
|
|
||||||
lsp-diags:nostic(pos:Range(pos:toPosition($text, $b),
|
if(string-length($text) gt 0)
|
||||||
|
then let $last:= max((0,string-length($text)-1))
|
||||||
|
let $dmesg:=$xml/string()=>trace("parse-error")
|
||||||
|
let $dmesg:=translate($dmesg," ",";")
|
||||||
|
let $b:=number($xml/@b)-1
|
||||||
|
let $e:= number($xml/@e)-1
|
||||||
|
return (
|
||||||
|
(: mark error :)
|
||||||
|
lsp-diags:nostic(pos:Range(pos:toPosition($text, $b),
|
||||||
pos:toPosition($text, min(($e,$last)))),
|
pos:toPosition($text, min(($e,$last)))),
|
||||||
1,
|
1,
|
||||||
$dmesg,'XPST0003'),
|
$dmesg,'XPST0003'),
|
||||||
if($e ge string-length($text))
|
|
||||||
then ()
|
(:mark after error:)
|
||||||
else lsp-diags:nostic(pos:Range(pos:toPosition($text, $e +1 ),
|
if($e ge string-length($text))
|
||||||
|
then ()
|
||||||
|
else lsp-diags:nostic(pos:Range(pos:toPosition($text, $e +1 ),
|
||||||
pos:toPosition($text, $last)),
|
pos:toPosition($text, $last)),
|
||||||
2,
|
2,
|
||||||
"Unparsed due to previous parser error.",
|
"Unparsed due to previous parser error.",
|
||||||
"XQLT0001")
|
"XQLT0001")
|
||||||
)
|
)
|
||||||
|
else ()
|
||||||
};
|
};
|
||||||
|
|
||||||
(: test data :)
|
(: test data :)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
(:~
|
(:~
|
||||||
text editing API
|
positions in text
|
||||||
:)
|
:)
|
||||||
module namespace pos="lsp/position";
|
module namespace pos="lsp/position";
|
||||||
|
|
||||||
|
@ -89,6 +89,8 @@ as xs:integer
|
||||||
return $s?max
|
return $s?max
|
||||||
};
|
};
|
||||||
|
|
||||||
declare function pos:ln-col($pos as pos:Position){
|
(:~ position text for display :)
|
||||||
`Ln { $pos?line}, Col { $pos?character}`
|
declare function pos:ln-col($pos as pos:Position,$offset as xs:integer:=1)
|
||||||
|
{
|
||||||
|
`Ln { $pos?line + $offset}, Col { $pos?character + $offset}`
|
||||||
};
|
};
|
|
@ -56,7 +56,8 @@ document.getElementById("load").onchange = e => {
|
||||||
insert: t
|
insert: t
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log("SYNC")
|
client.sync();
|
||||||
|
console.log("SYNC");
|
||||||
});
|
});
|
||||||
document.getElementById("load").value="";
|
document.getElementById("load").value="";
|
||||||
};
|
};
|
||||||
|
@ -104,11 +105,11 @@ function diags(params){
|
||||||
const severities=["error","warning" ,"info","hint" ]
|
const severities=["error","warning" ,"info","hint" ]
|
||||||
//
|
//
|
||||||
const diagnostics = params.diagnostics
|
const diagnostics = params.diagnostics
|
||||||
.map(({ range, message, severity }) => ({
|
.map(({ range, message, severity,code }) => ({
|
||||||
from: plugin.fromPosition( range.start,view.state.doc),
|
from: plugin.fromPosition( range.start,view.state.doc),
|
||||||
to: plugin.fromPosition( range.end,view.state.doc),
|
to: plugin.fromPosition( range.end,view.state.doc),
|
||||||
severity: severities[severity -1],
|
severity: severities[severity -1],
|
||||||
message,
|
message: ((typeof code === 'undefined')?"":`[${code}] `)+message,
|
||||||
}))
|
}))
|
||||||
.filter(
|
.filter(
|
||||||
({ from, to }) =>
|
({ from, to }) =>
|
||||||
|
|
Loading…
Add table
Reference in a new issue