websocket-text-relay 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.eslintrc +29 -0
  2. package/LICENSE +21 -0
  3. package/README.md +40 -0
  4. package/docs/code-structure.md +77 -0
  5. package/docs/creating-text-editor-plugin.md +10 -0
  6. package/docs/dev-getting-started.md +8 -0
  7. package/index.js +87 -0
  8. package/package.json +45 -0
  9. package/src/language-server/JsonRpcInterface.js +126 -0
  10. package/src/language-server/JsonRpcInterface.test.js +496 -0
  11. package/src/language-server/LspReader.js +119 -0
  12. package/src/language-server/LspReader.test.js +508 -0
  13. package/src/language-server/LspWriter.js +44 -0
  14. package/src/language-server/LspWriter.test.js +179 -0
  15. package/src/language-server/constants.js +23 -0
  16. package/src/ui/css/fonts/Montserrat-Black.ttf +0 -0
  17. package/src/ui/css/fonts/Montserrat-Bold.ttf +0 -0
  18. package/src/ui/css/fonts/Montserrat-ExtraBold.ttf +0 -0
  19. package/src/ui/css/fonts/Montserrat-ExtraLight.ttf +0 -0
  20. package/src/ui/css/fonts/Montserrat-Light.ttf +0 -0
  21. package/src/ui/css/fonts/Montserrat-Medium.ttf +0 -0
  22. package/src/ui/css/fonts/Montserrat-Regular.ttf +0 -0
  23. package/src/ui/css/fonts/Montserrat-SemiBold.ttf +0 -0
  24. package/src/ui/css/fonts/Montserrat-Thin.ttf +0 -0
  25. package/src/ui/css/fonts.css +54 -0
  26. package/src/ui/css/main.css +198 -0
  27. package/src/ui/index.html +36 -0
  28. package/src/ui/js/components/ActivityTimeseriesGraph.js +149 -0
  29. package/src/ui/js/components/HeaderSummary.js +23 -0
  30. package/src/ui/js/components/ServerStatus.js +31 -0
  31. package/src/ui/js/components/SessionLabels.js +171 -0
  32. package/src/ui/js/components/SessionWedges.js +107 -0
  33. package/src/ui/js/components/StatusRing.js +42 -0
  34. package/src/ui/js/components/grids.js +29 -0
  35. package/src/ui/js/index.js +117 -0
  36. package/src/ui/js/main.js +97 -0
  37. package/src/ui/js/util/DependencyManager.js +31 -0
  38. package/src/ui/js/util/EventEmitter.js +40 -0
  39. package/src/ui/js/util/WebsocketClient.js +76 -0
  40. package/src/ui/js/util/constants.js +9 -0
  41. package/src/ui/js/util/drawing.js +128 -0
  42. package/src/websocket-interface/WebsocketClient.js +56 -0
  43. package/src/websocket-interface/WebsocketInterface.js +71 -0
  44. package/src/websocket-interface/WtrSession.js +122 -0
  45. package/src/websocket-interface/httpServer.js +58 -0
  46. package/src/websocket-interface/sessionManager.js +107 -0
  47. package/src/websocket-interface/util.js +12 -0
  48. package/src/websocket-interface/websocketApi.js +116 -0
  49. package/src/websocket-interface/websocketServer.js +18 -0
  50. package/start.js +4 -0
@@ -0,0 +1,116 @@
1
+ import { triggerStatusUpdate, statusEvents, addWatchedFileLinks, removeWatchedFileLinks, removeOpenedFileLinks, addOpenedFileLinks } from './sessionManager.js'
2
+
3
+ export const apiMethods = new Map([
4
+ ["watch-log-messages", watchLogMessages],
5
+ ["unwatch-log-messages", unwatchLogMessages],
6
+ ["init", init],
7
+ ["watch-file", watchFile],
8
+ ["unwatch-file", unwatchFile],
9
+ ["update-open-files", updateEditorOpenFiles],
10
+ ["watch-editor-active-files", watchEditorActiveFiles],
11
+ ["unwatch-editor-active-files", unwatchEditorActiveFiles],
12
+ ["relay-text", relayText],
13
+ ["watch-wtr-status", watchWtrStatus],
14
+ ["unwatch-wtr-status", unwatchWtrStatus],
15
+ ["watch-wtr-activity", watchWtrActivity],
16
+ ["unwatch-wtr-activity", unwatchWtrActivity],
17
+ ])
18
+
19
+ function watchLogMessages (wtrSession) {
20
+ wtrSession.watchLogMessages = true
21
+ wtrSession.emitter.emit('log', { level: "info", text: "Watching WTR log messages" })
22
+ }
23
+
24
+ function unwatchLogMessages (wtrSession) {
25
+ wtrSession.emitter.emit('log', { level: "info", text: "Unwatching WTR log messages" })
26
+ wtrSession.watchLogMessages = false
27
+ }
28
+
29
+ function init (wtrSession, data) {
30
+ wtrSession.name = data.name
31
+ wtrSession.editorPid = data.editorPid
32
+ wtrSession.lsPid = data.lsPid
33
+ triggerStatusUpdate()
34
+ wtrSession.emitter.emit('log', { level: "info", text: "Init success" })
35
+ }
36
+
37
+ function watchFile (wtrSession, data) {
38
+ if (data.endsWith == null || data.endsWith.length === 0) {
39
+ wtrSession.emitter.emit('log', { level: "error", text: "Must provide an endsWith property" })
40
+ return
41
+ }
42
+ wtrSession.watchedFiles.add(data.endsWith)
43
+ addWatchedFileLinks(wtrSession, data.endsWith)
44
+ wtrSession.emitter.emit('log', { level: "info", text: `Watching files that end with ${data.endsWith}` })
45
+ }
46
+
47
+ function unwatchFile (wtrSession, data) {
48
+ if (data.endsWith == null || data.endsWith.length === 0) {
49
+ wtrSession.emitter.emit('log', { level: "error", text: "Must provide an endsWith property" })
50
+ return
51
+ }
52
+ wtrSession.watchedFiles.delete(data.endsWith)
53
+ removeWatchedFileLinks(wtrSession, data.endsWith)
54
+ wtrSession.emitter.emit('log', { level: "info", text: `No longer watching files that end with ${data.endsWith}` })
55
+ }
56
+
57
+ function updateEditorOpenFiles (wtrSession, data) {
58
+ const updatedFileSet = new Set(data.files)
59
+ for (const fileName of wtrSession.openFiles) {
60
+ if (!updatedFileSet.has(fileName)) {
61
+ wtrSession.openFiles.delete(fileName)
62
+ removeOpenedFileLinks(wtrSession, fileName)
63
+ }
64
+ }
65
+ for (const fileName of updatedFileSet) {
66
+ if (!wtrSession.openFiles.has(fileName)) {
67
+ wtrSession.openFiles.add(fileName)
68
+ addOpenedFileLinks(wtrSession, fileName)
69
+ }
70
+ }
71
+ triggerStatusUpdate()
72
+ }
73
+
74
+ function watchEditorActiveFiles (wtrSession) {
75
+ wtrSession.watchActiveFiles = true
76
+ wtrSession.emitter.emit('log', { level: "info", text: "Watching editor active files" })
77
+ }
78
+
79
+ function unwatchEditorActiveFiles (wtrSession) {
80
+ wtrSession.emitter.emit('log', { level: "info", text: "Unwatching editor active files" })
81
+ wtrSession.watchActiveFiles = false
82
+ }
83
+
84
+ function relayText (wtrSession, data) {
85
+ if (!data || !data.file) { return }
86
+ const {file, contents} = data
87
+ const watchers = wtrSession.activeOpenFiles.get(file)
88
+ if (!watchers) { return }
89
+ const watcherSessionIds = []
90
+ for (const {clientSession: watcherWtrSession, endsWith} of watchers.values()) {
91
+ watcherSessionIds.push(watcherWtrSession.id)
92
+ watcherWtrSession.sendMessageToClient({method: "watch-file", endsWith, contents})
93
+ }
94
+ const activityData = {action: "relay", relayer: wtrSession.id, watchers: watcherSessionIds}
95
+ statusEvents.emit('activity-update', activityData)
96
+ }
97
+
98
+ function watchWtrStatus (wtrSession) {
99
+ wtrSession.watchWtrStatus = true
100
+ wtrSession.emitter.emit('log', { level: "info", text: "Watching WTR status updates" })
101
+ }
102
+
103
+ function unwatchWtrStatus (wtrSession) {
104
+ wtrSession.emitter.emit('log', { level: "info", text: "Unwatching WTR status updates" })
105
+ wtrSession.watchWtrStatus = false
106
+ }
107
+
108
+ function watchWtrActivity (wtrSession) {
109
+ wtrSession.watchWtrActivity = true
110
+ wtrSession.emitter.emit('log', { level: "info", text: "Watching WTR activity events" })
111
+ }
112
+
113
+ function unwatchWtrActivity (wtrSession) {
114
+ wtrSession.emitter.emit('log', { level: "info", text: "Unwatching WTR activity events" })
115
+ wtrSession.watchWtrActivity = false
116
+ }
@@ -0,0 +1,18 @@
1
+ import { WebSocketServer } from 'ws'
2
+ import { createHttpServer } from "./httpServer.js"
3
+ import { apiMethods } from "./websocketApi.js"
4
+ import { WtrSession } from './WtrSession.js'
5
+
6
+ export const createWebsocketServer = async (port) => {
7
+ const httpServer = await createHttpServer(port) // promise will reject if can't start HTTP server on specified port
8
+
9
+ const websocketServer = new WebSocketServer({ server: httpServer })
10
+
11
+ websocketServer.on('error', () => { })
12
+
13
+ websocketServer.on('connection', (wsConnection) => {
14
+ new WtrSession({apiMethods, wsConnection})
15
+ })
16
+
17
+ return websocketServer
18
+ }
package/start.js ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env node
2
+ import { startLanguageServer } from "./index.js"
3
+
4
+ startLanguageServer()