[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>
|
<body>
|
||||||
<nav class="navbar bg-body-tertiary">
|
<nav class="navbar bg-body-tertiary">
|
||||||
<div class="container-fluid">
|
<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">
|
<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">
|
<button id="popcon" popovertarget="mypopover" class="btn btn-danger">
|
||||||
<i class="bi bi-router"></i>
|
<i class="bi bi-router"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@ -29,6 +30,7 @@
|
||||||
<button id="connect">connect</button>
|
<button id="connect">connect</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<a href="/dba/logs" target="dba">#</a>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div>
|
<div>
|
||||||
<select id="language">
|
<select id="language">
|
||||||
|
|
|
@ -3,7 +3,7 @@ let doc = `3+1`;
|
||||||
var client;
|
var client;
|
||||||
var extLint;
|
var extLint;
|
||||||
|
|
||||||
function $(id){return document.getElementById(id)};
|
function $(id) { return document.getElementById(id) };
|
||||||
// Load saved content from localStorage when the page loads
|
// Load saved content from localStorage when the page loads
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', () => {
|
||||||
const savedText = localStorage.getItem('code');
|
const savedText = localStorage.getItem('code');
|
||||||
|
@ -26,8 +26,8 @@ document.getElementById("search").onclick = e => {
|
||||||
lsp.openSearchPanel(view);
|
lsp.openSearchPanel(view);
|
||||||
};
|
};
|
||||||
document.getElementById("lint").onclick = async e => {
|
document.getElementById("lint").onclick = async e => {
|
||||||
console.log("word",view.state.wordAt(1));
|
console.log("word", view.state.wordAt(1));
|
||||||
const ser=document.getElementById("iServer").value;
|
const ser = document.getElementById("iServer").value;
|
||||||
//const transport = new WebTransport(ser);
|
//const transport = new WebTransport(ser);
|
||||||
|
|
||||||
// The connection can be used once ready fulfills
|
// The connection can be used once ready fulfills
|
||||||
|
@ -42,7 +42,7 @@ document.getElementById("sync").onclick = e => {
|
||||||
|
|
||||||
document.getElementById("load").onchange = e => {
|
document.getElementById("load").onchange = e => {
|
||||||
const url = e.target.value;
|
const url = e.target.value;
|
||||||
if(url.length==0)return
|
if (url.length == 0) return
|
||||||
fetch(url)
|
fetch(url)
|
||||||
.then(response => response.text())
|
.then(response => response.text())
|
||||||
.then(t => {
|
.then(t => {
|
||||||
|
@ -57,7 +57,7 @@ document.getElementById("load").onchange = e => {
|
||||||
client.sync();
|
client.sync();
|
||||||
console.log("SYNC");
|
console.log("SYNC");
|
||||||
});
|
});
|
||||||
document.getElementById("load").value="";
|
document.getElementById("load").value = "";
|
||||||
};
|
};
|
||||||
function connect() {
|
function connect() {
|
||||||
const server = document.getElementById("iServer").value;
|
const server = document.getElementById("iServer").value;
|
||||||
|
@ -65,32 +65,35 @@ function connect() {
|
||||||
lsp.simpleWebSocketTransport(server)
|
lsp.simpleWebSocketTransport(server)
|
||||||
.then(transport => {
|
.then(transport => {
|
||||||
transport.subscribe(incoming);
|
transport.subscribe(incoming);
|
||||||
transport.socket.onclose=(event) => connectStatus(false);
|
transport.socket.onclose = (event) => connectStatus(false);
|
||||||
transport.socket.oneror=(event) => $("msg").innerText="sock error!";
|
transport.socket.oneror = (event) => $("msg").innerText = "sock error!";
|
||||||
client = new lsp.LSPClient().connect(transport);
|
client = new lsp.LSPClient().connect(transport);
|
||||||
|
$("mypopover").hidePopover();
|
||||||
connectStatus(true);
|
connectStatus(true);
|
||||||
let extLsp=lsp.languageServerSupport(client,file,"xquery");
|
let extLsp = lsp.languageServerSupport(client, file, "xquery");
|
||||||
extLint=lsp.linter(
|
extLint = lsp.linter(
|
||||||
view=>{ client.sync();return [];},
|
view => { client.sync(); return []; },
|
||||||
{autoPanel:true});
|
{ autoPanel: true });
|
||||||
const doc = view.state.doc.toString();
|
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);
|
view.setState(state);
|
||||||
})
|
})
|
||||||
.catch(r => alert("connection failed: "+ server));
|
.catch(r => { connectStatus(false); alert("connection failed: " + server) });
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function connectStatus(bool){
|
function connectStatus(bool) {
|
||||||
if(bool){
|
if (bool) {
|
||||||
$("popcon").classList.remove("btn-danger")
|
$("popcon").classList.remove("btn-danger")
|
||||||
$("popcon").classList.add("btn-success")
|
$("popcon").classList.add("btn-success")
|
||||||
}else{
|
} else {
|
||||||
$("popcon").classList.add("btn-danger")
|
$("popcon").classList.add("btn-danger")
|
||||||
$("popcon").classList.remove("btn-success")
|
$("popcon").classList.remove("btn-success")
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
function incoming(msg) {
|
function incoming(msg) {
|
||||||
const rpc=JSON.parse(msg);
|
const rpc = JSON.parse(msg);
|
||||||
log(rpc);
|
log(rpc);
|
||||||
switch (rpc.method) {
|
switch (rpc.method) {
|
||||||
case "textDocument/publishDiagnostics":
|
case "textDocument/publishDiagnostics":
|
||||||
|
@ -103,25 +106,25 @@ function incoming(msg) {
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function log(rpc){
|
function log(rpc) {
|
||||||
if(rpc.id) return
|
if (rpc.id) return
|
||||||
const text=rpc.method;
|
const text = rpc.method;
|
||||||
const li = document.createElement("li");
|
const li = document.createElement("li");
|
||||||
li.appendChild(document.createTextNode(text));
|
li.appendChild(document.createTextNode(text));
|
||||||
$("traffic").insertBefore(li,$("traffic").firstChild)
|
$("traffic").insertBefore(li, $("traffic").firstChild)
|
||||||
};
|
};
|
||||||
|
|
||||||
function diags(params){
|
function diags(params) {
|
||||||
console.log("--",params)
|
console.log("--", params)
|
||||||
let plugin= lsp.LSPPlugin.get(view);
|
let plugin = lsp.LSPPlugin.get(view);
|
||||||
const severities=["error","warning" ,"info","hint" ]
|
const severities = ["error", "warning", "info", "hint"]
|
||||||
//
|
//
|
||||||
const diagnostics = params.diagnostics
|
const diagnostics = params.diagnostics
|
||||||
.map(({ range, message, severity,code }) => ({
|
.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: ((typeof code === 'undefined')?"":`[${code}] `)+message,
|
message: ((typeof code === 'undefined') ? "" : `[${code}] `) + message,
|
||||||
}))
|
}))
|
||||||
.filter(
|
.filter(
|
||||||
({ from, to }) =>
|
({ from, to }) =>
|
||||||
|
|
Loading…
Add table
Reference in a new issue