jaclang 0.8.9__py3-none-any.whl → 0.8.10__py3-none-any.whl
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.
Potentially problematic release.
This version of jaclang might be problematic. Click here for more details.
- jaclang/cli/cli.py +147 -25
- jaclang/cli/cmdreg.py +144 -8
- jaclang/compiler/__init__.py +6 -1
- jaclang/compiler/codeinfo.py +16 -1
- jaclang/compiler/constant.py +33 -13
- jaclang/compiler/jac.lark +130 -31
- jaclang/compiler/larkparse/jac_parser.py +2 -2
- jaclang/compiler/parser.py +567 -176
- jaclang/compiler/passes/__init__.py +2 -1
- jaclang/compiler/passes/ast_gen/__init__.py +5 -0
- jaclang/compiler/passes/ast_gen/base_ast_gen_pass.py +54 -0
- jaclang/compiler/passes/ast_gen/jsx_processor.py +344 -0
- jaclang/compiler/passes/ecmascript/__init__.py +25 -0
- jaclang/compiler/passes/ecmascript/es_unparse.py +576 -0
- jaclang/compiler/passes/ecmascript/esast_gen_pass.py +2068 -0
- jaclang/compiler/passes/ecmascript/estree.py +972 -0
- jaclang/compiler/passes/ecmascript/tests/__init__.py +1 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/advanced_language_features.jac +170 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/class_separate_impl.impl.jac +30 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/class_separate_impl.jac +14 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/client_jsx.jac +89 -0
- jaclang/compiler/passes/ecmascript/tests/fixtures/core_language_features.jac +195 -0
- jaclang/compiler/passes/ecmascript/tests/test_esast_gen_pass.py +167 -0
- jaclang/compiler/passes/ecmascript/tests/test_js_generation.py +239 -0
- jaclang/compiler/passes/main/__init__.py +0 -3
- jaclang/compiler/passes/main/annex_pass.py +23 -1
- jaclang/compiler/passes/main/pyast_gen_pass.py +324 -234
- jaclang/compiler/passes/main/pyast_load_pass.py +46 -11
- jaclang/compiler/passes/main/pyjac_ast_link_pass.py +2 -0
- jaclang/compiler/passes/main/sym_tab_build_pass.py +18 -1
- jaclang/compiler/passes/main/tests/fixtures/autoimpl.cl.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_arity.jac +3 -0
- jaclang/compiler/passes/main/tests/fixtures/checker_class_construct.jac +33 -0
- jaclang/compiler/passes/main/tests/fixtures/defuse_modpath.jac +7 -0
- jaclang/compiler/passes/main/tests/fixtures/member_access_type_resolve.jac +2 -1
- jaclang/compiler/passes/main/tests/test_checker_pass.py +31 -2
- jaclang/compiler/passes/main/tests/test_def_use_pass.py +12 -0
- jaclang/compiler/passes/main/tests/test_import_pass.py +23 -4
- jaclang/compiler/passes/main/tests/test_pyast_gen_pass.py +25 -0
- jaclang/compiler/passes/main/type_checker_pass.py +7 -0
- jaclang/compiler/passes/tool/doc_ir_gen_pass.py +115 -0
- jaclang/compiler/passes/tool/fuse_comments_pass.py +1 -10
- jaclang/compiler/passes/tool/tests/test_jac_format_pass.py +4 -1
- jaclang/compiler/passes/transform.py +9 -1
- jaclang/compiler/passes/uni_pass.py +5 -7
- jaclang/compiler/program.py +22 -25
- jaclang/compiler/tests/test_client_codegen.py +113 -0
- jaclang/compiler/tests/test_importer.py +12 -10
- jaclang/compiler/tests/test_parser.py +249 -3
- jaclang/compiler/type_system/type_evaluator.jac +169 -50
- jaclang/compiler/type_system/type_utils.py +1 -1
- jaclang/compiler/type_system/types.py +6 -0
- jaclang/compiler/unitree.py +430 -84
- jaclang/langserve/engine.jac +224 -288
- jaclang/langserve/sem_manager.jac +12 -8
- jaclang/langserve/server.jac +48 -48
- jaclang/langserve/tests/fixtures/greet.py +17 -0
- jaclang/langserve/tests/fixtures/md_path.jac +22 -0
- jaclang/langserve/tests/fixtures/user.jac +15 -0
- jaclang/langserve/tests/test_server.py +66 -371
- jaclang/lib.py +1 -1
- jaclang/runtimelib/client_bundle.py +169 -0
- jaclang/runtimelib/client_runtime.jac +586 -0
- jaclang/runtimelib/constructs.py +2 -0
- jaclang/runtimelib/machine.py +259 -100
- jaclang/runtimelib/meta_importer.py +111 -22
- jaclang/runtimelib/mtp.py +15 -0
- jaclang/runtimelib/server.py +1089 -0
- jaclang/runtimelib/tests/fixtures/client_app.jac +18 -0
- jaclang/runtimelib/tests/fixtures/custom_access_validation.jac +1 -1
- jaclang/runtimelib/tests/fixtures/savable_object.jac +4 -5
- jaclang/runtimelib/tests/fixtures/serve_api.jac +75 -0
- jaclang/runtimelib/tests/test_client_bundle.py +55 -0
- jaclang/runtimelib/tests/test_client_render.py +63 -0
- jaclang/runtimelib/tests/test_serve.py +1069 -0
- jaclang/settings.py +0 -2
- jaclang/tests/fixtures/iife_functions.jac +142 -0
- jaclang/tests/fixtures/iife_functions_client.jac +143 -0
- jaclang/tests/fixtures/multistatement_lambda.jac +116 -0
- jaclang/tests/fixtures/multistatement_lambda_client.jac +113 -0
- jaclang/tests/fixtures/needs_import_dup.jac +6 -4
- jaclang/tests/fixtures/py_run.py +7 -5
- jaclang/tests/fixtures/pyfunc_fstr.py +2 -2
- jaclang/tests/fixtures/simple_lambda_test.jac +12 -0
- jaclang/tests/test_cli.py +1 -1
- jaclang/tests/test_language.py +10 -39
- jaclang/tests/test_reference.py +17 -2
- jaclang/utils/NonGPT.py +375 -0
- jaclang/utils/helpers.py +44 -16
- jaclang/utils/lang_tools.py +31 -4
- jaclang/utils/tests/test_lang_tools.py +1 -1
- jaclang/utils/treeprinter.py +8 -3
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/METADATA +3 -3
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/RECORD +96 -66
- jaclang/compiler/passes/main/binder_pass.py +0 -594
- jaclang/compiler/passes/main/tests/fixtures/sym_binder.jac +0 -47
- jaclang/compiler/passes/main/tests/test_binder_pass.py +0 -111
- jaclang/langserve/tests/session.jac +0 -294
- jaclang/langserve/tests/test_dev_server.py +0 -80
- jaclang/runtimelib/importer.py +0 -351
- jaclang/tests/test_typecheck.py +0 -542
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/WHEEL +0 -0
- {jaclang-0.8.9.dist-info → jaclang-0.8.10.dist-info}/entry_points.txt +0 -0
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"""Test Binder pass."""
|
|
2
|
-
|
|
3
|
-
from jaclang.compiler.program import JacProgram
|
|
4
|
-
from jaclang.utils.symtable_test_helpers import SymTableTestMixin
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class BinderPassTests( SymTableTestMixin):
|
|
8
|
-
"""Test pass module."""
|
|
9
|
-
|
|
10
|
-
def setUp(self) -> None:
|
|
11
|
-
"""Set up test."""
|
|
12
|
-
return super().setUp()
|
|
13
|
-
|
|
14
|
-
def test_glob_sym_build(self) -> None:
|
|
15
|
-
"""Test symbol table construction for symbol_binding_test.jac fixture."""
|
|
16
|
-
mod_targ = JacProgram().bind(self.fixture_abs_path("sym_binder.jac"))
|
|
17
|
-
sym_table = mod_targ.sym_tab
|
|
18
|
-
|
|
19
|
-
#currenlty 'aa' is not in the main table, need fix #TODO
|
|
20
|
-
# defns=[(9, 6), (16, 5), (27, 9), (32, 5)],
|
|
21
|
-
# uses=[(33, 11), (37, 11)]
|
|
22
|
-
# Test global variable 'aa'
|
|
23
|
-
self.assert_symbol_complete(
|
|
24
|
-
sym_table, "aa", "variable",
|
|
25
|
-
decl=(9, 6),
|
|
26
|
-
defns=[(9, 6), (16, 5), ],
|
|
27
|
-
uses=[ (37, 11)]
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
# Test global variable 'n'
|
|
31
|
-
self.assert_symbol_complete(
|
|
32
|
-
sym_table, "n", "variable",
|
|
33
|
-
decl=(14, 5),
|
|
34
|
-
defns=[(14, 5)]
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
# Test imported module 'M1'
|
|
38
|
-
self.assert_symbol_complete(
|
|
39
|
-
sym_table, "M1", "module",
|
|
40
|
-
decl=(1, 8),
|
|
41
|
-
defns=[(1, 8)]
|
|
42
|
-
)
|
|
43
|
-
|
|
44
|
-
# Test global variable 'z'
|
|
45
|
-
self.assert_symbol_complete(
|
|
46
|
-
sym_table, "z", "variable",
|
|
47
|
-
decl=(15, 5),
|
|
48
|
-
defns=[(15, 5)]
|
|
49
|
-
)
|
|
50
|
-
|
|
51
|
-
# Test global variable 'Y'
|
|
52
|
-
self.assert_symbol_complete(
|
|
53
|
-
sym_table, "Y", "variable",
|
|
54
|
-
decl=(11, 5),
|
|
55
|
-
defns=[(11, 5), (12, 5), (19, 5)],
|
|
56
|
-
uses=[(15, 9)]
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
# Test ability 'ccc'
|
|
60
|
-
self.assert_symbol_complete(
|
|
61
|
-
sym_table, "ccc", "ability",
|
|
62
|
-
decl=(22, 5),
|
|
63
|
-
defns=[(22, 5)],
|
|
64
|
-
uses=[(36, 5)]
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
#TODO: Fix the following test, 'bb' is not in the main table
|
|
68
|
-
# # Test global variable 'bb'
|
|
69
|
-
# self.assert_symbol_complete(
|
|
70
|
-
# sym_table, "bb", "variable",
|
|
71
|
-
# decl=(26, 17),
|
|
72
|
-
# defns=[(26, 17), (28, 9)]
|
|
73
|
-
# )
|
|
74
|
-
|
|
75
|
-
# Test sub-table for ability 'ccc'
|
|
76
|
-
ccc_table = self.assert_sub_table_exists(sym_table, "ccc",'ability')
|
|
77
|
-
|
|
78
|
-
# Test sub-table for if statement inside 'ccc'
|
|
79
|
-
if_table = self.assert_sub_table_exists(ccc_table, "IfStmt",'variable')
|
|
80
|
-
|
|
81
|
-
# Test local variable 'p' inside if statement
|
|
82
|
-
self.assert_symbol_complete(
|
|
83
|
-
if_table, "p", "variable",
|
|
84
|
-
decl=(29, 9),
|
|
85
|
-
defns=[(29, 9)]
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
def test_symbol_table_structure(self) -> None:
|
|
89
|
-
"""Test the overall structure of the symbol table."""
|
|
90
|
-
mod_targ = JacProgram().build(self.fixture_abs_path("sym_binder.jac"))
|
|
91
|
-
sym_table = mod_targ.sym_tab
|
|
92
|
-
|
|
93
|
-
# Verify main module table exists
|
|
94
|
-
self.assertIn("sym_binder", str(sym_table))
|
|
95
|
-
|
|
96
|
-
# Verify expected number of symbols in main table
|
|
97
|
-
main_symbols = ["aa", "n", "M1", "z", "Y", "ccc"]
|
|
98
|
-
# 'bb' is not here:need fix #TODO
|
|
99
|
-
for symbol_name in main_symbols:
|
|
100
|
-
self.assert_symbol_exists(sym_table, symbol_name)
|
|
101
|
-
|
|
102
|
-
# Verify sub-tables exist
|
|
103
|
-
sub_tables = sym_table.kid_scope
|
|
104
|
-
self.assertTrue(len(sub_tables) > 0, "No sub-tables found")
|
|
105
|
-
|
|
106
|
-
# Verify ability sub-table has nested if-statement table
|
|
107
|
-
ccc_table = self.assert_sub_table_exists(sym_table, "ccc", 'ability')
|
|
108
|
-
if_table = self.assert_sub_table_exists(ccc_table, "IfStmt", 'variable')
|
|
109
|
-
|
|
110
|
-
# Verify if-statement table contains local variable
|
|
111
|
-
self.assert_symbol_exists(if_table, "p")
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
"""Provides LSP session helpers for testing."""
|
|
2
|
-
|
|
3
|
-
import os;
|
|
4
|
-
import subprocess;
|
|
5
|
-
import sys;
|
|
6
|
-
import from concurrent.futures { Future, ThreadPoolExecutor }
|
|
7
|
-
import from threading { Event }
|
|
8
|
-
|
|
9
|
-
import from pylsp_jsonrpc.dispatchers { MethodDispatcher }
|
|
10
|
-
import from pylsp_jsonrpc.endpoint { Endpoint }
|
|
11
|
-
import from pylsp_jsonrpc.streams { JsonRpcStreamReader, JsonRpcStreamWriter }
|
|
12
|
-
|
|
13
|
-
import defaults;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
with entry {
|
|
17
|
-
LSP_EXIT_TIMEOUT = 5000;
|
|
18
|
-
PUBLISH_DIAGNOSTICS = 'textDocument/publishDiagnostics';
|
|
19
|
-
WINDOW_LOG_MESSAGE = 'window/logMessage';
|
|
20
|
-
WINDOW_SHOW_MESSAGE = 'window/showMessage';
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"""Send and Receive messages over LSP as a test LS Client."""
|
|
25
|
-
class LspSession (MethodDispatcher) {
|
|
26
|
-
def init(self: LspSession, cwd: Any = None) {
|
|
27
|
-
self.cwd = cwd if cwd else os.getcwd() ;
|
|
28
|
-
self._thread_pool = ThreadPoolExecutor();
|
|
29
|
-
self._sub = None;
|
|
30
|
-
self._writer = None;
|
|
31
|
-
self._reader = None;
|
|
32
|
-
self._endpoint = None;
|
|
33
|
-
self._notification_callbacks = {};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
"""Context manager entrypoint.\n\n shell=True needed for pytest-cov to work in subprocess.\n """
|
|
37
|
-
def __enter__(self: LspSession) {
|
|
38
|
-
self._sub = subprocess.Popen(
|
|
39
|
-
["jac", "run",
|
|
40
|
-
os.path.join(os.path.dirname(os.path.dirname(__file__)), 'server.jac')],
|
|
41
|
-
stdout=subprocess.PIPE,
|
|
42
|
-
stdin=subprocess.PIPE,
|
|
43
|
-
stderr=subprocess.DEVNULL,
|
|
44
|
-
bufsize=0,
|
|
45
|
-
cwd=self.cwd,
|
|
46
|
-
env=os.environ,
|
|
47
|
-
shell=('WITH_COVERAGE' in os.environ)
|
|
48
|
-
);
|
|
49
|
-
self._writer = JsonRpcStreamWriter(os.fdopen(self._sub.stdin.fileno(), 'wb'));
|
|
50
|
-
self._reader = JsonRpcStreamReader(os.fdopen(self._sub.stdout.fileno(), 'rb'));
|
|
51
|
-
dispatcher =
|
|
52
|
-
{PUBLISH_DIAGNOSTICS : self._publish_diagnostics , WINDOW_SHOW_MESSAGE : self._window_show_message , WINDOW_LOG_MESSAGE : self._window_log_message };
|
|
53
|
-
self._endpoint = Endpoint(dispatcher, self._writer.write);
|
|
54
|
-
self._thread_pool.submit(self._reader.listen, self._endpoint.consume);
|
|
55
|
-
return self;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
def __exit__(self: LspSession, typ: Any, value: Any, _tb: Any) {
|
|
59
|
-
self.shutdown(True);
|
|
60
|
-
try {
|
|
61
|
-
self._sub.terminate();
|
|
62
|
-
} except Exception as e {
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
self._endpoint.shutdown();
|
|
67
|
-
self._thread_pool.shutdown();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
"""Sends the initialize request to LSP server."""
|
|
71
|
-
def initialize(
|
|
72
|
-
self: LspSession,
|
|
73
|
-
initialize_params: Any = None,
|
|
74
|
-
process_server_capabilities: Any = None
|
|
75
|
-
) {
|
|
76
|
-
server_initialized = Event();
|
|
77
|
-
def _after_initialize(fut: Any) {
|
|
78
|
-
if process_server_capabilities {
|
|
79
|
-
process_server_capabilities(fut.result());
|
|
80
|
-
}
|
|
81
|
-
self.initialized();
|
|
82
|
-
server_initialized.set();
|
|
83
|
-
}
|
|
84
|
-
self._send_request(
|
|
85
|
-
'initialize',
|
|
86
|
-
params=initialize_params
|
|
87
|
-
if (initialize_params is not None)
|
|
88
|
-
else defaults.VSCODE_DEFAULT_INITIALIZE
|
|
89
|
-
,
|
|
90
|
-
handle_response=_after_initialize
|
|
91
|
-
);
|
|
92
|
-
server_initialized.wait();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
"""Sends the initialized notification to LSP server."""
|
|
96
|
-
def initialized(self: LspSession, initialized_params: Any = None) {
|
|
97
|
-
if (initialized_params is None) {
|
|
98
|
-
initialized_params = {};
|
|
99
|
-
}
|
|
100
|
-
self._endpoint.notify('initialized', initialized_params);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
"""Sends the shutdown request to LSP server."""
|
|
104
|
-
def shutdown(
|
|
105
|
-
self: LspSession,
|
|
106
|
-
should_exit: Any,
|
|
107
|
-
exit_timeout: Any = LSP_EXIT_TIMEOUT
|
|
108
|
-
) {
|
|
109
|
-
def _after_shutdown(_: Any) {
|
|
110
|
-
if should_exit {
|
|
111
|
-
self.exit_lsp(exit_timeout);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
self._send_request('shutdown', handle_response=_after_shutdown);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
"""Handles LSP server process exit."""
|
|
118
|
-
def exit_lsp(self: LspSession, exit_timeout: Any = LSP_EXIT_TIMEOUT) {
|
|
119
|
-
self._endpoint.notify('exit');
|
|
120
|
-
assert (self._sub.wait(exit_timeout) == 0) ;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
"""Sends text document completion request to LSP server."""
|
|
124
|
-
def text_document_completion(self: LspSession, completion_params: Any) {
|
|
125
|
-
fut = self._send_request('textDocument/completion', params=completion_params);
|
|
126
|
-
return fut.result();
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
"""Sends text document rename request to LSP server."""
|
|
130
|
-
def text_document_rename(self: LspSession, rename_params: Any) {
|
|
131
|
-
fut = self._send_request('textDocument/rename', params=rename_params);
|
|
132
|
-
return fut.result();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
"""Sends text document code action request to LSP server."""
|
|
136
|
-
def text_document_code_action(self: LspSession, code_action_params: Any) {
|
|
137
|
-
fut = self._send_request('textDocument/codeAction', params=code_action_params);
|
|
138
|
-
return fut.result();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
"""Sends text document hover request to LSP server."""
|
|
142
|
-
def text_document_hover(self: LspSession, hover_params: Any) {
|
|
143
|
-
fut = self._send_request('textDocument/hover', params=hover_params);
|
|
144
|
-
return fut.result();
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
"""Sends text document formatting request to LSP server."""
|
|
148
|
-
def text_document_formatting(self: LspSession, formatting_params: Any) {
|
|
149
|
-
fut = self._send_request('textDocument/formatting', params=formatting_params);
|
|
150
|
-
return fut.result();
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
"""Sends text document hover request to LSP server."""
|
|
154
|
-
def text_document_signature_help(self: LspSession, signature_help_params: Any) {
|
|
155
|
-
fut = self._send_request(
|
|
156
|
-
'textDocument/signatureHelp',
|
|
157
|
-
params=signature_help_params
|
|
158
|
-
);
|
|
159
|
-
return fut.result();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
"""Sends text document declaration request to LSP server."""
|
|
163
|
-
def text_document_declaration(self: LspSession, declaration_params: Any) {
|
|
164
|
-
fut = self._send_request('textDocument/declaration', params=declaration_params);
|
|
165
|
-
return fut.result();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
"""Sends text document definition request to LSP server."""
|
|
169
|
-
def text_document_definition(self: LspSession, definition_params: Any) {
|
|
170
|
-
fut = self._send_request('textDocument/definition', params=definition_params);
|
|
171
|
-
return fut.result();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
"""Sends text document symbol request to LSP server."""
|
|
175
|
-
def text_document_symbol(self: LspSession, document_symbol_params: Any) {
|
|
176
|
-
fut = self._send_request(
|
|
177
|
-
'textDocument/documentSymbol',
|
|
178
|
-
params=document_symbol_params
|
|
179
|
-
);
|
|
180
|
-
return fut.result();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
"""Sends text document highlight request to LSP server."""
|
|
184
|
-
def text_document_highlight(self: LspSession, document_highlight_params: Any) {
|
|
185
|
-
fut = self._send_request(
|
|
186
|
-
'textDocument/documentHighlight',
|
|
187
|
-
params=document_highlight_params
|
|
188
|
-
);
|
|
189
|
-
return fut.result();
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
"""Sends text document references request to LSP server."""
|
|
193
|
-
def text_document_references(self: LspSession, references_params: Any) {
|
|
194
|
-
fut = self._send_request('textDocument/references', params=references_params);
|
|
195
|
-
return fut.result();
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
"""Sends workspace symbol request to LSP server."""
|
|
199
|
-
def workspace_symbol(self: LspSession, workspace_symbol_params: Any) {
|
|
200
|
-
fut = self._send_request('workspace/symbol', params=workspace_symbol_params);
|
|
201
|
-
return fut.result();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
"""Sends completion item resolve request to LSP server."""
|
|
205
|
-
def completion_item_resolve(self: LspSession, resolve_params: Any) {
|
|
206
|
-
fut = self._send_request('completionItem/resolve', params=resolve_params);
|
|
207
|
-
return fut.result();
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
"""Sends did change notification to LSP Server."""
|
|
211
|
-
def notify_did_change(self: LspSession, did_change_params: Any) {
|
|
212
|
-
self._send_notification('textDocument/didChange', params=did_change_params);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
"""Sends did save notification to LSP Server."""
|
|
216
|
-
def notify_did_save(self: LspSession, did_save_params: Any) {
|
|
217
|
-
self._send_notification('textDocument/didSave', params=did_save_params);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
"""Sends did open notification to LSP Server."""
|
|
221
|
-
def notify_did_open(self: LspSession, did_open_params: Any) {
|
|
222
|
-
self._send_notification('textDocument/didOpen', params=did_open_params);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
"""Set custom LS notification handler."""
|
|
226
|
-
def set_notification_callback(
|
|
227
|
-
self: LspSession,
|
|
228
|
-
notification_name: Any,
|
|
229
|
-
callback: Any
|
|
230
|
-
) {
|
|
231
|
-
self._notification_callbacks[notification_name] = callback;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
"""Gets callback if set or default callback for a given LS notification."""
|
|
235
|
-
def get_notification_callback(self: LspSession, notification_name: Any) {
|
|
236
|
-
try {
|
|
237
|
-
return self._notification_callbacks[notification_name];
|
|
238
|
-
} except KeyError {
|
|
239
|
-
def _default_handler(_params: Any) -> None {}
|
|
240
|
-
return _default_handler;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
"""Internal handler for text document publish diagnostics."""
|
|
246
|
-
def _publish_diagnostics(self: LspSession, publish_diagnostics_params: Any) {
|
|
247
|
-
return self._handle_notification(
|
|
248
|
-
PUBLISH_DIAGNOSTICS,
|
|
249
|
-
publish_diagnostics_params
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
"""Internal handler for window log message."""
|
|
254
|
-
def _window_log_message(self: LspSession, window_log_message_params: Any) {
|
|
255
|
-
return self._handle_notification(WINDOW_LOG_MESSAGE, window_log_message_params);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
"""Internal handler for window show message."""
|
|
259
|
-
def _window_show_message(self: LspSession, window_show_message_params: Any) {
|
|
260
|
-
return self._handle_notification(
|
|
261
|
-
WINDOW_SHOW_MESSAGE,
|
|
262
|
-
window_show_message_params
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
"""Internal handler for notifications."""
|
|
267
|
-
def _handle_notification(self: LspSession, notification_name: Any, params: Any) {
|
|
268
|
-
fut = Future();
|
|
269
|
-
def _handler() {
|
|
270
|
-
callback = self.get_notification_callback(notification_name);
|
|
271
|
-
callback(params);
|
|
272
|
-
fut.set_result(None);
|
|
273
|
-
}
|
|
274
|
-
self._thread_pool.submit(_handler);
|
|
275
|
-
return fut;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
"""Sends {name} request to the LSP server."""
|
|
279
|
-
def _send_request(
|
|
280
|
-
self: LspSession,
|
|
281
|
-
name: Any,
|
|
282
|
-
params: Any = None,
|
|
283
|
-
handle_response: Any = lambda f: Any: f.done()
|
|
284
|
-
) {
|
|
285
|
-
fut = self._endpoint.request(name, params);
|
|
286
|
-
fut.add_done_callback(handle_response);
|
|
287
|
-
return fut;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
"""Sends {name} notification to the LSP server."""
|
|
291
|
-
def _send_notification(self: LspSession, name: Any, params: Any = None) {
|
|
292
|
-
self._endpoint.notify(name, params);
|
|
293
|
-
}
|
|
294
|
-
}
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
from jaclang.utils.test import TestCase
|
|
2
|
-
from jaclang.vendor.pygls import uris
|
|
3
|
-
from jaclang.vendor.pygls.workspace import Workspace
|
|
4
|
-
|
|
5
|
-
import lsprotocol.types as lspt
|
|
6
|
-
from jaclang.langserve.engine import JacLangServer
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class TestJacLangServer(TestCase):
|
|
10
|
-
|
|
11
|
-
def test_type_annotation_assignment_server(self) -> None:
|
|
12
|
-
"""Test that the server doesn't run if there is a syntax error."""
|
|
13
|
-
lsp = JacLangServer()
|
|
14
|
-
workspace_path = self.fixture_abs_path("")
|
|
15
|
-
workspace = Workspace(workspace_path, lsp)
|
|
16
|
-
lsp.lsp._workspace = workspace
|
|
17
|
-
circle_file = uris.from_fs_path(
|
|
18
|
-
self.fixture_abs_path(
|
|
19
|
-
"../../../../jaclang/compiler/passes/main/tests/fixtures/type_annotation_assignment.jac"
|
|
20
|
-
)
|
|
21
|
-
)
|
|
22
|
-
lsp.deep_check(circle_file)
|
|
23
|
-
self.assertIn(
|
|
24
|
-
"(public variable) should_fail1: int",
|
|
25
|
-
lsp.get_hover_info(circle_file, lspt.Position(1, 15)).contents.value,
|
|
26
|
-
)
|
|
27
|
-
self.assertIn(
|
|
28
|
-
"(public variable) should_pass2: str",
|
|
29
|
-
lsp.get_hover_info(circle_file, lspt.Position(2, 15)).contents.value,
|
|
30
|
-
)
|
|
31
|
-
self.assertIn(
|
|
32
|
-
"(public variable) should_fail2: str",
|
|
33
|
-
lsp.get_hover_info(circle_file, lspt.Position(3, 15)).contents.value,
|
|
34
|
-
)
|
|
35
|
-
diagnostics_list = list(lsp.diagnostics.values())[0]
|
|
36
|
-
self.assertEqual(len(diagnostics_list), 2)
|
|
37
|
-
self.assertIn(
|
|
38
|
-
"Cannot assign",
|
|
39
|
-
diagnostics_list[0].message,
|
|
40
|
-
)
|
|
41
|
-
self.assertEqual(
|
|
42
|
-
"1:5-1:30",
|
|
43
|
-
str(diagnostics_list[0].range),
|
|
44
|
-
)
|
|
45
|
-
self.assertEqual(
|
|
46
|
-
"3:5-3:27",
|
|
47
|
-
str(diagnostics_list[1].range),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
def test_member_access_type_inferred_server(self) -> None:
|
|
52
|
-
"""Test that the server doesn't run if there is a syntax error."""
|
|
53
|
-
lsp = JacLangServer()
|
|
54
|
-
workspace_path = self.fixture_abs_path("")
|
|
55
|
-
workspace = Workspace(workspace_path, lsp)
|
|
56
|
-
lsp.lsp._workspace = workspace
|
|
57
|
-
circle_file = uris.from_fs_path(
|
|
58
|
-
self.fixture_abs_path(
|
|
59
|
-
"../../../../jaclang/compiler/passes/main/tests/fixtures/member_access_type_inferred.jac"
|
|
60
|
-
)
|
|
61
|
-
)
|
|
62
|
-
lsp.deep_check(circle_file)
|
|
63
|
-
self.assertIn(
|
|
64
|
-
"(public variable) i: int",
|
|
65
|
-
lsp.get_hover_info(circle_file, lspt.Position(10, 2)).contents.value,
|
|
66
|
-
)
|
|
67
|
-
self.assertIn(
|
|
68
|
-
"(public variable) s: str",
|
|
69
|
-
lsp.get_hover_info(circle_file, lspt.Position(11, 2)).contents.value,
|
|
70
|
-
)
|
|
71
|
-
diagnostics_list = list(lsp.diagnostics.values())[0]
|
|
72
|
-
self.assertEqual(len(diagnostics_list), 1)
|
|
73
|
-
self.assertIn(
|
|
74
|
-
"Cannot assign",
|
|
75
|
-
diagnostics_list[0].message,
|
|
76
|
-
)
|
|
77
|
-
self.assertEqual(
|
|
78
|
-
"11:2-11:12",
|
|
79
|
-
str(diagnostics_list[0].range),
|
|
80
|
-
)
|