[fix] hide popover
This commit is contained in:
parent
e32ff3d77a
commit
e32e3437a1
2 changed files with 48 additions and 43 deletions
|
@ -16,9 +16,10 @@
|
|||
<body>
|
||||
<nav class="navbar bg-body-tertiary">
|
||||
<div class="container-fluid">
|
||||
<a class="navbar-brand">BaseX LSP client</a>
|
||||
<a href="/dba/logs" target="dba">#</a>
|
||||
|
||||
|
||||
<div class="btn-toolbar" role="toolbar" aria-label="Toolbar with button groups">
|
||||
<a class="navbar-brand">BaseX LSP client</a>
|
||||
<button id="popcon" popovertarget="mypopover" class="btn btn-danger">
|
||||
<i class="bi bi-router"></i>
|
||||
</button>
|
||||
|
@ -29,6 +30,7 @@
|
|||
<button id="connect">connect</button>
|
||||
</div>
|
||||
</div>
|
||||
<a href="/dba/logs" target="dba">#</a>
|
||||
<div class="row">
|
||||
<div>
|
||||
<select id="language">
|
||||
|
|
|
@ -3,7 +3,7 @@ let doc = `3+1`;
|
|||
var client;
|
||||
var extLint;
|
||||
|
||||
function $(id){return document.getElementById(id)};
|
||||
function $(id) { return document.getElementById(id) };
|
||||
// Load saved content from localStorage when the page loads
|
||||
window.addEventListener('load', () => {
|
||||
const savedText = localStorage.getItem('code');
|
||||
|
@ -26,8 +26,8 @@ document.getElementById("search").onclick = e => {
|
|||
lsp.openSearchPanel(view);
|
||||
};
|
||||
document.getElementById("lint").onclick = async e => {
|
||||
console.log("word",view.state.wordAt(1));
|
||||
const ser=document.getElementById("iServer").value;
|
||||
console.log("word", view.state.wordAt(1));
|
||||
const ser = document.getElementById("iServer").value;
|
||||
//const transport = new WebTransport(ser);
|
||||
|
||||
// The connection can be used once ready fulfills
|
||||
|
@ -42,7 +42,7 @@ document.getElementById("sync").onclick = e => {
|
|||
|
||||
document.getElementById("load").onchange = e => {
|
||||
const url = e.target.value;
|
||||
if(url.length==0)return
|
||||
if (url.length == 0) return
|
||||
fetch(url)
|
||||
.then(response => response.text())
|
||||
.then(t => {
|
||||
|
@ -57,7 +57,7 @@ document.getElementById("load").onchange = e => {
|
|||
client.sync();
|
||||
console.log("SYNC");
|
||||
});
|
||||
document.getElementById("load").value="";
|
||||
document.getElementById("load").value = "";
|
||||
};
|
||||
function connect() {
|
||||
const server = document.getElementById("iServer").value;
|
||||
|
@ -65,63 +65,66 @@ function connect() {
|
|||
lsp.simpleWebSocketTransport(server)
|
||||
.then(transport => {
|
||||
transport.subscribe(incoming);
|
||||
transport.socket.onclose=(event) => connectStatus(false);
|
||||
transport.socket.oneror=(event) => $("msg").innerText="sock error!";
|
||||
transport.socket.onclose = (event) => connectStatus(false);
|
||||
transport.socket.oneror = (event) => $("msg").innerText = "sock error!";
|
||||
client = new lsp.LSPClient().connect(transport);
|
||||
$("mypopover").hidePopover();
|
||||
connectStatus(true);
|
||||
let extLsp=lsp.languageServerSupport(client,file,"xquery");
|
||||
extLint=lsp.linter(
|
||||
view=>{ client.sync();return [];},
|
||||
{autoPanel:true});
|
||||
let extLsp = lsp.languageServerSupport(client, file, "xquery");
|
||||
extLint = lsp.linter(
|
||||
view => { client.sync(); return []; },
|
||||
{ autoPanel: true });
|
||||
const doc = view.state.doc.toString();
|
||||
const state = lsp.createEditorState(doc, [...lsp.baseExts, extLsp,extLint]);
|
||||
const state = lsp.createEditorState(doc, [...lsp.baseExts, extLsp, extLint]);
|
||||
view.setState(state);
|
||||
})
|
||||
.catch(r => alert("connection failed: "+ server));
|
||||
.catch(r => { connectStatus(false); alert("connection failed: " + server) });
|
||||
|
||||
};
|
||||
|
||||
function connectStatus(bool) {
|
||||
if (bool) {
|
||||
$("popcon").classList.remove("btn-danger")
|
||||
$("popcon").classList.add("btn-success")
|
||||
} else {
|
||||
$("popcon").classList.add("btn-danger")
|
||||
$("popcon").classList.remove("btn-success")
|
||||
}
|
||||
};
|
||||
|
||||
function connectStatus(bool){
|
||||
if(bool){
|
||||
$("popcon").classList.remove("btn-danger")
|
||||
$("popcon").classList.add("btn-success")
|
||||
}else{
|
||||
$("popcon").classList.add("btn-danger")
|
||||
$("popcon").classList.remove("btn-success")
|
||||
}
|
||||
}
|
||||
function incoming(msg) {
|
||||
const rpc=JSON.parse(msg);
|
||||
const rpc = JSON.parse(msg);
|
||||
log(rpc);
|
||||
switch (rpc.method) {
|
||||
case "textDocument/publishDiagnostics":
|
||||
diags(rpc.params);
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
function log(rpc){
|
||||
if(rpc.id) return
|
||||
const text=rpc.method;
|
||||
function log(rpc) {
|
||||
if (rpc.id) return
|
||||
const text = rpc.method;
|
||||
const li = document.createElement("li");
|
||||
li.appendChild(document.createTextNode(text));
|
||||
$("traffic").insertBefore(li,$("traffic").firstChild)
|
||||
$("traffic").insertBefore(li, $("traffic").firstChild)
|
||||
};
|
||||
|
||||
function diags(params){
|
||||
console.log("--",params)
|
||||
let plugin= lsp.LSPPlugin.get(view);
|
||||
const severities=["error","warning" ,"info","hint" ]
|
||||
//
|
||||
const diagnostics = params.diagnostics
|
||||
.map(({ range, message, severity,code }) => ({
|
||||
from: plugin.fromPosition( range.start,view.state.doc),
|
||||
to: plugin.fromPosition( range.end,view.state.doc),
|
||||
severity: severities[severity -1],
|
||||
message: ((typeof code === 'undefined')?"":`[${code}] `)+message,
|
||||
function diags(params) {
|
||||
console.log("--", params)
|
||||
let plugin = lsp.LSPPlugin.get(view);
|
||||
const severities = ["error", "warning", "info", "hint"]
|
||||
//
|
||||
const diagnostics = params.diagnostics
|
||||
.map(({ range, message, severity, code }) => ({
|
||||
from: plugin.fromPosition(range.start, view.state.doc),
|
||||
to: plugin.fromPosition(range.end, view.state.doc),
|
||||
severity: severities[severity - 1],
|
||||
message: ((typeof code === 'undefined') ? "" : `[${code}] `) + message,
|
||||
}))
|
||||
.filter(
|
||||
({ from, to }) =>
|
||||
|
@ -139,5 +142,5 @@ function diags(params){
|
|||
}
|
||||
return 0;
|
||||
});
|
||||
view.dispatch(lsp.setDiagnostics(view.state, diagnostics));
|
||||
view.dispatch(lsp.setDiagnostics(view.state, diagnostics));
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue