diff --git a/src/server/html/acego.js b/src/server/html/acego.js
index 8138df3..afb01c0 100644
--- a/src/server/html/acego.js
+++ b/src/server/html/acego.js
@@ -1,6 +1,11 @@
-import * as ace from "ace-builds/ace";
-import {Mode as JSONMode} from "ace-builds/src/mode/json"; // any mode you want
-import {AceLanguageClient} from "ace-linters/build/ace-language-client";
+import * as aceBuilds from 'https://esm.run/ace-builds';
+
+import ace from 'https://cdn.jsdelivr.net/npm/ace/+esm'
+
+/* import 'ace-builds/src-noconflict/mode-javascript';
+import 'ace-builds/src-noconflict/theme-chrome'; */
+
+/* import {AceLanguageClient} from "ace-linters/build/ace-language-client";
const serverData = {
module: () => import("ace-linters/build/language-client"),
@@ -8,12 +13,16 @@ const serverData = {
type: "socket",
socket: new WebSocket("ws://127.0.0.1:3000/ws/lsp"), // your websocket server address
}
-
-// Create an Ace editor
-let editor = ace.edit("container", {
- mode: new JSONMode()
+ */
+ // Initialize the editor
+ const editor = ace.edit("editor", {
+ theme: "ace/theme/chrome",
+ mode: "ace/mode/javascript",
+ fontSize: "14px",
+ showPrintMargin: false,
+ useWorker: false // Disable web worker for this simple demo
});
// Create a language provider for WebSocket
-let languageProvider = AceLanguageClient.for(serverData);
-languageProvider.registerEditor(editor);
\ No newline at end of file
+//let languageProvider = AceLanguageClient.for(serverData);
+//languageProvider.registerEditor(editor);
\ No newline at end of file
diff --git a/src/server/html/index.html b/src/server/html/index.html
index 6264a29..6b0b4da 100644
--- a/src/server/html/index.html
+++ b/src/server/html/index.html
@@ -1,34 +1,42 @@
-
+
-
-
+
+ BaseX LSP
+
+
+ something
some text
+
\ No newline at end of file
diff --git a/webapp/lsp/lsp-util.xqm b/webapp/lsp/lsp-util.xqm
index 20396e5..39d8360 100644
--- a/webapp/lsp/lsp-util.xqm
+++ b/webapp/lsp/lsp-util.xqm
@@ -14,7 +14,7 @@ declare variable $chat-util:id := 'id';
: Sends a users list (all, active) to all registered clients.
:)
declare function chat-util:users() as empty-sequence() {
- ws:emit({
+ ws:emit(map{
'type': 'users',
'users': array { sort(user:list()) },
'active': array { distinct-values(
@@ -34,7 +34,7 @@ declare function chat-util:message(
$to as xs:string?
) as empty-sequence() {
let $ws-ids := ws:ids()[not($to) or ws:get(., $chat-util:id) = $to]
- return ws:send({
+ return ws:send(map{
'type': 'message',
'text': serialize($text),
'from': ws:get(ws:id(), $chat-util:id),
diff --git a/webapp/lsp/lsp-ws.xqm b/webapp/lsp/lsp-ws.xqm
index b5e0870..2237d1b 100644
--- a/webapp/lsp/lsp-ws.xqm
+++ b/webapp/lsp/lsp-ws.xqm
@@ -5,15 +5,15 @@
module namespace chat-ws = 'chat-ws';
import module namespace chat-util = 'chat/util' at 'lsp-util.xqm';
-import module namespace request = "http://exquery.org/ns/request";
+
(:~
: Creates a WebSocket connection. Registers the user and notifies all clients.
:)
declare
- %ws:connect('/chat')
+ %ws:connect('/lsp')
function chat-ws:connect() as empty-sequence() {
- ws:set(ws:id(), $chat-util:id, session:get($chat-util:id)),
+ ws:set(ws:id()=>trace("CONNECT: "), $chat-util:id, session:get($chat-util:id)),
chat-util:users()
};
@@ -22,7 +22,7 @@ function chat-ws:connect() as empty-sequence() {
: @param $message message
:)
declare
- %ws:message('/chat', '{$message}')
+ %ws:message('/lsp', '{$message}')
function chat-ws:message(
$message as xs:string
) as empty-sequence() {
@@ -39,7 +39,7 @@ function chat-ws:message(
: Closes a WebSocket connection. Unregisters the user and notifies all clients.
:)
declare
- %ws:close('/chat')
+ %ws:close('/lsp')
function chat-ws:close() as empty-sequence() {
ws:delete(ws:id(), $chat-util:id),
chat-util:users()
diff --git a/webapp/lsp/lsp.xqm b/webapp/lsp/lsp.xqm
deleted file mode 100644
index 90facf9..0000000
--- a/webapp/lsp/lsp.xqm
+++ /dev/null
@@ -1,144 +0,0 @@
-(:~
- : Simple WebSocket chat. RESTXQ functions.
- : @author BaseX Team, BSD License
- :)
-module namespace chat = 'chat';
-
-import module namespace chat-util = 'chat/util' at 'lsp-util.xqm';
-
-(:~
- : Login or main page.
- : @return HTML page
- :)
-declare
- %rest:path('/lsp')
- %output:method('html')
-function chat:chat() as element() {
- if(session:get($chat-util:id)) then (
- chat:main()
- ) else (
- chat:login()
- )
-};
-
-(:~
- : Checks the user input, registers the user and reloads the chat.
- : @param $name username
- : @param $pass password
- : @return redirection
- :)
-declare
- %rest:POST
- %rest:path('/lsp/login-check')
- %rest:form-param('name', '{$name}')
- %rest:form-param('pass', '{$pass}')
-function chat:login-check(
- $name as xs:string,
- $pass as xs:string
-) as element(rest:response) {
- try {
- user:check($name, $pass),
- session:set($chat-util:id, $name)
- } catch user:* {
- (: login fails: no session info is set :)
- },
- web:redirect('/chat')
-};
-
-(:~
- : Logs out the current user, notifies all WebSocket clients, and redirects to the login page.
- : @return redirection
- :)
-declare
- %rest:path('/lsp/logout')
-function chat:logout() as element(rest:response) {
- session:get($chat-util:id) ! chat-util:close(.),
- session:delete($chat-util:id),
- web:redirect('/chat')
-};
-
-(:~
- : Returns the HTML login page.
- : @return HTML page
- :)
-declare %private function chat:login() as element(html) {
- chat:wrap((
- Please enter your credentials:
,
-
- ), ())
-};
-
-(:~
- : Returns the HTML main page.
- : @return HTML page
- :)
-declare %private function chat:main() as element(html) {
- chat:wrap((
-
-
-
,
-
-
-
- USERS (online)
-
- |
- |
-
- CHAT MESSAGES
-
- |
-
-
- ), )
-};
-
-(:~
- : Returns an HTML page.
- : @param $contents page contents
- : @param $login login page
- : @return HTML page
- :)
-declare %private function chat:wrap(
- $contents as item()*,
- $headers as element()*
-) as element(html) {
-
-
-
- BaseX WebSocket Chat
-
-
- { $headers }
-
-
-
- {
- for $id in session:get($chat-util:id)
- return { $id } (logout)
- }
-
-
- BaseX WebSocket Chat
- { $contents }
-
-
-};