zexus 1.6.2

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 (227) hide show
  1. package/LICENSE +0 -0
  2. package/README.md +2513 -0
  3. package/bin/zexus +2 -0
  4. package/bin/zpics +2 -0
  5. package/bin/zpm +2 -0
  6. package/bin/zx +2 -0
  7. package/bin/zx-deploy +2 -0
  8. package/bin/zx-dev +2 -0
  9. package/bin/zx-run +2 -0
  10. package/package.json +66 -0
  11. package/scripts/README.md +24 -0
  12. package/scripts/postinstall.js +44 -0
  13. package/shared_config.json +24 -0
  14. package/src/README.md +1525 -0
  15. package/src/tests/run_zexus_tests.py +117 -0
  16. package/src/tests/test_all_phases.zx +346 -0
  17. package/src/tests/test_blockchain_features.zx +306 -0
  18. package/src/tests/test_complexity_features.zx +321 -0
  19. package/src/tests/test_core_integration.py +185 -0
  20. package/src/tests/test_phase10_ecosystem.zx +177 -0
  21. package/src/tests/test_phase1_modifiers.zx +87 -0
  22. package/src/tests/test_phase2_plugins.zx +80 -0
  23. package/src/tests/test_phase3_security.zx +97 -0
  24. package/src/tests/test_phase4_vfs.zx +116 -0
  25. package/src/tests/test_phase5_types.zx +117 -0
  26. package/src/tests/test_phase6_metaprogramming.zx +125 -0
  27. package/src/tests/test_phase7_optimization.zx +132 -0
  28. package/src/tests/test_phase9_advanced_types.zx +157 -0
  29. package/src/tests/test_security_features.py +419 -0
  30. package/src/tests/test_security_features.zx +276 -0
  31. package/src/tests/test_simple_zx.zx +1 -0
  32. package/src/tests/test_verification_simple.zx +69 -0
  33. package/src/zexus/__init__.py +28 -0
  34. package/src/zexus/__main__.py +5 -0
  35. package/src/zexus/__pycache__/__init__.cpython-312.pyc +0 -0
  36. package/src/zexus/__pycache__/advanced_types.cpython-312.pyc +0 -0
  37. package/src/zexus/__pycache__/builtin_modules.cpython-312.pyc +0 -0
  38. package/src/zexus/__pycache__/capability_system.cpython-312.pyc +0 -0
  39. package/src/zexus/__pycache__/complexity_system.cpython-312.pyc +0 -0
  40. package/src/zexus/__pycache__/concurrency_system.cpython-312.pyc +0 -0
  41. package/src/zexus/__pycache__/config.cpython-312.pyc +0 -0
  42. package/src/zexus/__pycache__/dependency_injection.cpython-312.pyc +0 -0
  43. package/src/zexus/__pycache__/ecosystem.cpython-312.pyc +0 -0
  44. package/src/zexus/__pycache__/environment.cpython-312.pyc +0 -0
  45. package/src/zexus/__pycache__/error_reporter.cpython-312.pyc +0 -0
  46. package/src/zexus/__pycache__/hybrid_orchestrator.cpython-312.pyc +0 -0
  47. package/src/zexus/__pycache__/lexer.cpython-312.pyc +0 -0
  48. package/src/zexus/__pycache__/metaprogramming.cpython-312.pyc +0 -0
  49. package/src/zexus/__pycache__/module_cache.cpython-312.pyc +0 -0
  50. package/src/zexus/__pycache__/object.cpython-312.pyc +0 -0
  51. package/src/zexus/__pycache__/optimization.cpython-312.pyc +0 -0
  52. package/src/zexus/__pycache__/plugin_system.cpython-312.pyc +0 -0
  53. package/src/zexus/__pycache__/policy_engine.cpython-312.pyc +0 -0
  54. package/src/zexus/__pycache__/security.cpython-312.pyc +0 -0
  55. package/src/zexus/__pycache__/stdlib_integration.cpython-312.pyc +0 -0
  56. package/src/zexus/__pycache__/strategy_recovery.cpython-312.pyc +0 -0
  57. package/src/zexus/__pycache__/syntax_validator.cpython-312.pyc +0 -0
  58. package/src/zexus/__pycache__/type_system.cpython-312.pyc +0 -0
  59. package/src/zexus/__pycache__/virtual_filesystem.cpython-312.pyc +0 -0
  60. package/src/zexus/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  61. package/src/zexus/__pycache__/zexus_token.cpython-312.pyc +0 -0
  62. package/src/zexus/advanced_types.py +401 -0
  63. package/src/zexus/blockchain/__init__.py +40 -0
  64. package/src/zexus/blockchain/__pycache__/__init__.cpython-312.pyc +0 -0
  65. package/src/zexus/blockchain/__pycache__/crypto.cpython-312.pyc +0 -0
  66. package/src/zexus/blockchain/__pycache__/ledger.cpython-312.pyc +0 -0
  67. package/src/zexus/blockchain/__pycache__/transaction.cpython-312.pyc +0 -0
  68. package/src/zexus/blockchain/crypto.py +463 -0
  69. package/src/zexus/blockchain/ledger.py +255 -0
  70. package/src/zexus/blockchain/transaction.py +267 -0
  71. package/src/zexus/builtin_modules.py +284 -0
  72. package/src/zexus/builtin_plugins.py +317 -0
  73. package/src/zexus/capability_system.py +372 -0
  74. package/src/zexus/cli/__init__.py +2 -0
  75. package/src/zexus/cli/__pycache__/__init__.cpython-312.pyc +0 -0
  76. package/src/zexus/cli/__pycache__/main.cpython-312.pyc +0 -0
  77. package/src/zexus/cli/main.py +707 -0
  78. package/src/zexus/cli/zpm.py +203 -0
  79. package/src/zexus/compare_interpreter_compiler.py +146 -0
  80. package/src/zexus/compiler/__init__.py +169 -0
  81. package/src/zexus/compiler/__pycache__/__init__.cpython-312.pyc +0 -0
  82. package/src/zexus/compiler/__pycache__/lexer.cpython-312.pyc +0 -0
  83. package/src/zexus/compiler/__pycache__/parser.cpython-312.pyc +0 -0
  84. package/src/zexus/compiler/__pycache__/zexus_ast.cpython-312.pyc +0 -0
  85. package/src/zexus/compiler/bytecode.py +266 -0
  86. package/src/zexus/compiler/compat_runtime.py +277 -0
  87. package/src/zexus/compiler/lexer.py +257 -0
  88. package/src/zexus/compiler/parser.py +779 -0
  89. package/src/zexus/compiler/semantic.py +118 -0
  90. package/src/zexus/compiler/zexus_ast.py +454 -0
  91. package/src/zexus/complexity_system.py +575 -0
  92. package/src/zexus/concurrency_system.py +493 -0
  93. package/src/zexus/config.py +201 -0
  94. package/src/zexus/crypto_bridge.py +19 -0
  95. package/src/zexus/dependency_injection.py +423 -0
  96. package/src/zexus/ecosystem.py +434 -0
  97. package/src/zexus/environment.py +101 -0
  98. package/src/zexus/environment_manager.py +119 -0
  99. package/src/zexus/error_reporter.py +314 -0
  100. package/src/zexus/evaluator/__init__.py +12 -0
  101. package/src/zexus/evaluator/__pycache__/__init__.cpython-312.pyc +0 -0
  102. package/src/zexus/evaluator/__pycache__/bytecode_compiler.cpython-312.pyc +0 -0
  103. package/src/zexus/evaluator/__pycache__/core.cpython-312.pyc +0 -0
  104. package/src/zexus/evaluator/__pycache__/expressions.cpython-312.pyc +0 -0
  105. package/src/zexus/evaluator/__pycache__/functions.cpython-312.pyc +0 -0
  106. package/src/zexus/evaluator/__pycache__/integration.cpython-312.pyc +0 -0
  107. package/src/zexus/evaluator/__pycache__/statements.cpython-312.pyc +0 -0
  108. package/src/zexus/evaluator/__pycache__/utils.cpython-312.pyc +0 -0
  109. package/src/zexus/evaluator/bytecode_compiler.py +700 -0
  110. package/src/zexus/evaluator/core.py +891 -0
  111. package/src/zexus/evaluator/expressions.py +827 -0
  112. package/src/zexus/evaluator/functions.py +3989 -0
  113. package/src/zexus/evaluator/integration.py +396 -0
  114. package/src/zexus/evaluator/statements.py +4303 -0
  115. package/src/zexus/evaluator/utils.py +126 -0
  116. package/src/zexus/evaluator_original.py +2041 -0
  117. package/src/zexus/external_bridge.py +16 -0
  118. package/src/zexus/find_affected_imports.sh +155 -0
  119. package/src/zexus/hybrid_orchestrator.py +152 -0
  120. package/src/zexus/input_validation.py +259 -0
  121. package/src/zexus/lexer.py +571 -0
  122. package/src/zexus/logging.py +89 -0
  123. package/src/zexus/lsp/__init__.py +9 -0
  124. package/src/zexus/lsp/completion_provider.py +207 -0
  125. package/src/zexus/lsp/definition_provider.py +22 -0
  126. package/src/zexus/lsp/hover_provider.py +71 -0
  127. package/src/zexus/lsp/server.py +269 -0
  128. package/src/zexus/lsp/symbol_provider.py +31 -0
  129. package/src/zexus/metaprogramming.py +321 -0
  130. package/src/zexus/module_cache.py +89 -0
  131. package/src/zexus/module_manager.py +107 -0
  132. package/src/zexus/object.py +973 -0
  133. package/src/zexus/optimization.py +424 -0
  134. package/src/zexus/parser/__init__.py +31 -0
  135. package/src/zexus/parser/__pycache__/__init__.cpython-312.pyc +0 -0
  136. package/src/zexus/parser/__pycache__/parser.cpython-312.pyc +0 -0
  137. package/src/zexus/parser/__pycache__/strategy_context.cpython-312.pyc +0 -0
  138. package/src/zexus/parser/__pycache__/strategy_structural.cpython-312.pyc +0 -0
  139. package/src/zexus/parser/integration.py +86 -0
  140. package/src/zexus/parser/parser.py +3977 -0
  141. package/src/zexus/parser/strategy_context.py +7254 -0
  142. package/src/zexus/parser/strategy_structural.py +1033 -0
  143. package/src/zexus/persistence.py +391 -0
  144. package/src/zexus/plugin_system.py +290 -0
  145. package/src/zexus/policy_engine.py +365 -0
  146. package/src/zexus/profiler/__init__.py +5 -0
  147. package/src/zexus/profiler/profiler.py +233 -0
  148. package/src/zexus/purity_system.py +398 -0
  149. package/src/zexus/runtime/__init__.py +20 -0
  150. package/src/zexus/runtime/async_runtime.py +324 -0
  151. package/src/zexus/search_old_imports.sh +65 -0
  152. package/src/zexus/security.py +1407 -0
  153. package/src/zexus/stack_trace.py +233 -0
  154. package/src/zexus/stdlib/__init__.py +27 -0
  155. package/src/zexus/stdlib/blockchain.py +341 -0
  156. package/src/zexus/stdlib/compression.py +167 -0
  157. package/src/zexus/stdlib/crypto.py +124 -0
  158. package/src/zexus/stdlib/datetime.py +163 -0
  159. package/src/zexus/stdlib/db_mongo.py +199 -0
  160. package/src/zexus/stdlib/db_mysql.py +162 -0
  161. package/src/zexus/stdlib/db_postgres.py +163 -0
  162. package/src/zexus/stdlib/db_sqlite.py +133 -0
  163. package/src/zexus/stdlib/encoding.py +230 -0
  164. package/src/zexus/stdlib/fs.py +195 -0
  165. package/src/zexus/stdlib/http.py +219 -0
  166. package/src/zexus/stdlib/http_server.py +248 -0
  167. package/src/zexus/stdlib/json_module.py +61 -0
  168. package/src/zexus/stdlib/math.py +360 -0
  169. package/src/zexus/stdlib/os_module.py +265 -0
  170. package/src/zexus/stdlib/regex.py +148 -0
  171. package/src/zexus/stdlib/sockets.py +253 -0
  172. package/src/zexus/stdlib/test_framework.zx +208 -0
  173. package/src/zexus/stdlib/test_runner.zx +119 -0
  174. package/src/zexus/stdlib_integration.py +341 -0
  175. package/src/zexus/strategy_recovery.py +256 -0
  176. package/src/zexus/syntax_validator.py +356 -0
  177. package/src/zexus/testing/zpics.py +407 -0
  178. package/src/zexus/testing/zpics_runtime.py +369 -0
  179. package/src/zexus/type_system.py +374 -0
  180. package/src/zexus/validation_system.py +569 -0
  181. package/src/zexus/virtual_filesystem.py +355 -0
  182. package/src/zexus/vm/__init__.py +8 -0
  183. package/src/zexus/vm/__pycache__/__init__.cpython-312.pyc +0 -0
  184. package/src/zexus/vm/__pycache__/async_optimizer.cpython-312.pyc +0 -0
  185. package/src/zexus/vm/__pycache__/bytecode.cpython-312.pyc +0 -0
  186. package/src/zexus/vm/__pycache__/cache.cpython-312.pyc +0 -0
  187. package/src/zexus/vm/__pycache__/jit.cpython-312.pyc +0 -0
  188. package/src/zexus/vm/__pycache__/memory_manager.cpython-312.pyc +0 -0
  189. package/src/zexus/vm/__pycache__/memory_pool.cpython-312.pyc +0 -0
  190. package/src/zexus/vm/__pycache__/optimizer.cpython-312.pyc +0 -0
  191. package/src/zexus/vm/__pycache__/parallel_vm.cpython-312.pyc +0 -0
  192. package/src/zexus/vm/__pycache__/peephole_optimizer.cpython-312.pyc +0 -0
  193. package/src/zexus/vm/__pycache__/profiler.cpython-312.pyc +0 -0
  194. package/src/zexus/vm/__pycache__/register_allocator.cpython-312.pyc +0 -0
  195. package/src/zexus/vm/__pycache__/register_vm.cpython-312.pyc +0 -0
  196. package/src/zexus/vm/__pycache__/ssa_converter.cpython-312.pyc +0 -0
  197. package/src/zexus/vm/__pycache__/vm.cpython-312.pyc +0 -0
  198. package/src/zexus/vm/async_optimizer.py +420 -0
  199. package/src/zexus/vm/bytecode.py +428 -0
  200. package/src/zexus/vm/bytecode_converter.py +297 -0
  201. package/src/zexus/vm/cache.py +532 -0
  202. package/src/zexus/vm/jit.py +720 -0
  203. package/src/zexus/vm/memory_manager.py +520 -0
  204. package/src/zexus/vm/memory_pool.py +511 -0
  205. package/src/zexus/vm/optimizer.py +478 -0
  206. package/src/zexus/vm/parallel_vm.py +899 -0
  207. package/src/zexus/vm/peephole_optimizer.py +452 -0
  208. package/src/zexus/vm/profiler.py +527 -0
  209. package/src/zexus/vm/register_allocator.py +462 -0
  210. package/src/zexus/vm/register_vm.py +520 -0
  211. package/src/zexus/vm/ssa_converter.py +757 -0
  212. package/src/zexus/vm/vm.py +1392 -0
  213. package/src/zexus/zexus_ast.py +1782 -0
  214. package/src/zexus/zexus_token.py +253 -0
  215. package/src/zexus/zpm/__init__.py +15 -0
  216. package/src/zexus/zpm/installer.py +116 -0
  217. package/src/zexus/zpm/package_manager.py +208 -0
  218. package/src/zexus/zpm/publisher.py +98 -0
  219. package/src/zexus/zpm/registry.py +110 -0
  220. package/src/zexus.egg-info/PKG-INFO +2235 -0
  221. package/src/zexus.egg-info/SOURCES.txt +876 -0
  222. package/src/zexus.egg-info/dependency_links.txt +1 -0
  223. package/src/zexus.egg-info/entry_points.txt +3 -0
  224. package/src/zexus.egg-info/not-zip-safe +1 -0
  225. package/src/zexus.egg-info/requires.txt +14 -0
  226. package/src/zexus.egg-info/top_level.txt +2 -0
  227. package/zexus.json +14 -0
@@ -0,0 +1,207 @@
1
+ """Completion provider for Zexus LSP."""
2
+
3
+ from typing import List, Dict, Any
4
+ try:
5
+ from pygls.lsp.types import CompletionItem, CompletionItemKind, Position
6
+ PYGLS_AVAILABLE = True
7
+ except ImportError:
8
+ PYGLS_AVAILABLE = False
9
+
10
+
11
+ # Zexus keywords
12
+ KEYWORDS = [
13
+ 'let', 'const', 'action', 'function', 'lambda', 'return', 'if', 'elif', 'else',
14
+ 'while', 'for', 'each', 'in', 'match', 'case', 'default', 'break', 'continue',
15
+ 'entity', 'data', 'enum', 'protocol', 'interface', 'type_alias', 'implements',
16
+ 'use', 'import', 'export', 'module', 'package', 'from', 'external',
17
+ 'protect', 'verify', 'restrict', 'require', 'assert', 'seal', 'sandbox',
18
+ 'audit', 'trail', 'capability', 'grant', 'revoke', 'validate', 'sanitize',
19
+ 'contract', 'state', 'ledger', 'persistent', 'storage', 'tx', 'gas', 'limit',
20
+ 'hash', 'signature', 'verify_sig', 'emit', 'event', 'revert', 'this',
21
+ 'public', 'private', 'pure', 'view', 'payable', 'modifier', 'sealed', 'secure',
22
+ 'async', 'await', 'channel', 'send', 'receive', 'atomic', 'stream', 'watch',
23
+ 'try', 'catch', 'throw', 'finally', 'defer',
24
+ 'native', 'inline', 'gc', 'buffer', 'simd', 'pattern', 'exactly', 'embedded', 'using',
25
+ 'screen', 'component', 'theme', 'canvas', 'graphics', 'animation', 'clock', 'color',
26
+ 'middleware', 'auth', 'throttle', 'cache', 'inject',
27
+ 'true', 'false', 'null', 'map', 'TX', 'print', 'debug', 'log', 'immutable'
28
+ ]
29
+
30
+ # Built-in functions with their signatures
31
+ BUILTINS = {
32
+ # I/O
33
+ 'print': 'print(value)',
34
+ 'println': 'println(value)',
35
+ 'input': 'input(prompt)',
36
+ 'read_text': 'read_text(path)',
37
+ 'write_text': 'write_text(path, content)',
38
+
39
+ # Type conversion
40
+ 'string': 'string(value)',
41
+ 'int': 'int(value)',
42
+ 'float': 'float(value)',
43
+ 'bool': 'bool(value)',
44
+
45
+ # Collections
46
+ 'len': 'len(collection)',
47
+ 'list': 'list(items...)',
48
+ 'map': 'map(pairs...)', # Map data structure
49
+ 'set': 'set(items...)',
50
+ 'range': 'range(start, end, step)',
51
+
52
+ # Functional
53
+ 'filter': 'filter(collection, predicate)',
54
+ 'map_transform': 'map(collection, transform)', # Functional map
55
+ 'reduce': 'reduce(collection, fn, initial)',
56
+ 'sort': 'sort(collection, comparator)',
57
+ 'reverse': 'reverse(collection)',
58
+
59
+ # String operations
60
+ 'join': 'join(array, separator)',
61
+ 'split': 'split(string, delimiter)',
62
+ 'replace': 'replace(string, old, new)',
63
+ 'uppercase': 'uppercase(string)',
64
+ 'lowercase': 'lowercase(string)',
65
+ 'trim': 'trim(string)',
66
+ 'substring': 'substring(string, start, end)',
67
+
68
+ # Math
69
+ 'abs': 'abs(number)',
70
+ 'ceil': 'ceil(number)',
71
+ 'floor': 'floor(number)',
72
+ 'round': 'round(number, decimals)',
73
+ 'min': 'min(numbers...)',
74
+ 'max': 'max(numbers...)',
75
+ 'sum': 'sum(numbers)',
76
+ 'sqrt': 'sqrt(number)',
77
+ 'pow': 'pow(base, exponent)',
78
+ 'random': 'random() or random(max) or random(min, max)',
79
+
80
+ # Date/Time
81
+ 'now': 'now()',
82
+ 'timestamp': 'timestamp()',
83
+
84
+ # File I/O
85
+ 'file_read_text': 'file_read_text(path)',
86
+ 'file_write_text': 'file_write_text(path, content)',
87
+ 'file_exists': 'file_exists(path)',
88
+ 'file_read_json': 'file_read_json(path)',
89
+ 'file_write_json': 'file_write_json(path, data)',
90
+ 'file_append': 'file_append(path, content)',
91
+ 'file_list_dir': 'file_list_dir(path)',
92
+ 'read_file': 'read_file(path)',
93
+ 'eval_file': 'eval_file(path, language)',
94
+
95
+ # Persistence
96
+ 'persist_set': 'persist_set(key, value)',
97
+ 'persist_get': 'persist_get(key)',
98
+ 'persist_clear': 'persist_clear(key)',
99
+ 'persist_list': 'persist_list()',
100
+
101
+ # Memory
102
+ 'track_memory': 'track_memory()',
103
+ 'memory_stats': 'memory_stats()',
104
+
105
+ # Security
106
+ 'protect': 'protect(function, policy, mode)',
107
+ 'verify': 'verify(condition)',
108
+ 'restrict': 'restrict(value, constraints)',
109
+ 'create_policy': 'create_policy(rules)',
110
+ 'enforce_policy': 'enforce_policy(policy, value)',
111
+
112
+ # Dependency Injection
113
+ 'register_dependency': 'register_dependency(name, impl)',
114
+ 'inject_dependency': 'inject_dependency(name)',
115
+ 'mock_dependency': 'mock_dependency(name, mock)',
116
+ 'test_mode': 'test_mode(enabled)',
117
+
118
+ # Channels
119
+ 'send': 'send(channel, value)',
120
+ 'receive': 'receive(channel)',
121
+ 'close_channel': 'close_channel(channel)',
122
+
123
+ # Blockchain
124
+ 'emit': 'emit(event, ...args)',
125
+ 'require': 'require(condition, message)',
126
+ 'assert': 'assert(condition)',
127
+ 'balance_of': 'balance_of(address)',
128
+ 'transfer': 'transfer(to, amount)',
129
+ 'hash': 'hash(data)',
130
+ 'keccak256': 'keccak256(data)',
131
+ 'signature': 'signature(data, key)',
132
+ 'verify_sig': 'verify_sig(data, sig, key)',
133
+
134
+ # Renderer
135
+ 'define_screen': 'define_screen(name, props)',
136
+ 'define_component': 'define_component(name, props)',
137
+ 'render_screen': 'render_screen(name)',
138
+ 'set_theme': 'set_theme(theme)',
139
+
140
+ # Debug
141
+ 'debug': 'debug(value)',
142
+ 'debug_log': 'debug_log(message, context)',
143
+ 'debug_trace': 'debug_trace()',
144
+ 'is_main': 'is_main()',
145
+ 'exit_program': 'exit_program(code)',
146
+ 'module_info': 'module_info()',
147
+
148
+ # Main entry point
149
+ 'run': 'run(task_fn)',
150
+ 'execute': 'execute(fn)',
151
+ 'on_start': 'on_start(fn)',
152
+ 'on_exit': 'on_exit(fn)',
153
+ 'signal_handler': 'signal_handler(signal, fn)',
154
+ 'schedule': 'schedule(fn, delay)',
155
+ 'sleep': 'sleep(seconds)',
156
+
157
+ # Validation
158
+ 'is_email': 'is_email(string)',
159
+ 'is_url': 'is_url(string)',
160
+ 'is_phone': 'is_phone(string)',
161
+ 'is_numeric': 'is_numeric(string)',
162
+ 'is_alpha': 'is_alpha(string)',
163
+ 'is_alphanumeric': 'is_alphanumeric(string)',
164
+ 'matches_pattern': 'matches_pattern(str, pattern)',
165
+ 'password_strength': 'password_strength(password)',
166
+ 'sanitize_input': 'sanitize_input(text, type)',
167
+ 'validate_length': 'validate_length(str, min, max)',
168
+ 'env_get': 'env_get(name)',
169
+ 'env_set': 'env_set(name, value)',
170
+ 'env_exists': 'env_exists(name)',
171
+ }
172
+
173
+
174
+ class CompletionProvider:
175
+ """Provides completion suggestions for Zexus code."""
176
+
177
+ def get_completions(self, text: str, position: Position, doc_info: Dict[str, Any]) -> List:
178
+ """Get completion items for the given position."""
179
+ if not PYGLS_AVAILABLE:
180
+ return []
181
+
182
+ items = []
183
+
184
+ # Add keywords
185
+ for keyword in KEYWORDS:
186
+ items.append(CompletionItem(
187
+ label=keyword,
188
+ kind=CompletionItemKind.Keyword,
189
+ detail='Keyword',
190
+ documentation=f'Zexus keyword: {keyword}'
191
+ ))
192
+
193
+ # Add built-in functions
194
+ for name, signature in BUILTINS.items():
195
+ items.append(CompletionItem(
196
+ label=name,
197
+ kind=CompletionItemKind.Function,
198
+ detail=signature,
199
+ documentation=f'Built-in function: {signature}',
200
+ insert_text=f'{name}($1)',
201
+ insert_text_format=2 # Snippet format
202
+ ))
203
+
204
+ # TODO: Add user-defined symbols from AST
205
+ # TODO: Add context-aware completions
206
+
207
+ return items
@@ -0,0 +1,22 @@
1
+ """Definition provider for Zexus LSP."""
2
+
3
+ from typing import List, Dict, Any, Optional
4
+ try:
5
+ from pygls.lsp.types import Position
6
+ PYGLS_AVAILABLE = True
7
+ except ImportError:
8
+ PYGLS_AVAILABLE = False
9
+
10
+
11
+ class DefinitionProvider:
12
+ """Provides go-to-definition for Zexus code."""
13
+
14
+ def get_definition(self, uri: str, position: Position, doc_info: Dict[str, Any]) -> Optional[List]:
15
+ """Get definition location for symbol at position."""
16
+ if not PYGLS_AVAILABLE:
17
+ return None
18
+
19
+ # TODO: Implement go-to-definition by analyzing AST
20
+ # For now, return None
21
+
22
+ return None
@@ -0,0 +1,71 @@
1
+ """Hover provider for Zexus LSP."""
2
+
3
+ from typing import Dict, Any, Optional
4
+ try:
5
+ from pygls.lsp.types import Hover, MarkupContent, MarkupKind, Position, Range
6
+ PYGLS_AVAILABLE = True
7
+ except ImportError:
8
+ PYGLS_AVAILABLE = False
9
+
10
+
11
+ class HoverProvider:
12
+ """Provides hover information for Zexus code."""
13
+
14
+ def get_hover(self, position: Position, doc_info: Dict[str, Any]) -> Optional[Hover]:
15
+ """Get hover information for the given position."""
16
+ if not PYGLS_AVAILABLE:
17
+ return None
18
+
19
+ text = doc_info.get('text', '')
20
+
21
+ # Get word at position
22
+ lines = text.split('\n')
23
+ if position.line >= len(lines):
24
+ return None
25
+
26
+ line = lines[position.line]
27
+ if position.character >= len(line):
28
+ return None
29
+
30
+ # Find word boundaries
31
+ start = position.character
32
+ end = position.character
33
+
34
+ while start > 0 and (line[start - 1].isalnum() or line[start - 1] == '_'):
35
+ start -= 1
36
+
37
+ while end < len(line) and (line[end].isalnum() or line[end] == '_'):
38
+ end += 1
39
+
40
+ word = line[start:end]
41
+
42
+ if not word:
43
+ return None
44
+
45
+ # Provide documentation for keywords and built-ins
46
+ docs = {
47
+ 'let': 'Declare a mutable variable',
48
+ 'const': 'Declare an immutable constant',
49
+ 'action': 'Define a function/action',
50
+ 'contract': 'Define a smart contract',
51
+ 'entity': 'Define a data structure',
52
+ 'verify': 'Runtime verification with custom logic',
53
+ 'protect': 'Apply security policy to function',
54
+ 'print': 'Print value to console',
55
+ 'len': 'Get length of collection',
56
+ # Add more...
57
+ }
58
+
59
+ if word in docs:
60
+ return Hover(
61
+ contents=MarkupContent(
62
+ kind=MarkupKind.Markdown,
63
+ value=f'**{word}**\n\n{docs[word]}'
64
+ ),
65
+ range=Range(
66
+ start=Position(line=position.line, character=start),
67
+ end=Position(line=position.line, character=end)
68
+ )
69
+ )
70
+
71
+ return None
@@ -0,0 +1,269 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Zexus Language Server
4
+ Implements LSP for Zexus language providing IntelliSense and other features.
5
+ """
6
+
7
+ import logging
8
+ import sys
9
+ from typing import List, Optional
10
+
11
+ # Configure logging first before any imports that might fail
12
+ logging.basicConfig(
13
+ level=logging.INFO,
14
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
15
+ stream=sys.stderr
16
+ )
17
+
18
+ logger = logging.getLogger(__name__)
19
+
20
+ try:
21
+ from pygls.server import LanguageServer
22
+ from pygls.lsp.methods import (
23
+ TEXT_DOCUMENT_DID_OPEN,
24
+ TEXT_DOCUMENT_DID_CHANGE,
25
+ TEXT_DOCUMENT_DID_SAVE,
26
+ TEXT_DOCUMENT_COMPLETION,
27
+ TEXT_DOCUMENT_HOVER,
28
+ TEXT_DOCUMENT_DEFINITION,
29
+ TEXT_DOCUMENT_REFERENCES,
30
+ TEXT_DOCUMENT_DOCUMENT_SYMBOL,
31
+ TEXT_DOCUMENT_FORMATTING,
32
+ TEXT_DOCUMENT_SIGNATURE_HELP,
33
+ )
34
+ from pygls.lsp.types import (
35
+ CompletionItem,
36
+ CompletionItemKind,
37
+ CompletionList,
38
+ CompletionParams,
39
+ DidOpenTextDocumentParams,
40
+ DidChangeTextDocumentParams,
41
+ DidSaveTextDocumentParams,
42
+ Hover,
43
+ HoverParams,
44
+ Location,
45
+ MarkupContent,
46
+ MarkupKind,
47
+ Position,
48
+ Range,
49
+ TextDocumentPositionParams,
50
+ DocumentSymbol,
51
+ DocumentSymbolParams,
52
+ SymbolKind,
53
+ DocumentFormattingParams,
54
+ TextEdit,
55
+ SignatureHelp,
56
+ SignatureInformation,
57
+ ParameterInformation,
58
+ SignatureHelpParams,
59
+ )
60
+ PYGLS_AVAILABLE = True
61
+ except ImportError:
62
+ PYGLS_AVAILABLE = False
63
+ logger.error("pygls not installed. Install with: pip install pygls")
64
+
65
+ # Import Zexus modules - these should always be available if zexus is installed
66
+ try:
67
+ from zexus.lexer import Lexer
68
+ from zexus.parser import Parser
69
+ from zexus.evaluator.core import Evaluator
70
+ from .completion_provider import CompletionProvider
71
+ from .symbol_provider import SymbolProvider
72
+ from .hover_provider import HoverProvider
73
+ from .definition_provider import DefinitionProvider
74
+ ZEXUS_AVAILABLE = True
75
+ except ImportError as e:
76
+ ZEXUS_AVAILABLE = False
77
+ logger.error(f"Zexus modules not available: {e}")
78
+ logger.error("Make sure Zexus is properly installed: pip install -e .")
79
+
80
+
81
+ if PYGLS_AVAILABLE:
82
+ if not ZEXUS_AVAILABLE:
83
+ logger.error("Error: Zexus modules not available. LSP server cannot start.")
84
+ raise RuntimeError("Zexus modules not available. LSP server cannot start.")
85
+
86
+ class ZexusLanguageServer(LanguageServer):
87
+ """Zexus Language Server implementation."""
88
+
89
+ def __init__(self):
90
+ super().__init__('zexus-language-server', 'v1.6.2')
91
+ self.completion_provider = CompletionProvider()
92
+ self.symbol_provider = SymbolProvider()
93
+ self.hover_provider = HoverProvider()
94
+ self.definition_provider = DefinitionProvider()
95
+ self.documents = {} # Store parsed documents
96
+
97
+
98
+ server = ZexusLanguageServer()
99
+
100
+
101
+ @server.feature(TEXT_DOCUMENT_DID_OPEN)
102
+ async def did_open(ls: ZexusLanguageServer, params: DidOpenTextDocumentParams):
103
+ """Handle document open event."""
104
+ logger.info(f"Document opened: {params.text_document.uri}")
105
+ uri = params.text_document.uri
106
+ text = params.text_document.text
107
+
108
+ # Parse the document
109
+ try:
110
+ lexer = Lexer(text)
111
+ tokens = lexer.tokenize()
112
+ parser = Parser(tokens)
113
+ ast = parser.parse()
114
+ ls.documents[uri] = {
115
+ 'text': text,
116
+ 'ast': ast,
117
+ 'tokens': tokens
118
+ }
119
+ logger.info(f"Document parsed successfully: {uri}")
120
+ except Exception as e:
121
+ logger.error(f"Error parsing document {uri}: {e}")
122
+ ls.documents[uri] = {
123
+ 'text': text,
124
+ 'ast': None,
125
+ 'tokens': []
126
+ }
127
+
128
+
129
+ @server.feature(TEXT_DOCUMENT_DID_CHANGE)
130
+ async def did_change(ls: ZexusLanguageServer, params: DidChangeTextDocumentParams):
131
+ """Handle document change event."""
132
+ uri = params.text_document.uri
133
+ changes = params.content_changes
134
+
135
+ if changes:
136
+ text = changes[0].text
137
+ # Re-parse the document
138
+ try:
139
+ lexer = Lexer(text)
140
+ tokens = lexer.tokenize()
141
+ parser = Parser(tokens)
142
+ ast = parser.parse()
143
+ ls.documents[uri] = {
144
+ 'text': text,
145
+ 'ast': ast,
146
+ 'tokens': tokens
147
+ }
148
+ except Exception as e:
149
+ logger.error(f"Error parsing document {uri}: {e}")
150
+ ls.documents[uri] = {
151
+ 'text': text,
152
+ 'ast': None,
153
+ 'tokens': []
154
+ }
155
+
156
+
157
+ @server.feature(TEXT_DOCUMENT_DID_SAVE)
158
+ async def did_save(ls: ZexusLanguageServer, params: DidSaveTextDocumentParams):
159
+ """Handle document save event."""
160
+ logger.info(f"Document saved: {params.text_document.uri}")
161
+
162
+
163
+ @server.feature(TEXT_DOCUMENT_COMPLETION)
164
+ async def completions(ls: ZexusLanguageServer, params: CompletionParams) -> CompletionList:
165
+ """Provide completion items."""
166
+ uri = params.text_document.uri
167
+ position = params.position
168
+
169
+ doc_info = ls.documents.get(uri, {})
170
+ text = doc_info.get('text', '')
171
+
172
+ items = ls.completion_provider.get_completions(text, position, doc_info)
173
+ return CompletionList(is_incomplete=False, items=items)
174
+
175
+
176
+ @server.feature(TEXT_DOCUMENT_HOVER)
177
+ async def hover(ls: ZexusLanguageServer, params: HoverParams) -> Optional[Hover]:
178
+ """Provide hover information."""
179
+ uri = params.text_document.uri
180
+ position = params.position
181
+
182
+ doc_info = ls.documents.get(uri, {})
183
+
184
+ return ls.hover_provider.get_hover(position, doc_info)
185
+
186
+
187
+ @server.feature(TEXT_DOCUMENT_DEFINITION)
188
+ async def definition(ls: ZexusLanguageServer, params: TextDocumentPositionParams) -> Optional[List[Location]]:
189
+ """Provide go-to-definition."""
190
+ uri = params.text_document.uri
191
+ position = params.position
192
+
193
+ doc_info = ls.documents.get(uri, {})
194
+
195
+ return ls.definition_provider.get_definition(uri, position, doc_info)
196
+
197
+
198
+ @server.feature(TEXT_DOCUMENT_DOCUMENT_SYMBOL)
199
+ async def document_symbols(ls: ZexusLanguageServer, params: DocumentSymbolParams) -> List[DocumentSymbol]:
200
+ """Provide document symbols for outline view."""
201
+ uri = params.text_document.uri
202
+ doc_info = ls.documents.get(uri, {})
203
+
204
+ return ls.symbol_provider.get_symbols(doc_info)
205
+
206
+
207
+ @server.feature(TEXT_DOCUMENT_FORMATTING)
208
+ async def formatting(ls: ZexusLanguageServer, params: DocumentFormattingParams) -> List[TextEdit]:
209
+ """Format document."""
210
+ # TODO: Implement code formatting
211
+ return []
212
+
213
+
214
+ @server.feature(TEXT_DOCUMENT_SIGNATURE_HELP)
215
+ async def signature_help(ls: ZexusLanguageServer, params: SignatureHelpParams) -> Optional[SignatureHelp]:
216
+ """Provide signature help for function calls."""
217
+ uri = params.text_document.uri
218
+ position = params.position
219
+
220
+ doc_info = ls.documents.get(uri, {})
221
+ text = doc_info.get('text', '')
222
+
223
+ # Get current line
224
+ lines = text.split('\n')
225
+ if position.line >= len(lines):
226
+ return None
227
+
228
+ current_line = lines[position.line][:position.character]
229
+
230
+ # Simple signature help for built-in functions
231
+ # TODO: Make this more sophisticated by parsing AST
232
+ builtins_signatures = {
233
+ 'print': SignatureInformation(
234
+ label='print(value)',
235
+ documentation='Print value to console',
236
+ parameters=[ParameterInformation(label='value', documentation='Value to print')]
237
+ ),
238
+ 'len': SignatureInformation(
239
+ label='len(collection)',
240
+ documentation='Get length of collection',
241
+ parameters=[ParameterInformation(label='collection', documentation='Collection to measure')]
242
+ ),
243
+ # Add more built-ins...
244
+ }
245
+
246
+ # Find which function is being called
247
+ for func_name, sig in builtins_signatures.items():
248
+ if func_name + '(' in current_line:
249
+ return SignatureHelp(
250
+ signatures=[sig],
251
+ active_signature=0,
252
+ active_parameter=0
253
+ )
254
+
255
+ return None
256
+
257
+
258
+ def main():
259
+ """Start the language server."""
260
+ logger.info("Starting Zexus Language Server...")
261
+ server.start_io()
262
+
263
+
264
+ if __name__ == '__main__':
265
+ main()
266
+ else:
267
+ def main():
268
+ print("Error: pygls is not installed. Please install it with: pip install pygls", file=sys.stderr)
269
+ sys.exit(1)
@@ -0,0 +1,31 @@
1
+ """Symbol provider for Zexus LSP."""
2
+
3
+ from typing import List, Dict, Any
4
+ try:
5
+ from pygls.lsp.types import (DocumentSymbol, SymbolKind, Range, Position)
6
+ PYGLS_AVAILABLE = True
7
+ except ImportError:
8
+ PYGLS_AVAILABLE = False
9
+ # Define minimal stubs when pygls not available
10
+ class SymbolKind:
11
+ pass
12
+
13
+
14
+ class SymbolProvider:
15
+ """Provides document symbols for outline view."""
16
+
17
+ def get_symbols(self, doc_info: Dict[str, Any]) -> List:
18
+ """Get document symbols from AST."""
19
+ if not PYGLS_AVAILABLE:
20
+ return []
21
+
22
+ symbols = []
23
+ ast = doc_info.get('ast')
24
+
25
+ if not ast:
26
+ return symbols
27
+
28
+ # TODO: Walk AST and extract symbols
29
+ # For now, return empty list
30
+
31
+ return symbols