@mun-ui/ui 0.0.0-stage → 0.2.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 (158) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +104 -2
  3. package/bin/compile.mjs +38 -0
  4. package/bin/dev-protocol.mjs +94 -0
  5. package/bin/formatter.mjs +109 -0
  6. package/bin/hot-reload.mjs +38 -0
  7. package/bin/mun.mjs +521 -0
  8. package/bin/native.mjs +133 -0
  9. package/bin/pnpm-workspace.mjs +58 -0
  10. package/bin/program-patch.mjs +104 -0
  11. package/bin/project.mjs +322 -0
  12. package/bin/watch.mjs +316 -0
  13. package/bin/workflow.mjs +261 -0
  14. package/dist/astro.d.ts +3 -0
  15. package/dist/astro.d.ts.map +1 -0
  16. package/dist/astro.js +3 -0
  17. package/dist/astro.js.map +1 -0
  18. package/dist/closures.d.ts +2 -0
  19. package/dist/closures.d.ts.map +1 -0
  20. package/dist/closures.js +2 -0
  21. package/dist/closures.js.map +1 -0
  22. package/dist/compiler/index.d.ts +2 -0
  23. package/dist/compiler/index.d.ts.map +1 -0
  24. package/dist/compiler/index.js +2 -0
  25. package/dist/compiler/index.js.map +1 -0
  26. package/dist/core.d.ts +3 -0
  27. package/dist/core.d.ts.map +1 -0
  28. package/dist/core.js +3 -0
  29. package/dist/core.js.map +1 -0
  30. package/dist/experimental.d.ts +2 -0
  31. package/dist/experimental.d.ts.map +1 -0
  32. package/dist/experimental.js +2 -0
  33. package/dist/experimental.js.map +1 -0
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +3 -0
  37. package/dist/index.js.map +1 -0
  38. package/dist/jsx-dev-runtime.d.ts +2 -0
  39. package/dist/jsx-dev-runtime.d.ts.map +1 -0
  40. package/dist/jsx-dev-runtime.js +2 -0
  41. package/dist/jsx-dev-runtime.js.map +1 -0
  42. package/dist/jsx-runtime.d.ts +2 -0
  43. package/dist/jsx-runtime.d.ts.map +1 -0
  44. package/dist/jsx-runtime.js +2 -0
  45. package/dist/jsx-runtime.js.map +1 -0
  46. package/dist/legacy.d.ts +3 -0
  47. package/dist/legacy.d.ts.map +1 -0
  48. package/dist/legacy.js +3 -0
  49. package/dist/legacy.js.map +1 -0
  50. package/dist/mun.d.ts +5 -0
  51. package/dist/mun.d.ts.map +1 -0
  52. package/dist/mun.js +4 -0
  53. package/dist/mun.js.map +1 -0
  54. package/dist/progressive-blur/index.d.ts +8 -0
  55. package/dist/progressive-blur/index.d.ts.map +1 -0
  56. package/dist/progressive-blur/index.js +8 -0
  57. package/dist/progressive-blur/index.js.map +1 -0
  58. package/dist/progressive-blur/plan.d.ts +3 -0
  59. package/dist/progressive-blur/plan.d.ts.map +1 -0
  60. package/dist/progressive-blur/plan.js +3 -0
  61. package/dist/progressive-blur/plan.js.map +1 -0
  62. package/dist/react-types.d.ts +2 -0
  63. package/dist/react-types.d.ts.map +1 -0
  64. package/dist/react-types.js +2 -0
  65. package/dist/react-types.js.map +1 -0
  66. package/dist/rendering-quality.d.ts +4 -0
  67. package/dist/rendering-quality.d.ts.map +1 -0
  68. package/dist/rendering-quality.js +4 -0
  69. package/dist/rendering-quality.js.map +1 -0
  70. package/dist/state.d.ts +2 -0
  71. package/dist/state.d.ts.map +1 -0
  72. package/dist/state.js +2 -0
  73. package/dist/state.js.map +1 -0
  74. package/dist/types.d.ts +2 -0
  75. package/dist/types.d.ts.map +1 -0
  76. package/dist/types.js +2 -0
  77. package/dist/types.js.map +1 -0
  78. package/dist/vite.d.ts +2 -0
  79. package/dist/vite.d.ts.map +1 -0
  80. package/dist/vite.js +2 -0
  81. package/dist/vite.js.map +1 -0
  82. package/editors/install.mjs +102 -0
  83. package/editors/lsp/mun-lsp.mjs +123 -0
  84. package/editors/lsp/service.mjs +306 -0
  85. package/editors/lsp/source.mjs +58 -0
  86. package/editors/vscode/client.mjs +40 -0
  87. package/editors/vscode/dev-client.mjs +83 -0
  88. package/editors/vscode/discovery.mjs +46 -0
  89. package/editors/vscode/export.mjs +42 -0
  90. package/editors/vscode/extension.cjs +226 -0
  91. package/editors/vscode/language-configuration.json +15 -0
  92. package/editors/vscode/package.json +119 -0
  93. package/editors/vscode/protocol.mjs +29 -0
  94. package/editors/vscode/syntaxes/mun.tmLanguage.json +130 -0
  95. package/native/Cargo.lock +3581 -0
  96. package/native/Cargo.toml +21 -0
  97. package/native/README.md +21 -0
  98. package/native/mun-native/Cargo.toml +23 -0
  99. package/native/mun-native/src/accessibility.rs +738 -0
  100. package/native/mun-native/src/dev.rs +604 -0
  101. package/native/mun-native/src/lib.rs +2676 -0
  102. package/native/mun-native/src/main.rs +204 -0
  103. package/native/mun-native/src/offscreen.rs +393 -0
  104. package/native/mun-native/src/rect.wgsl +63 -0
  105. package/native/mun-native/src/text.rs +310 -0
  106. package/native/mun-native/tests/offscreen_rendering.rs +161 -0
  107. package/native/mun-native/tests/stress.rs +408 -0
  108. package/native/mun-native/tests/window_lifecycle.rs +183 -0
  109. package/native/mun-runtime/Cargo.toml +13 -0
  110. package/native/mun-runtime/src/accessibility.rs +193 -0
  111. package/native/mun-runtime/src/collection.rs +1073 -0
  112. package/native/mun-runtime/src/gesture.rs +1070 -0
  113. package/native/mun-runtime/src/input.rs +325 -0
  114. package/native/mun-runtime/src/ir.rs +782 -0
  115. package/native/mun-runtime/src/kinetics.rs +500 -0
  116. package/native/mun-runtime/src/layout.rs +173 -0
  117. package/native/mun-runtime/src/layout_cache.rs +209 -0
  118. package/native/mun-runtime/src/lib.rs +49 -0
  119. package/native/mun-runtime/src/motion.rs +1162 -0
  120. package/native/mun-runtime/src/retained.rs +574 -0
  121. package/native/mun-runtime/src/runtime.rs +7078 -0
  122. package/native/mun-runtime/src/scene.rs +530 -0
  123. package/native/mun-runtime/src/scroll.rs +521 -0
  124. package/native/mun-runtime/src/scroll_view.rs +220 -0
  125. package/native/mun-runtime/src/text_edit.rs +670 -0
  126. package/native/mun-runtime/src/timeline.rs +1534 -0
  127. package/native/mun-runtime/src/validate.rs +677 -0
  128. package/native/mun-runtime/tests/accessibility_semantics.rs +168 -0
  129. package/native/mun-runtime/tests/compiler_contract.rs +110 -0
  130. package/native/mun-runtime/tests/flexible_frames.rs +47 -0
  131. package/native/mun-runtime/tests/hot_update.rs +367 -0
  132. package/native/mun-runtime/tests/incremental_runtime.rs +323 -0
  133. package/native/mun-runtime/tests/ir_validation.rs +167 -0
  134. package/native/mun-runtime/tests/keyed_collections.rs +251 -0
  135. package/native/mun-runtime/tests/native_controls_style.rs +491 -0
  136. package/native/mun-runtime/tests/native_demo.rs +285 -0
  137. package/native/mun-runtime/tests/native_layout_style.rs +175 -0
  138. package/native/mun-runtime/tests/native_settings_pane.rs +152 -0
  139. package/native/mun-runtime/tests/scroll_view.rs +403 -0
  140. package/native/mun-runtime/tests/text_editing.rs +491 -0
  141. package/package.json +210 -3
  142. package/schemas/README.md +19 -0
  143. package/schemas/semantic-ui-ir-v1.schema.json +1972 -0
  144. package/templates/native/App.mun +15 -0
  145. package/templates/native/gitignore +3 -0
  146. package/templates/native/mun.toml +8 -0
  147. package/templates/project/gitignore +5 -0
  148. package/templates/project/index.html +13 -0
  149. package/templates/project/package.json +21 -0
  150. package/templates/project/src/App.mun +13 -0
  151. package/templates/project/src/index.css +21 -0
  152. package/templates/project/src/main.ts +5 -0
  153. package/templates/project/tsconfig.json +20 -0
  154. package/templates/project/vite.config.ts +6 -0
  155. package/templates/vite/src/App.css +134 -0
  156. package/templates/vite/src/App.tsx +91 -0
  157. package/templates/vite/src/index.css +23 -0
  158. package/templates/vite/vite.config.ts +10 -0
@@ -0,0 +1,226 @@
1
+ const vscode = require('vscode')
2
+ const path = require('node:path')
3
+ const { spawn } = require('node:child_process')
4
+
5
+ let clients = []
6
+ const folderStates = new Map()
7
+
8
+ class RuntimeTreeProvider {
9
+ constructor() { this.emitter = new vscode.EventEmitter(); this.onDidChangeTreeData = this.emitter.event }
10
+ refresh() { this.emitter.fire(undefined) }
11
+ dispose() { this.emitter.dispose() }
12
+ getChildren(element) {
13
+ if (!element) {
14
+ const active = [...folderStates.values()].filter(state => state.tree)
15
+ if (active.length === 1) return active[0].tree.roots.map(node => ({ type: 'runtime', state: active[0], node }))
16
+ return active.map(state => ({ type: 'folder', state }))
17
+ }
18
+ if (element.type === 'folder') return element.state.tree.roots.map(node => ({ type: 'runtime', state: element.state, node }))
19
+ if (element.type === 'runtime') return element.state.tree.children(element.node).map(node => ({ type: 'runtime', state: element.state, node }))
20
+ return []
21
+ }
22
+ getTreeItem(element) {
23
+ if (element.type === 'folder') {
24
+ const item = new vscode.TreeItem(element.state.folder.name ?? path.basename(element.state.root), vscode.TreeItemCollapsibleState.Expanded)
25
+ item.description = element.state.snapshot ? `rev ${element.state.snapshot.devRevision ?? '?'}` : undefined
26
+ item.contextValue = 'munRuntimeProject'
27
+ return item
28
+ }
29
+ const { node, state } = element
30
+ const children = state.tree.children(node)
31
+ const item = new vscode.TreeItem(node.kind, children.length ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None)
32
+ const component = node.component ? `<${node.component}>` : ''
33
+ const source = node.source ? `${node.source.file}:${node.source.line}` : ''
34
+ item.description = [component, source].filter(Boolean).join(' ')
35
+ const frame = node.frame ? `frame ${node.frame.map(value => Math.round(value)).join(', ')}` : ''
36
+ item.tooltip = [node.id, source, frame].filter(Boolean).join('\n')
37
+ item.contextValue = 'munRuntimeNode'
38
+ if (node.source) item.command = { command: 'mun.openRuntimeSource', title: 'Open Mün Source', arguments: [state, node] }
39
+ return item
40
+ }
41
+ }
42
+
43
+ async function activate(context) {
44
+ const { discoverMunCommand } = await import('./discovery.mjs')
45
+ const { LspClient } = await import('./client.mjs')
46
+ const { inspectDevSession, runtimeTree } = await import('./dev-client.mjs')
47
+ const version = context.extension?.packageJSON?.version ?? require('./package.json').version
48
+ const folders = vscode.workspace.workspaceFolders ?? []
49
+ const diagnostics = vscode.languages.createDiagnosticCollection('mun')
50
+ const runtimeDiagnostics = vscode.languages.createDiagnosticCollection('mun-runtime')
51
+ const output = vscode.window.createOutputChannel('Mün Language Server')
52
+ const devOutput = vscode.window.createOutputChannel('Mün Development')
53
+ const treeProvider = new RuntimeTreeProvider()
54
+ const treeView = vscode.window.createTreeView('mun.runtimeView', { treeDataProvider: treeProvider, showCollapseAll: true })
55
+ context.subscriptions.push(diagnostics, runtimeDiagnostics, output, devOutput, treeProvider, treeView)
56
+
57
+ const workspaceEntries = folders.length ? folders : [{ uri: vscode.Uri.file(process.cwd()), name: 'Mün' }]
58
+ for (const folder of workspaceEntries) {
59
+ const state = { folder, root: folder.uri.fsPath, child: undefined, timer: undefined, snapshot: undefined, tree: undefined, runtimeDiagnosticUris: new Set(), toolchain: undefined }
60
+ folderStates.set(folder.uri.toString(), state)
61
+ const config = vscode.workspace.getConfiguration('mun', folder.uri)
62
+ try {
63
+ state.toolchain = await discoverMunCommand({ cwd: folder.uri.fsPath, command: config.get('server.command'), expectedVersion: version })
64
+ const server = { ...state.toolchain, args: [...state.toolchain.args, 'lsp', '--stdio'] }
65
+ const client = new LspClient(server, (method, params) => {
66
+ if (method === 'textDocument/publishDiagnostics') diagnostics.set(vscode.Uri.parse(params.uri), params.diagnostics.map(d => {
67
+ const diagnostic = new vscode.Diagnostic(range(d.range), d.message, d.severity === 2 ? vscode.DiagnosticSeverity.Warning : vscode.DiagnosticSeverity.Error)
68
+ diagnostic.source = 'mun'; diagnostic.code = d.code; return diagnostic
69
+ }))
70
+ if (method === 'mun/log') output.append(params.message)
71
+ }, error => { output.appendLine(error.message); vscode.window.showErrorMessage(error.message) })
72
+ clients.push(client)
73
+ const initialization = await client.request('initialize', { processId: process.pid, rootUri: folder.uri.toString(), workspaceFolders: [{ uri: folder.uri.toString(), name: folder.name ?? 'Mün' }], capabilities: { general: { positionEncodings: ['utf-16'] } } })
74
+ if (initialization.serverInfo?.version !== version) throw new Error(`Mün LSP ${initialization.serverInfo?.version} does not match extension ${version}.`)
75
+ client.notify('initialized', {})
76
+ const belongs = document => document.languageId === 'mun' && document.uri.scheme === 'file' && (!folders.length || vscode.workspace.getWorkspaceFolder(document.uri)?.uri.toString() === folder.uri.toString())
77
+ const selector = { language: 'mun', scheme: 'file', pattern: `${folder.uri.fsPath.replaceAll('\\', '/')}/**/*.mun` }
78
+ const request = (method, document, params = {}) => client.request(method, { textDocument: { uri: document.uri.toString() }, ...params })
79
+ const open = document => { if (belongs(document)) client.notify('textDocument/didOpen', { textDocument: { uri: document.uri.toString(), languageId: 'mun', version: document.version, text: document.getText() } }) }
80
+ vscode.workspace.textDocuments.forEach(open)
81
+ context.subscriptions.push(
82
+ vscode.workspace.onDidOpenTextDocument(open),
83
+ vscode.workspace.onDidChangeTextDocument(event => { if (belongs(event.document)) client.notify('textDocument/didChange', { textDocument: { uri: event.document.uri.toString(), version: event.document.version }, contentChanges: [{ text: event.document.getText() }] }) }),
84
+ vscode.workspace.onDidCloseTextDocument(document => { if (belongs(document)) client.notify('textDocument/didClose', { textDocument: { uri: document.uri.toString() } }) }),
85
+ vscode.languages.registerDocumentFormattingEditProvider(selector, { provideDocumentFormattingEdits: async (d, options) => (await request('textDocument/formatting', d, { options })).map(e => vscode.TextEdit.replace(range(e.range), e.newText)) }),
86
+ vscode.languages.registerCompletionItemProvider(selector, { provideCompletionItems: async (d, p) => (await request('textDocument/completion', d, { position: p })).items.map(item => {
87
+ const completion = new vscode.CompletionItem(item.label, item.kind === 7 ? vscode.CompletionItemKind.Class : item.kind === 2 ? vscode.CompletionItemKind.Method : vscode.CompletionItemKind.Variable)
88
+ completion.detail = item.detail; completion.insertText = item.insertText; return completion
89
+ }) }, '.', '$', '@', ':'),
90
+ vscode.languages.registerHoverProvider(selector, { provideHover: async (d, p) => { const result = await request('textDocument/hover', d, { position: p }); return result ? new vscode.Hover(new vscode.MarkdownString(result.contents.value), range(result.range)) : undefined } }),
91
+ vscode.languages.registerSignatureHelpProvider(selector, { provideSignatureHelp: async (d, p) => {
92
+ const result = await request('textDocument/signatureHelp', d, { position: p }); if (!result) return undefined
93
+ const help = new vscode.SignatureHelp(); help.activeSignature = result.activeSignature; help.activeParameter = result.activeParameter
94
+ help.signatures = result.signatures.map(s => { const info = new vscode.SignatureInformation(s.label); info.parameters = s.parameters.map(p => new vscode.ParameterInformation(p.label)); return info }); return help
95
+ } }, '(', ',', ':'),
96
+ vscode.languages.registerDefinitionProvider(selector, { provideDefinition: async (d, p) => { const result = await request('textDocument/definition', d, { position: p }); return result ? location(result) : undefined } }),
97
+ vscode.languages.registerReferenceProvider(selector, { provideReferences: async (d, p, requestContext) => (await request('textDocument/references', d, { position: p, context: requestContext })).map(location) }),
98
+ vscode.languages.registerRenameProvider(selector, {
99
+ prepareRename: async (d, p) => { const result = await request('textDocument/prepareRename', d, { position: p }); if (!result) throw new Error('No unambiguous Mün symbol here.'); return { range: range(result.range), placeholder: result.placeholder } },
100
+ provideRenameEdits: async (d, p, newName) => { const result = await request('textDocument/rename', d, { position: p, newName }); const edit = new vscode.WorkspaceEdit(); for (const [uri, edits] of Object.entries(result.changes)) for (const e of edits) edit.replace(vscode.Uri.parse(uri), range(e.range), e.newText); return edit },
101
+ }),
102
+ vscode.languages.registerCodeActionsProvider(selector, { provideCodeActions: async (d, selected, actionContext) => (await request('textDocument/codeAction', d, { range: selected, context: { diagnostics: [], only: actionContext.only ? [actionContext.only.value] : undefined } })).map(action => {
103
+ const result = new vscode.CodeAction(action.title, vscode.CodeActionKind.QuickFix)
104
+ const edit = new vscode.WorkspaceEdit()
105
+ for (const [uri, edits] of Object.entries(action.edit.changes)) for (const e of edits) edit.replace(vscode.Uri.parse(uri), range(e.range), e.newText)
106
+ result.edit = edit; return result
107
+ }) }, { providedCodeActionKinds: [vscode.CodeActionKind.QuickFix] }),
108
+ vscode.languages.registerDocumentSymbolProvider(selector, { provideDocumentSymbols: async d => (await request('textDocument/documentSymbol', d)).map(symbol) }),
109
+ vscode.languages.registerDocumentSemanticTokensProvider(selector, { provideDocumentSemanticTokens: async d => new vscode.SemanticTokens(new Uint32Array((await request('textDocument/semanticTokens/full', d)).data)) }, new vscode.SemanticTokensLegend(initialization.capabilities.semanticTokensProvider.legend.tokenTypes)),
110
+ vscode.languages.registerFoldingRangeProvider(selector, { provideFoldingRanges: async d => (await request('textDocument/foldingRange', d)).map(r => new vscode.FoldingRange(r.startLine, r.endLine)) }),
111
+ vscode.languages.registerSelectionRangeProvider(selector, { provideSelectionRanges: async (d, positions) => (await request('textDocument/selectionRange', d, { positions })).map(selection) }),
112
+ )
113
+ const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(folder, '**/*.mun'))
114
+ for (const [event, type] of [['onDidCreate', 1], ['onDidChange', 2], ['onDidDelete', 3]]) context.subscriptions.push(watcher[event](uri => client.notify('workspace/didChangeWatchedFiles', { changes: [{ uri: uri.toString(), type }] })))
115
+ context.subscriptions.push(watcher, { dispose: () => { void client.dispose() } })
116
+ } catch (error) { output.appendLine(error.message); vscode.window.showErrorMessage(`Mün toolchain unavailable: ${error.message}`) }
117
+ }
118
+
119
+ const pickState = async () => {
120
+ const activeFolder = vscode.window.activeTextEditor && vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)
121
+ if (activeFolder && folderStates.has(activeFolder.uri.toString())) return folderStates.get(activeFolder.uri.toString())
122
+ const states = [...folderStates.values()]
123
+ if (states.length === 1) return states[0]
124
+ const picked = await vscode.window.showQuickPick(states.map(state => ({ label: state.folder.name ?? path.basename(state.root), state })), { placeHolder: 'Select a Mün project' })
125
+ return picked?.state
126
+ }
127
+
128
+ const clearRuntimeDiagnostics = state => {
129
+ for (const uri of state.runtimeDiagnosticUris) runtimeDiagnostics.delete(vscode.Uri.parse(uri))
130
+ state.runtimeDiagnosticUris.clear()
131
+ }
132
+
133
+ const publishRuntimeDiagnostics = state => {
134
+ clearRuntimeDiagnostics(state)
135
+ const grouped = new Map()
136
+ for (const diagnostic of state.snapshot?.runtimeDiagnostics ?? []) {
137
+ if (!diagnostic.source?.file) continue
138
+ const uri = vscode.Uri.file(path.resolve(state.root, diagnostic.source.file))
139
+ const key = uri.toString()
140
+ const item = new vscode.Diagnostic(sourceRange(diagnostic.source), diagnostic.message, diagnostic.severity === 'warning' ? vscode.DiagnosticSeverity.Warning : vscode.DiagnosticSeverity.Error)
141
+ item.source = 'mun-runtime'
142
+ const list = grouped.get(key) ?? []; list.push(item); grouped.set(key, list)
143
+ }
144
+ for (const [uri, items] of grouped) { runtimeDiagnostics.set(vscode.Uri.parse(uri), items); state.runtimeDiagnosticUris.add(uri) }
145
+ }
146
+
147
+ const refreshRuntime = async (state, showErrors = false) => {
148
+ try {
149
+ const snapshot = await inspectDevSession(state.root)
150
+ const changed = snapshot.devRevision !== state.snapshot?.devRevision || snapshot.revision !== state.snapshot?.revision || snapshot.runtimeDiagnostics?.length !== state.snapshot?.runtimeDiagnostics?.length
151
+ state.snapshot = snapshot
152
+ state.tree = runtimeTree(snapshot)
153
+ publishRuntimeDiagnostics(state)
154
+ if (changed) treeProvider.refresh()
155
+ return snapshot
156
+ } catch (error) {
157
+ if (showErrors) vscode.window.showErrorMessage(`Mün inspect failed: ${error.message}`)
158
+ return undefined
159
+ }
160
+ }
161
+
162
+ const stopDev = async state => {
163
+ if (state.timer) { clearInterval(state.timer); state.timer = undefined }
164
+ const child = state.child
165
+ state.child = undefined
166
+ if (child && child.exitCode === null) {
167
+ await new Promise(resolveClose => {
168
+ const timer = setTimeout(resolveClose, 2000)
169
+ child.once('close', () => { clearTimeout(timer); resolveClose() })
170
+ child.kill()
171
+ })
172
+ }
173
+ state.snapshot = undefined; state.tree = undefined; clearRuntimeDiagnostics(state); treeProvider.refresh()
174
+ }
175
+
176
+ const startDev = async state => {
177
+ if (!state) return
178
+ if (state.child && state.child.exitCode === null) { vscode.window.showInformationMessage('Mün dev is already running for this project.'); return }
179
+ if (!state.toolchain) {
180
+ const config = vscode.workspace.getConfiguration('mun', state.folder.uri)
181
+ state.toolchain = await discoverMunCommand({ cwd: state.root, command: config.get('server.command'), expectedVersion: version })
182
+ }
183
+ clearRuntimeDiagnostics(state)
184
+ devOutput.show(true)
185
+ devOutput.appendLine(`Starting Mün dev: ${state.root}`)
186
+ const child = spawn(state.toolchain.command, [...state.toolchain.args, 'dev', '--project', state.root], { cwd: state.root, env: state.toolchain.env, stdio: ['ignore', 'pipe', 'pipe'] })
187
+ state.child = child
188
+ const append = chunk => devOutput.append(chunk.toString('utf8'))
189
+ child.stdout.on('data', append); child.stderr.on('data', append)
190
+ child.once('error', error => { devOutput.appendLine(`Mün dev failed: ${error.message}`); vscode.window.showErrorMessage(`Mün dev failed: ${error.message}`) })
191
+ child.once('close', code => {
192
+ if (state.child === child) state.child = undefined
193
+ if (state.timer) { clearInterval(state.timer); state.timer = undefined }
194
+ state.snapshot = undefined; state.tree = undefined; clearRuntimeDiagnostics(state); treeProvider.refresh()
195
+ devOutput.appendLine(`Mün dev exited${code === null ? '' : ` (${code})`}.`)
196
+ })
197
+ const poll = () => { void refreshRuntime(state, false) }
198
+ state.timer = setInterval(poll, 500)
199
+ setTimeout(poll, 100)
200
+ }
201
+
202
+ context.subscriptions.push(
203
+ vscode.commands.registerCommand('mun.formatDocument', () => vscode.commands.executeCommand('editor.action.formatDocument')),
204
+ vscode.commands.registerCommand('mun.startDev', async () => { try { await startDev(await pickState()) } catch (error) { vscode.window.showErrorMessage(`Mün dev failed: ${error.message}`) } }),
205
+ vscode.commands.registerCommand('mun.stopDev', async () => { const state = await pickState(); if (state) await stopDev(state) }),
206
+ vscode.commands.registerCommand('mun.restartDev', async () => { const state = await pickState(); if (!state) return; await stopDev(state); await startDev(state) }),
207
+ vscode.commands.registerCommand('mun.inspectRunningApp', async () => { const state = await pickState(); if (state) await refreshRuntime(state, true) }),
208
+ vscode.commands.registerCommand('mun.openRuntimeSource', async (state, node) => {
209
+ if (!node?.source?.file) return
210
+ const document = await vscode.workspace.openTextDocument(vscode.Uri.file(path.resolve(state.root, node.source.file)))
211
+ const editor = await vscode.window.showTextDocument(document)
212
+ const selected = sourceRange(node.source)
213
+ editor.selection = new vscode.Selection(selected.start, selected.end)
214
+ editor.revealRange(selected, vscode.TextEditorRevealType.InCenterIfOutsideViewport)
215
+ }),
216
+ { dispose: () => { for (const state of folderStates.values()) { if (state.timer) clearInterval(state.timer); if (state.child?.exitCode === null) state.child.kill() } folderStates.clear() } },
217
+ )
218
+ }
219
+
220
+ function range(r) { return new vscode.Range(r.start.line, r.start.character, r.end.line, r.end.character) }
221
+ function sourceRange(source) { return new vscode.Range(Math.max(0, source.line - 1), Math.max(0, source.column - 1), Math.max(0, (source.endLine ?? source.line) - 1), Math.max(0, (source.endColumn ?? source.column) - 1)) }
222
+ function location(l) { return new vscode.Location(vscode.Uri.parse(l.uri), range(l.range)) }
223
+ function symbol(s) { const result = new vscode.DocumentSymbol(s.name, s.detail ?? '', s.kind === 23 ? vscode.SymbolKind.Struct : vscode.SymbolKind.Property, range(s.range), range(s.selectionRange)); result.children = (s.children ?? []).map(symbol); return result }
224
+ function selection(s) { return new vscode.SelectionRange(range(s.range), s.parent ? selection(s.parent) : undefined) }
225
+ async function deactivate() { for (const state of folderStates.values()) { if (state.timer) clearInterval(state.timer); if (state.child?.exitCode === null) state.child.kill() } folderStates.clear(); await Promise.all(clients.map(client => client.dispose())); clients = [] }
226
+ module.exports = { activate, deactivate }
@@ -0,0 +1,15 @@
1
+ {
2
+ "comments": { "lineComment": "//", "blockComment": ["/*", "*/"] },
3
+ "brackets": [["{", "}"], ["[", "]"], ["(", ")"]],
4
+ "autoClosingPairs": [
5
+ { "open": "{", "close": "}" },
6
+ { "open": "[", "close": "]" },
7
+ { "open": "(", "close": ")" },
8
+ { "open": "\"", "close": "\"" },
9
+ { "open": "'", "close": "'" }
10
+ ],
11
+ "indentationRules": {
12
+ "increaseIndentPattern": "^.*\\{[^}]*$",
13
+ "decreaseIndentPattern": "^\\s*[}]"
14
+ }
15
+ }
@@ -0,0 +1,119 @@
1
+ {
2
+ "name": "mun-language-support",
3
+ "displayName": "Mün Language Support",
4
+ "description": "Mün language tooling plus native dev, runtime inspection, diagnostics, and source navigation.",
5
+ "version": "0.1.20",
6
+ "publisher": "mun",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/kyooni18/Mun"
10
+ },
11
+ "license": "MIT",
12
+ "files": [
13
+ "extension.cjs",
14
+ "client.mjs",
15
+ "discovery.mjs",
16
+ "dev-client.mjs",
17
+ "protocol.mjs",
18
+ "language-configuration.json",
19
+ "syntaxes",
20
+ "package.json"
21
+ ],
22
+ "engines": {
23
+ "vscode": "^1.85.0"
24
+ },
25
+ "categories": [
26
+ "Programming Languages"
27
+ ],
28
+ "activationEvents": [
29
+ "onLanguage:mun",
30
+ "onCommand:mun.startDev",
31
+ "onCommand:mun.stopDev",
32
+ "onCommand:mun.restartDev",
33
+ "onCommand:mun.inspectRunningApp",
34
+ "onView:mun.runtimeView"
35
+ ],
36
+ "main": "./extension.cjs",
37
+ "contributes": {
38
+ "languages": [
39
+ {
40
+ "id": "mun",
41
+ "aliases": [
42
+ "Mün",
43
+ "Mun",
44
+ "mun"
45
+ ],
46
+ "extensions": [
47
+ ".mun"
48
+ ],
49
+ "configuration": "./language-configuration.json"
50
+ }
51
+ ],
52
+ "grammars": [
53
+ {
54
+ "language": "mun",
55
+ "scopeName": "source.mun",
56
+ "path": "./syntaxes/mun.tmLanguage.json"
57
+ }
58
+ ],
59
+ "commands": [
60
+ {
61
+ "command": "mun.formatDocument",
62
+ "title": "Mün: Format Document"
63
+ },
64
+ {
65
+ "command": "mun.startDev",
66
+ "title": "Mün: Start Dev"
67
+ },
68
+ {
69
+ "command": "mun.stopDev",
70
+ "title": "Mün: Stop Dev"
71
+ },
72
+ {
73
+ "command": "mun.restartDev",
74
+ "title": "Mün: Restart App"
75
+ },
76
+ {
77
+ "command": "mun.inspectRunningApp",
78
+ "title": "Mün: Inspect Running App"
79
+ }
80
+ ],
81
+ "configuration": {
82
+ "title": "Mün",
83
+ "properties": {
84
+ "mun.server.command": {
85
+ "type": "string",
86
+ "default": "",
87
+ "description": "Explicit mun executable. Otherwise use workspace-local @mun-ui/ui before global mun; versions must match the extension."
88
+ }
89
+ }
90
+ },
91
+ "views": {
92
+ "explorer": [
93
+ {
94
+ "id": "mun.runtimeView",
95
+ "name": "Mün Runtime"
96
+ }
97
+ ]
98
+ },
99
+ "menus": {
100
+ "view/title": [
101
+ {
102
+ "command": "mun.startDev",
103
+ "when": "view == mun.runtimeView",
104
+ "group": "navigation@1"
105
+ },
106
+ {
107
+ "command": "mun.inspectRunningApp",
108
+ "when": "view == mun.runtimeView",
109
+ "group": "navigation@2"
110
+ },
111
+ {
112
+ "command": "mun.stopDev",
113
+ "when": "view == mun.runtimeView",
114
+ "group": "navigation@3"
115
+ }
116
+ ]
117
+ }
118
+ }
119
+ }
@@ -0,0 +1,29 @@
1
+ // Bounded JSON-RPC/LSP framing. Shared by the server and lightweight editor client.
2
+ const MAX_MESSAGE = 8 * 1024 * 1024
3
+ export class MessageReader {
4
+ constructor(onMessage, onError) { this.buffer = Buffer.alloc(0); this.onMessage = onMessage; this.onError = onError; this.failed = false }
5
+ feed(chunk) {
6
+ if (this.failed) return
7
+ this.buffer = Buffer.concat([this.buffer, chunk])
8
+ try {
9
+ while (this.buffer.length) {
10
+ const separator = this.buffer.indexOf('\r\n\r\n')
11
+ if (separator < 0) { if (this.buffer.length > 8192) throw new Error('LSP header exceeds 8192 bytes.'); return }
12
+ const headers = this.buffer.subarray(0, separator).toString('ascii')
13
+ const lengths = [...headers.matchAll(/^Content-Length:\s*(\d+)\s*$/gim)]
14
+ if (lengths.length !== 1) throw new Error('LSP requires exactly one Content-Length header.')
15
+ const length = Number(lengths[0][1])
16
+ if (!Number.isSafeInteger(length) || length <= 0 || length > MAX_MESSAGE) throw new Error('LSP Content-Length is outside the supported limit.')
17
+ const start = separator + 4
18
+ if (this.buffer.length < start + length) return
19
+ const body = this.buffer.subarray(start, start + length).toString('utf8')
20
+ this.buffer = this.buffer.subarray(start + length)
21
+ this.onMessage(JSON.parse(body))
22
+ }
23
+ } catch (error) { this.failed = true; this.buffer = Buffer.alloc(0); this.onError(error) }
24
+ }
25
+ }
26
+ export function encode(message) {
27
+ const body = JSON.stringify(message)
28
+ return `Content-Length: ${Buffer.byteLength(body, 'utf8')}\r\n\r\n${body}`
29
+ }
@@ -0,0 +1,130 @@
1
+ {
2
+ "name": "Mün",
3
+ "scopeName": "source.mun",
4
+ "patterns": [
5
+ {
6
+ "include": "#comments"
7
+ },
8
+ {
9
+ "include": "#strings"
10
+ },
11
+ {
12
+ "include": "#keywords"
13
+ },
14
+ {
15
+ "include": "#views"
16
+ },
17
+ {
18
+ "include": "#modifiers"
19
+ },
20
+ {
21
+ "include": "#labels"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "comments": {
26
+ "patterns": [
27
+ {
28
+ "name": "comment.line.double-slash.mun",
29
+ "match": "//.*$"
30
+ },
31
+ {
32
+ "name": "comment.block.mun",
33
+ "begin": "/\\*",
34
+ "end": "\\*/"
35
+ }
36
+ ]
37
+ },
38
+ "strings": {
39
+ "patterns": [
40
+ {
41
+ "name": "string.quoted.double.mun",
42
+ "begin": "\"",
43
+ "end": "\"",
44
+ "patterns": [
45
+ {
46
+ "name": "meta.interpolation.mun",
47
+ "begin": "\\\\\\(",
48
+ "end": "\\)",
49
+ "patterns": [
50
+ {
51
+ "include": "#keywords"
52
+ },
53
+ {
54
+ "include": "#views"
55
+ },
56
+ {
57
+ "include": "#modifiers"
58
+ }
59
+ ]
60
+ },
61
+ {
62
+ "name": "constant.character.escape.mun",
63
+ "match": "\\\\."
64
+ }
65
+ ]
66
+ },
67
+ {
68
+ "name": "string.quoted.single.mun",
69
+ "begin": "'",
70
+ "end": "'",
71
+ "patterns": [
72
+ {
73
+ "name": "constant.character.escape.mun",
74
+ "match": "\\\\."
75
+ }
76
+ ]
77
+ },
78
+ {
79
+ "name": "string.template.mun",
80
+ "begin": "`",
81
+ "end": "`"
82
+ }
83
+ ]
84
+ },
85
+ "keywords": {
86
+ "patterns": [
87
+ {
88
+ "name": "keyword.control.mun",
89
+ "match": "\\b(struct|var|let|some|private|public|init|if|else|switch|case|default|for|in|return|true|false|nil)\\b"
90
+ },
91
+ {
92
+ "name": "storage.type.mun",
93
+ "match": "\\b(View|String|Bool|Int|Double|State|Binding)\\b"
94
+ },
95
+ {
96
+ "name": "storage.modifier.wrapper.mun",
97
+ "match": "@(main|State|Binding)\\b"
98
+ },
99
+ {
100
+ "name": "variable.other.binding.mun",
101
+ "match": "\\$[A-Za-z_][A-Za-z0-9_]*"
102
+ }
103
+ ]
104
+ },
105
+ "views": {
106
+ "patterns": [
107
+ {
108
+ "name": "entity.name.type.view.mun",
109
+ "match": "\\b[A-Z][A-Za-z0-9_$]*(?=\\s*\\()"
110
+ }
111
+ ]
112
+ },
113
+ "modifiers": {
114
+ "patterns": [
115
+ {
116
+ "name": "support.function.modifier.mun",
117
+ "match": "\\.[a-zA-Z_$][A-Za-z0-9_$]*"
118
+ }
119
+ ]
120
+ },
121
+ "labels": {
122
+ "patterns": [
123
+ {
124
+ "name": "entity.name.label.mun",
125
+ "match": "\\b[a-zA-Z_$][A-Za-z0-9_$]*(?=\\s*:)"
126
+ }
127
+ ]
128
+ }
129
+ }
130
+ }