setta 0.0.1.dev0__py3-none-any.whl → 0.0.2.dev0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- setta/__init__.py +1 -1
- setta/cli/__init__.py +1 -0
- setta/cli/connect.py +43 -0
- setta/cli/logger.py +225 -0
- setta/code_gen/__init__.py +0 -0
- setta/code_gen/create_runnable_scripts.py +466 -0
- setta/code_gen/export_selected.py +776 -0
- setta/code_gen/find_placeholders.py +13 -0
- setta/code_gen/python/__init__.py +0 -0
- setta/code_gen/python/ast_utils.py +183 -0
- setta/code_gen/python/check_scope.py +187 -0
- setta/code_gen/python/generate_code.py +280 -0
- setta/code_gen/python/make_parseable.py +97 -0
- setta/code_gen/python/position_line_col.py +33 -0
- setta/code_gen/python/validate_imports.py +87 -0
- setta/code_gen/utils.py +120 -0
- setta/code_gen/yaml/__init__.py +0 -0
- setta/code_gen/yaml/generate_yaml.py +23 -0
- setta/code_gen/yaml/section_dict.py +93 -0
- setta/database/__init__.py +0 -0
- setta/database/backup.py +80 -0
- setta/database/db/__init__.py +0 -0
- setta/database/db/artifacts/__init__.py +0 -0
- setta/database/db/artifacts/load.py +93 -0
- setta/database/db/artifacts/save.py +85 -0
- setta/database/db/artifacts/save_or_create.py +68 -0
- setta/database/db/artifacts/utils.py +13 -0
- setta/database/db/codeInfo/__init__.py +0 -0
- setta/database/db/codeInfo/copy.py +26 -0
- setta/database/db/codeInfo/load.py +65 -0
- setta/database/db/codeInfo/save.py +75 -0
- setta/database/db/codeInfo/utils.py +33 -0
- setta/database/db/evRefs/__init__.py +0 -0
- setta/database/db/evRefs/load.py +45 -0
- setta/database/db/evRefs/save.py +95 -0
- setta/database/db/projects/__init__.py +0 -0
- setta/database/db/projects/copy.py +36 -0
- setta/database/db/projects/delete.py +7 -0
- setta/database/db/projects/load.py +184 -0
- setta/database/db/projects/save.py +267 -0
- setta/database/db/projects/saveAs.py +40 -0
- setta/database/db/projects/utils.py +135 -0
- setta/database/db/sectionVariants/__init__.py +0 -0
- setta/database/db/sectionVariants/copy.py +28 -0
- setta/database/db/sectionVariants/load.py +139 -0
- setta/database/db/sectionVariants/save.py +140 -0
- setta/database/db/sectionVariants/utils.py +44 -0
- setta/database/db/sections/__init__.py +0 -0
- setta/database/db/sections/copy.py +70 -0
- setta/database/db/sections/jsonSource.py +119 -0
- setta/database/db/sections/load.py +350 -0
- setta/database/db/sections/save.py +204 -0
- setta/database/db/sections/utils.py +13 -0
- setta/database/db/uiTypes/__init__.py +0 -0
- setta/database/db/uiTypes/copy.py +33 -0
- setta/database/db/uiTypes/load.py +51 -0
- setta/database/db/uiTypes/save.py +99 -0
- setta/database/db/uiTypes/utils.py +27 -0
- setta/database/db_init.py +36 -0
- setta/database/db_objs.py +102 -0
- setta/database/db_path.py +8 -0
- setta/database/export_db/__init__.py +0 -0
- setta/database/export_db/export_db.py +43 -0
- setta/database/export_db/export_raw.py +53 -0
- setta/database/export_db/export_readable.py +242 -0
- setta/database/export_db/utils.py +16 -0
- setta/database/import_db.py +28 -0
- setta/database/seed.py +41 -0
- setta/database/settings_file.py +118 -0
- setta/database/utils.py +32 -0
- setta/lsp/__init__.py +0 -0
- setta/lsp/file_watcher.py +113 -0
- setta/lsp/reader.py +184 -0
- setta/lsp/reader_fns/__init__.py +0 -0
- setta/lsp/reader_fns/completion.py +84 -0
- setta/lsp/reader_fns/definition.py +2 -0
- setta/lsp/reader_fns/diagnostics.py +99 -0
- setta/lsp/reader_fns/documentHighlight.py +25 -0
- setta/lsp/reader_fns/references.py +34 -0
- setta/lsp/reader_fns/signatureHelp.py +99 -0
- setta/lsp/server.py +150 -0
- setta/lsp/utils.py +60 -0
- setta/lsp/writer.py +306 -0
- setta/routers/__init__.py +11 -0
- setta/routers/artifact.py +105 -0
- setta/routers/code_info.py +32 -0
- setta/routers/dependencies.py +49 -0
- setta/routers/in_memory_fn_stdout_websocket.py +21 -0
- setta/routers/interactive.py +119 -0
- setta/routers/lsp.py +14 -0
- setta/routers/projects.py +188 -0
- setta/routers/reference_renaming.py +111 -0
- setta/routers/sections.py +174 -0
- setta/routers/settings.py +40 -0
- setta/routers/terminals.py +83 -0
- setta/routers/websocket.py +36 -0
- setta/server.py +141 -0
- setta/start.py +112 -0
- setta/static/constants/BaseUITypes.json +153 -0
- setta/static/constants/Settings.json +113 -0
- setta/static/constants/constants.json +117 -0
- setta/static/constants/db_init.sql +249 -0
- setta/static/constants/defaultValues.json +125 -0
- setta/static/constants/settingsProject.json +276 -0
- setta/static/frontend/android-chrome-192x192.png +0 -0
- setta/static/frontend/android-chrome-512x512.png +0 -0
- setta/static/frontend/apple-touch-icon.png +0 -0
- setta/static/frontend/assets/KaTeX_AMS-Regular-0cdd387c.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_AMS-Regular-30da91e8.woff +0 -0
- setta/static/frontend/assets/KaTeX_AMS-Regular-68534840.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Bold-07d8e303.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Bold-1ae6bd74.woff +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Bold-de7701e4.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Regular-3398dd02.woff +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Regular-5d53e70a.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Caligraphic-Regular-ed0b7437.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Bold-74444efd.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Bold-9163df9c.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Bold-9be7ceb8.woff +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Regular-1e6f9579.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Regular-51814d27.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Fraktur-Regular-5e28753b.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Bold-0f60d1b8.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-Bold-138ac28d.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Main-Bold-c76c5d69.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-BoldItalic-70ee1f64.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Main-BoldItalic-99cd42a3.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-BoldItalic-a6f7ec0d.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Italic-0d85ae7c.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Main-Italic-97479ca6.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-Italic-f1d6ef86.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Regular-c2342cd8.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Main-Regular-c6368d87.woff +0 -0
- setta/static/frontend/assets/KaTeX_Main-Regular-d0332f52.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Math-BoldItalic-850c0af5.woff +0 -0
- setta/static/frontend/assets/KaTeX_Math-BoldItalic-dc47344d.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Math-BoldItalic-f9377ab0.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Math-Italic-08ce98e5.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Math-Italic-7af58c5e.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Math-Italic-8a8d2445.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Bold-1ece03f7.ttf +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Bold-e99ae511.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Bold-ece03cfd.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Italic-00b26ac8.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Italic-3931dd81.ttf +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Italic-91ee6750.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Regular-11e4dc8a.woff +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Regular-68e8c73e.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_SansSerif-Regular-f36ea897.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Script-Regular-036d4e95.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Script-Regular-1c67f068.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Script-Regular-d96cdf2b.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size1-Regular-6b47c401.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Size1-Regular-95b6d2f1.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Size1-Regular-c943cc98.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size2-Regular-2014c523.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size2-Regular-a6b2099f.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Size2-Regular-d04c5421.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Size3-Regular-500e04d5.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Size3-Regular-6ab6b62e.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size4-Regular-99f9c675.woff +0 -0
- setta/static/frontend/assets/KaTeX_Size4-Regular-a4af7d41.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Size4-Regular-c647367d.ttf +0 -0
- setta/static/frontend/assets/KaTeX_Typewriter-Regular-71d517d6.woff2 +0 -0
- setta/static/frontend/assets/KaTeX_Typewriter-Regular-e14fed02.woff +0 -0
- setta/static/frontend/assets/KaTeX_Typewriter-Regular-f01f3e87.ttf +0 -0
- setta/static/frontend/assets/cormorant-garamond-all-700-italic-c9b58582.woff +0 -0
- setta/static/frontend/assets/cormorant-garamond-cyrillic-700-italic-9101ad5f.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-cyrillic-ext-700-italic-950de0d6.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-latin-700-italic-0bc53e12.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-latin-ext-700-italic-525738e0.woff2 +0 -0
- setta/static/frontend/assets/cormorant-garamond-vietnamese-700-italic-99563037.woff2 +0 -0
- setta/static/frontend/assets/erase-5e0448ea.svg +15 -0
- setta/static/frontend/assets/index-1d4b4ecf.css +32 -0
- setta/static/frontend/assets/index-ee99dc72.js +678 -0
- setta/static/frontend/assets/inter-all-400-normal-054f12d0.woff +0 -0
- setta/static/frontend/assets/inter-all-600-normal-c03769e5.woff +0 -0
- setta/static/frontend/assets/inter-all-800-normal-15dc6e4b.woff +0 -0
- setta/static/frontend/assets/inter-cyrillic-400-normal-a4eee61a.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-600-normal-8b14f703.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-800-normal-e706eaaa.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-ext-400-normal-70047a3b.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-ext-600-normal-d4ab9bc4.woff2 +0 -0
- setta/static/frontend/assets/inter-cyrillic-ext-800-normal-eae7515a.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-400-normal-381ea30d.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-600-normal-601f93a2.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-800-normal-7af4fb64.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-ext-400-normal-27027b17.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-ext-600-normal-f2ddf9de.woff2 +0 -0
- setta/static/frontend/assets/inter-greek-ext-800-normal-4cb6189e.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-400-normal-d56fec21.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-600-normal-ff769fa6.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-800-normal-5eea1309.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-ext-400-normal-bb698d85.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-ext-600-normal-ca4808f9.woff2 +0 -0
- setta/static/frontend/assets/inter-latin-ext-800-normal-ebdacc0f.woff2 +0 -0
- setta/static/frontend/assets/logo/logo.svg +8 -0
- setta/static/frontend/assets/pen-455d7d8a.svg +19 -0
- setta/static/frontend/assets/source-code-pro-all-500-normal-6bdaa03b.woff +0 -0
- setta/static/frontend/assets/source-code-pro-cyrillic-500-normal-288a0d68.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-cyrillic-ext-500-normal-b110a13b.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-greek-500-normal-04328acb.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-latin-500-normal-06edef1e.woff2 +0 -0
- setta/static/frontend/assets/source-code-pro-latin-ext-500-normal-6dc60d5e.woff2 +0 -0
- setta/static/frontend/assets/web-vitals-44a8e082.js +1 -0
- setta/static/frontend/assets/work-sans-all-400-normal-38034a3c.woff +0 -0
- setta/static/frontend/assets/work-sans-all-500-normal-550d64e5.woff +0 -0
- setta/static/frontend/assets/work-sans-all-600-normal-ccf14060.woff +0 -0
- setta/static/frontend/assets/work-sans-all-700-normal-494c2971.woff +0 -0
- setta/static/frontend/assets/work-sans-latin-400-normal-36735bc1.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-500-normal-3790bfda.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-600-normal-5fba494e.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-700-normal-a5033d0a.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-400-normal-c20f571a.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-500-normal-0f5ac96c.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-600-normal-97a237d1.woff2 +0 -0
- setta/static/frontend/assets/work-sans-latin-ext-700-normal-103e112c.woff2 +0 -0
- setta/static/frontend/browserconfig.xml +9 -0
- setta/static/frontend/favicon-16x16.png +0 -0
- setta/static/frontend/favicon-32x32.png +0 -0
- setta/static/frontend/favicon.ico +0 -0
- setta/static/frontend/index.html +30 -0
- setta/static/frontend/manifest.json +25 -0
- setta/static/frontend/mstile-144x144.png +0 -0
- setta/static/frontend/mstile-150x150.png +0 -0
- setta/static/frontend/mstile-310x150.png +0 -0
- setta/static/frontend/mstile-310x310.png +0 -0
- setta/static/frontend/mstile-70x70.png +0 -0
- setta/static/frontend/robots.txt +3 -0
- setta/static/frontend/safari-pinned-tab.svg +18 -0
- setta/static/frontend/site.webmanifest +19 -0
- setta/static/seed/.DS_Store +0 -0
- setta/static/seed/examples/.DS_Store +0 -0
- setta/tasks/__init__.py +0 -0
- setta/tasks/fns/__init__.py +9 -0
- setta/tasks/fns/codeAreaAutocomplete.py +209 -0
- setta/tasks/fns/codeAreaFindTemplateVars.py +128 -0
- setta/tasks/fns/codeAreaInitializeCode.py +98 -0
- setta/tasks/fns/findEVRefs.py +236 -0
- setta/tasks/fns/parametersRequest.py +71 -0
- setta/tasks/fns/textFieldAutocomplete.py +210 -0
- setta/tasks/fns/textFieldInitializeCode.py +99 -0
- setta/tasks/fns/typeCheck.py +40 -0
- setta/tasks/fns/utils.py +134 -0
- setta/tasks/task_runner.py +29 -0
- setta/tasks/tasks.py +152 -0
- setta/tasks/utils.py +178 -0
- setta/terminals/__init__.py +0 -0
- setta/terminals/terminals.py +242 -0
- setta/terminals/utils.py +37 -0
- setta/utils/__init__.py +0 -0
- setta/utils/constants.py +148 -0
- setta/utils/generate_memorable_string.py +431 -0
- setta/utils/generate_new_filename.py +80 -0
- setta/utils/section_contents.py +133 -0
- setta/utils/utils.py +271 -0
- setta/utils/websocket_manager.py +91 -0
- setta-0.0.2.dev0.dist-info/LICENSE +201 -0
- setta-0.0.2.dev0.dist-info/METADATA +24 -0
- setta-0.0.2.dev0.dist-info/RECORD +263 -0
- {setta-0.0.1.dev0.dist-info → setta-0.0.2.dev0.dist-info}/WHEEL +1 -1
- setta-0.0.2.dev0.dist-info/entry_points.txt +2 -0
- setta-0.0.1.dev0.dist-info/METADATA +0 -18
- setta-0.0.1.dev0.dist-info/RECORD +0 -5
- {setta-0.0.1.dev0.dist-info → setta-0.0.2.dev0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,98 @@
|
|
1
|
+
import json
|
2
|
+
|
3
|
+
from pydantic import BaseModel
|
4
|
+
|
5
|
+
from setta.code_gen.create_runnable_scripts import generate_final_code_for_sections
|
6
|
+
from setta.code_gen.export_selected import export_selected
|
7
|
+
from setta.code_gen.find_placeholders import tp
|
8
|
+
from setta.tasks.task_runner import RunType
|
9
|
+
from setta.utils.constants import C
|
10
|
+
|
11
|
+
from .utils import (
|
12
|
+
TaskDefinition,
|
13
|
+
send_document_open_request_with_diagnostics_with_code_dict,
|
14
|
+
)
|
15
|
+
|
16
|
+
|
17
|
+
class CodeAreaInitializeCodeContent(BaseModel):
|
18
|
+
project: dict
|
19
|
+
sectionId: str
|
20
|
+
|
21
|
+
|
22
|
+
async def _codeAreaInitializeCode(message, lsp_writers):
|
23
|
+
message = CodeAreaInitializeCodeContent.parse_obj(message.content)
|
24
|
+
project = message.project
|
25
|
+
exporter_obj = export_selected(
|
26
|
+
project, always_export_args_objs=True, force_include_template_var=False
|
27
|
+
)
|
28
|
+
projectConfigName = project["projectConfig"]["name"]
|
29
|
+
code_dict = await generate_final_code_for_sections(
|
30
|
+
project,
|
31
|
+
exporter_obj,
|
32
|
+
lsp_writers=lsp_writers,
|
33
|
+
folder_path=lsp_writers["full"].project_code_folder(projectConfigName),
|
34
|
+
)
|
35
|
+
send_document_open_request_with_diagnostics_with_code_dict(
|
36
|
+
lsp_writers["full"],
|
37
|
+
code_dict,
|
38
|
+
exporter_obj,
|
39
|
+
projectConfigName,
|
40
|
+
)
|
41
|
+
|
42
|
+
referencable_var_names = []
|
43
|
+
generated_var_names = []
|
44
|
+
if (
|
45
|
+
exporter_obj.code_gen_template_var_section_details["section"].get("id")
|
46
|
+
== message.sectionId
|
47
|
+
):
|
48
|
+
generated_var_names = list(
|
49
|
+
code_dict[message.sectionId]["var_name_to_decl_rel_position_dict"][
|
50
|
+
tp(C.SETTA_GENERATED_PYTHON)
|
51
|
+
].keys()
|
52
|
+
)
|
53
|
+
infoToFullName = {
|
54
|
+
tuple(json.loads(k)): v for k, v in project["infoToFullName"].items()
|
55
|
+
}
|
56
|
+
referencable_var_names = [
|
57
|
+
infoToFullName[exporter_obj.var_name_reverse_mapping[v]]
|
58
|
+
for v in generated_var_names
|
59
|
+
]
|
60
|
+
|
61
|
+
template_var_replacement_values = {}
|
62
|
+
for r in code_dict[message.sectionId]["ref_template_var_positions"]["templateVars"]:
|
63
|
+
template_var_replacement_values[r["keyword"]] = r["value"]
|
64
|
+
|
65
|
+
return {
|
66
|
+
"content": True,
|
67
|
+
"cache": [
|
68
|
+
template_var_replacement_values,
|
69
|
+
generated_var_names,
|
70
|
+
referencable_var_names,
|
71
|
+
exporter_obj,
|
72
|
+
project["fullNameToInfo"],
|
73
|
+
project["fullNameToSectionId"],
|
74
|
+
],
|
75
|
+
}
|
76
|
+
|
77
|
+
|
78
|
+
def get_cache_key(projectConfigId, sectionId):
|
79
|
+
return f"codeAreaInitializeCode-{projectConfigId}-{sectionId}"
|
80
|
+
|
81
|
+
|
82
|
+
def write_cache(cache, message, result):
|
83
|
+
if result.get("cache") is None:
|
84
|
+
return
|
85
|
+
message = CodeAreaInitializeCodeContent.parse_obj(message.content)
|
86
|
+
cache[
|
87
|
+
get_cache_key(message.project["projectConfig"]["id"], message.sectionId)
|
88
|
+
] = result["cache"]
|
89
|
+
|
90
|
+
|
91
|
+
codeAreaInitializeCode = TaskDefinition(
|
92
|
+
name="codeAreaInitializeCode",
|
93
|
+
return_message_type="codeAreaInitializeCodeReturn",
|
94
|
+
fn=_codeAreaInitializeCode,
|
95
|
+
write_cache=write_cache,
|
96
|
+
run_as=RunType.NONE,
|
97
|
+
server_dependencies=["lsp_writers"],
|
98
|
+
)
|
@@ -0,0 +1,236 @@
|
|
1
|
+
import asyncio
|
2
|
+
from typing import List, Optional
|
3
|
+
|
4
|
+
from pydantic import BaseModel
|
5
|
+
|
6
|
+
from setta.code_gen.export_selected import get_gen_code_template_var
|
7
|
+
from setta.code_gen.python.check_scope import are_positions_in_scope_with_variable
|
8
|
+
from setta.database.utils import create_new_id
|
9
|
+
from setta.tasks.task_runner import RunType
|
10
|
+
from setta.utils.utils import multireplace
|
11
|
+
|
12
|
+
from .utils import (
|
13
|
+
TaskDefinition,
|
14
|
+
generate_unique_variable,
|
15
|
+
prepare_code_for_scope_checking,
|
16
|
+
)
|
17
|
+
|
18
|
+
|
19
|
+
class TextFieldFindReferencesContent(BaseModel):
|
20
|
+
sectionId: str
|
21
|
+
paramInfoId: Optional[str] = None
|
22
|
+
candidateEVRefs: List[list]
|
23
|
+
templateVars: Optional[List[dict]] = None
|
24
|
+
onlyAfterGenCodeTemplateVar: Optional[bool] = False
|
25
|
+
fullText: str
|
26
|
+
|
27
|
+
|
28
|
+
async def _findEVRefs(message, lsp_writers):
|
29
|
+
message_id = message.id
|
30
|
+
message = TextFieldFindReferencesContent.parse_obj(message.content)
|
31
|
+
request_ids = await sendEVRefRequests(
|
32
|
+
message_id,
|
33
|
+
message.sectionId,
|
34
|
+
message.paramInfoId,
|
35
|
+
message.candidateEVRefs,
|
36
|
+
message.templateVars,
|
37
|
+
message.onlyAfterGenCodeTemplateVar,
|
38
|
+
message.fullText,
|
39
|
+
lsp_writers,
|
40
|
+
local=False,
|
41
|
+
)
|
42
|
+
|
43
|
+
if len(request_ids) == 0:
|
44
|
+
return {"content": {"data": {"positions": [], "numMessages": 1}}}
|
45
|
+
|
46
|
+
return None
|
47
|
+
|
48
|
+
|
49
|
+
async def sendEVRefRequests(
|
50
|
+
message_id,
|
51
|
+
sectionId,
|
52
|
+
paramInfoId,
|
53
|
+
candidateEVRefs,
|
54
|
+
templateVars,
|
55
|
+
onlyAfterGenCodeTemplateVar,
|
56
|
+
fullText,
|
57
|
+
lsp_writers,
|
58
|
+
local,
|
59
|
+
):
|
60
|
+
candidateEVRefs = filterCandidatesByScope(
|
61
|
+
candidateEVRefs,
|
62
|
+
fullText,
|
63
|
+
onlyAfterGenCodeTemplateVar,
|
64
|
+
templateVars,
|
65
|
+
)
|
66
|
+
|
67
|
+
if len(candidateEVRefs) == 0:
|
68
|
+
return []
|
69
|
+
|
70
|
+
code, position_offset, num_keywords = generateCodeForReferenceFinding(
|
71
|
+
candidateEVRefs,
|
72
|
+
fullText,
|
73
|
+
onlyAfterGenCodeTemplateVar,
|
74
|
+
templateVars,
|
75
|
+
)
|
76
|
+
code_id = f"{sectionId}-{paramInfoId}-find-references"
|
77
|
+
|
78
|
+
await lsp_writers["basic"].send_document_open_request(code_id, code)
|
79
|
+
request_ids = []
|
80
|
+
for idx in range(num_keywords):
|
81
|
+
request_id = f"{message_id}-{idx}"
|
82
|
+
request_ids.append(request_id)
|
83
|
+
lsp_writers["basic"].create_asyncio_task(
|
84
|
+
lsp_writers["basic"].send_reference_request(
|
85
|
+
position_offset=position_offset,
|
86
|
+
line=idx,
|
87
|
+
character=0,
|
88
|
+
code_id=code_id,
|
89
|
+
request_id=request_id,
|
90
|
+
return_id=message_id,
|
91
|
+
num_messages=num_keywords,
|
92
|
+
),
|
93
|
+
request_id,
|
94
|
+
local=local,
|
95
|
+
)
|
96
|
+
|
97
|
+
return request_ids
|
98
|
+
|
99
|
+
|
100
|
+
async def findEVRefsLocally(
|
101
|
+
sectionId,
|
102
|
+
paramInfoId,
|
103
|
+
candidateEVRefs,
|
104
|
+
templateVars,
|
105
|
+
onlyAfterGenCodeTemplateVar,
|
106
|
+
fullText,
|
107
|
+
fullNameToInfo,
|
108
|
+
lsp_writers,
|
109
|
+
):
|
110
|
+
evRefRequestId = create_new_id()
|
111
|
+
request_ids = await sendEVRefRequests(
|
112
|
+
evRefRequestId,
|
113
|
+
sectionId,
|
114
|
+
paramInfoId,
|
115
|
+
candidateEVRefs,
|
116
|
+
templateVars,
|
117
|
+
onlyAfterGenCodeTemplateVar,
|
118
|
+
fullText,
|
119
|
+
lsp_writers,
|
120
|
+
local=True,
|
121
|
+
)
|
122
|
+
|
123
|
+
if len(request_ids) == 0:
|
124
|
+
return []
|
125
|
+
|
126
|
+
responses = await waitForEVRefResponses(request_ids, lsp_writers)
|
127
|
+
positions = []
|
128
|
+
for r in responses:
|
129
|
+
positions.extend(r["data"]["positions"])
|
130
|
+
return construct_ev_refs(positions, fullNameToInfo, fullText)
|
131
|
+
|
132
|
+
|
133
|
+
def construct_ev_refs(keyword_positions, fullNameToInfo, fullText):
|
134
|
+
output = []
|
135
|
+
for k in keyword_positions:
|
136
|
+
keyword = fullText[k["startPos"] : k["endPos"]]
|
137
|
+
if keyword in fullNameToInfo:
|
138
|
+
info = fullNameToInfo[keyword]
|
139
|
+
output.append(
|
140
|
+
{
|
141
|
+
"sectionId": info["sectionId"],
|
142
|
+
"paramInfoId": info["paramInfoId"],
|
143
|
+
"isArgsObj": info["isArgsObj"],
|
144
|
+
"startPos": k["startPos"],
|
145
|
+
"keyword": keyword,
|
146
|
+
}
|
147
|
+
)
|
148
|
+
return output
|
149
|
+
|
150
|
+
|
151
|
+
async def waitForEVRefResponses(request_ids, lsp_writers):
|
152
|
+
request_futures = []
|
153
|
+
for r in request_ids:
|
154
|
+
future = lsp_writers["basic"].wait_for_response(r)
|
155
|
+
request_futures.append(future)
|
156
|
+
|
157
|
+
return await asyncio.gather(*request_futures)
|
158
|
+
|
159
|
+
|
160
|
+
def filterCandidatesByScope(
|
161
|
+
candidateEVRefs, fullText, onlyAfterGenCodeTemplateVar, templateVars
|
162
|
+
):
|
163
|
+
if not onlyAfterGenCodeTemplateVar:
|
164
|
+
return candidateEVRefs
|
165
|
+
matching_template_var = get_gen_code_template_var(templateVars)
|
166
|
+
if matching_template_var is None:
|
167
|
+
return []
|
168
|
+
|
169
|
+
fullText, the_special_var_name = prepare_code_for_scope_checking(
|
170
|
+
fullText, templateVars, matching_template_var
|
171
|
+
)
|
172
|
+
|
173
|
+
response = are_positions_in_scope_with_variable(
|
174
|
+
fullText, [x[1] for x in candidateEVRefs], the_special_var_name
|
175
|
+
)
|
176
|
+
|
177
|
+
return [x for idx, x in enumerate(candidateEVRefs) if response[idx]]
|
178
|
+
|
179
|
+
|
180
|
+
def generateCodeForReferenceFinding(
|
181
|
+
candidateEVRefs, fullText, onlyAfterGenCodeTemplateVar, templateVars
|
182
|
+
):
|
183
|
+
position_offset = 0
|
184
|
+
|
185
|
+
if onlyAfterGenCodeTemplateVar:
|
186
|
+
matching_template_var = get_gen_code_template_var(templateVars)
|
187
|
+
if matching_template_var is None:
|
188
|
+
return "", position_offset, 0
|
189
|
+
# If SETTA_GENERATED_PYTHON is present, we only want to consider
|
190
|
+
# code that comes after it.
|
191
|
+
startPos = matching_template_var["startPos"]
|
192
|
+
keyword = matching_template_var["keyword"]
|
193
|
+
endPos = startPos + len(keyword)
|
194
|
+
template_str_len = endPos - startPos
|
195
|
+
before_text = fullText[:startPos]
|
196
|
+
fullText = fullText[endPos:]
|
197
|
+
position_offset -= len(before_text) + template_str_len
|
198
|
+
|
199
|
+
output = []
|
200
|
+
var_name_mapping = {}
|
201
|
+
visited_keywords = set()
|
202
|
+
for keyword, _ in candidateEVRefs:
|
203
|
+
# candidateEVRefs might contain multiple suggestions to the same keyword
|
204
|
+
# like in the case of fn(a=a), it'll suggest "a" in two positions
|
205
|
+
# but we only need to write the a=None declaration once
|
206
|
+
# so we keep track of keywords we've already visited
|
207
|
+
if keyword in visited_keywords:
|
208
|
+
continue
|
209
|
+
visited_keywords.add(keyword)
|
210
|
+
# Replace reference names like
|
211
|
+
# list_of_models[0]
|
212
|
+
# with a random valid variable name of the same length.
|
213
|
+
# If "[" is ever in the keyword,
|
214
|
+
# we know it will have a length of at least 4, e.g. x[0] has 4 characters.
|
215
|
+
# So we don't have to worry about clashes.
|
216
|
+
if "[" in keyword:
|
217
|
+
new_keyword = generate_unique_variable(fullText, keyword)
|
218
|
+
var_name_mapping[keyword] = new_keyword
|
219
|
+
keyword = new_keyword
|
220
|
+
output.append(f"{keyword}=None")
|
221
|
+
|
222
|
+
output = "\n".join(output)
|
223
|
+
# the plus 1 is for the newline between output and fullText
|
224
|
+
position_offset += len(output) + 1
|
225
|
+
if len(var_name_mapping) > 0:
|
226
|
+
fullText = multireplace(fullText, var_name_mapping)
|
227
|
+
return f"{output}\n{fullText}", position_offset, len(visited_keywords)
|
228
|
+
|
229
|
+
|
230
|
+
findEVRefs = TaskDefinition(
|
231
|
+
name="findEVRefs",
|
232
|
+
return_message_type="findEVRefsReturn",
|
233
|
+
fn=_findEVRefs,
|
234
|
+
run_as=RunType.NONE,
|
235
|
+
server_dependencies=["lsp_writers"],
|
236
|
+
)
|
@@ -0,0 +1,71 @@
|
|
1
|
+
from setta.code_gen.python.position_line_col import position_to_line_col
|
2
|
+
from setta.tasks.task_runner import RunType
|
3
|
+
|
4
|
+
from .textFieldAutocomplete import (
|
5
|
+
CodeCompletionContent,
|
6
|
+
get_code_and_cursor_position,
|
7
|
+
read_cache,
|
8
|
+
)
|
9
|
+
from .utils import TaskDefinition, send_document_open_request_with_diagnostics
|
10
|
+
|
11
|
+
|
12
|
+
async def _parametersRequest(message, lsp_writers):
|
13
|
+
request_id = message.id
|
14
|
+
message = CodeCompletionContent.parse_obj(message.content)
|
15
|
+
cached = message.cached
|
16
|
+
if cached is None:
|
17
|
+
return {"content": {"data": None}}
|
18
|
+
|
19
|
+
(
|
20
|
+
gen_code_dict,
|
21
|
+
var_name,
|
22
|
+
_,
|
23
|
+
_,
|
24
|
+
exporter_obj,
|
25
|
+
fullNameToInfo,
|
26
|
+
) = cached
|
27
|
+
|
28
|
+
(
|
29
|
+
evRefs,
|
30
|
+
code,
|
31
|
+
cursor_position,
|
32
|
+
ref_template_var_positions,
|
33
|
+
) = await get_code_and_cursor_position(
|
34
|
+
message,
|
35
|
+
fullNameToInfo,
|
36
|
+
gen_code_dict,
|
37
|
+
var_name,
|
38
|
+
exporter_obj,
|
39
|
+
lsp_writers,
|
40
|
+
)
|
41
|
+
code = code[:cursor_position] + "()" + code[cursor_position + 2 :]
|
42
|
+
# move cursor into parentheses
|
43
|
+
cursor_position += 1
|
44
|
+
line, column = position_to_line_col(code, cursor_position)
|
45
|
+
code_id = await send_document_open_request_with_diagnostics(
|
46
|
+
lsp_writers["full"],
|
47
|
+
code,
|
48
|
+
exporter_obj,
|
49
|
+
ref_template_var_positions,
|
50
|
+
message.projectConfigName,
|
51
|
+
gen_code_dict["sanitized_full_name"],
|
52
|
+
exporter_obj.code_gen_template_var_section_details["section"]["id"],
|
53
|
+
)
|
54
|
+
await lsp_writers["full"].send_signature_help_request(
|
55
|
+
line,
|
56
|
+
column,
|
57
|
+
code_id,
|
58
|
+
request_id,
|
59
|
+
otherData={"evRefs": evRefs},
|
60
|
+
)
|
61
|
+
return None
|
62
|
+
|
63
|
+
|
64
|
+
parametersRequest = TaskDefinition(
|
65
|
+
name="parametersRequest",
|
66
|
+
return_message_type="parametersRequestReturn",
|
67
|
+
fn=_parametersRequest,
|
68
|
+
read_cache=read_cache,
|
69
|
+
run_as=RunType.NONE,
|
70
|
+
server_dependencies=["lsp_writers"],
|
71
|
+
)
|
@@ -0,0 +1,210 @@
|
|
1
|
+
import copy
|
2
|
+
from typing import Any, Optional
|
3
|
+
|
4
|
+
from pydantic import BaseModel
|
5
|
+
|
6
|
+
from setta.code_gen.create_runnable_scripts import generate_final_code_for_section
|
7
|
+
from setta.code_gen.export_selected import get_gen_code_template_var
|
8
|
+
from setta.code_gen.find_placeholders import tp
|
9
|
+
from setta.code_gen.python.generate_code import (
|
10
|
+
construct_var_decl_with_trailing_whitespace,
|
11
|
+
var_declaration,
|
12
|
+
)
|
13
|
+
from setta.code_gen.python.position_line_col import position_to_line_col
|
14
|
+
from setta.code_gen.utils import process_refs
|
15
|
+
from setta.tasks.fns.textFieldInitializeCode import get_cache_key
|
16
|
+
from setta.tasks.task_runner import RunType
|
17
|
+
from setta.utils.constants import C
|
18
|
+
|
19
|
+
from .findEVRefs import findEVRefsLocally
|
20
|
+
from .utils import TaskDefinition, send_document_open_request_with_diagnostics
|
21
|
+
|
22
|
+
|
23
|
+
class CodeCompletionContent(BaseModel):
|
24
|
+
projectConfigId: str
|
25
|
+
projectConfigName: str
|
26
|
+
sectionId: str
|
27
|
+
paramInfoId: str | None
|
28
|
+
fullText: str
|
29
|
+
position: int
|
30
|
+
candidateEVRefs: list
|
31
|
+
cached: Optional[Any] = None
|
32
|
+
|
33
|
+
|
34
|
+
async def getEVRefsAndProcessThem(message, fullNameToInfo, exporter_obj, lsp_writers):
|
35
|
+
evRefs = await findEVRefsLocally(
|
36
|
+
message.sectionId,
|
37
|
+
message.paramInfoId,
|
38
|
+
message.candidateEVRefs,
|
39
|
+
[],
|
40
|
+
False,
|
41
|
+
message.fullText,
|
42
|
+
fullNameToInfo,
|
43
|
+
lsp_writers,
|
44
|
+
)
|
45
|
+
|
46
|
+
# 1. Create new variable declaration with new value
|
47
|
+
var_value, new_positions = process_refs(
|
48
|
+
message.fullText,
|
49
|
+
evRefs,
|
50
|
+
exporter_obj.get_ref_var_name,
|
51
|
+
cursor_position=message.position,
|
52
|
+
)
|
53
|
+
return evRefs, var_value, new_positions
|
54
|
+
|
55
|
+
|
56
|
+
async def get_code_and_cursor_position(
|
57
|
+
message,
|
58
|
+
fullNameToInfo,
|
59
|
+
gen_code_dict,
|
60
|
+
var_name,
|
61
|
+
exporter_obj,
|
62
|
+
lsp_writers,
|
63
|
+
):
|
64
|
+
evRefs, var_value, new_positions = await getEVRefsAndProcessThem(
|
65
|
+
message, fullNameToInfo, exporter_obj, lsp_writers
|
66
|
+
)
|
67
|
+
new_var_decl = var_declaration(var_name, var_value)
|
68
|
+
|
69
|
+
# 2. Compute relative cursor position (cursor position in the context of the variable declaration)
|
70
|
+
cursor_position = new_positions["cursor"]
|
71
|
+
cursor_position += len(new_var_decl) - len(
|
72
|
+
var_value
|
73
|
+
) # shift by length of var declaration (like x = ...)
|
74
|
+
|
75
|
+
# 3. Get position of original variable declaration within generated code.
|
76
|
+
# This will have to be the relative position, not the position adjusted after code generation
|
77
|
+
startPos, old_var_decl, chars_after_var_decl = gen_code_dict[
|
78
|
+
"var_name_to_decl_rel_position_dict"
|
79
|
+
][tp(C.SETTA_GENERATED_PYTHON)][var_name]
|
80
|
+
endPos = startPos + len(old_var_decl)
|
81
|
+
|
82
|
+
# 4. Replace the old declaration with the new declaration.
|
83
|
+
gen_code = get_gen_code_template_var(
|
84
|
+
gen_code_dict["ref_template_var_positions"]["templateVars"]
|
85
|
+
)["value"]
|
86
|
+
gen_code = (
|
87
|
+
gen_code[:startPos]
|
88
|
+
+ construct_var_decl_with_trailing_whitespace(
|
89
|
+
new_var_decl, chars_after_var_decl
|
90
|
+
)
|
91
|
+
+ gen_code[endPos:]
|
92
|
+
)
|
93
|
+
|
94
|
+
# 5. Call generate_final_code_for_section with the new generated code as a replacement value
|
95
|
+
template_var_replacement_values = {tp(C.SETTA_GENERATED_PYTHON): gen_code}
|
96
|
+
var_name_to_decl_rel_position_dict = copy.deepcopy(
|
97
|
+
gen_code_dict["var_name_to_decl_rel_position_dict"]
|
98
|
+
)
|
99
|
+
var_name_to_decl_rel_position_dict[tp(C.SETTA_GENERATED_PYTHON)][var_name] = (
|
100
|
+
startPos,
|
101
|
+
new_var_decl,
|
102
|
+
chars_after_var_decl,
|
103
|
+
)
|
104
|
+
gen_code_details = exporter_obj.code_gen_template_var_section_details
|
105
|
+
gen_code_section = gen_code_details["section"]
|
106
|
+
gen_code_section_variant = gen_code_details["sectionVariant"]
|
107
|
+
|
108
|
+
(
|
109
|
+
code,
|
110
|
+
_,
|
111
|
+
var_name_to_decl_rel_position_dict,
|
112
|
+
ref_template_var_positions,
|
113
|
+
) = await generate_final_code_for_section(
|
114
|
+
sectionId=message.sectionId,
|
115
|
+
code=gen_code_section_variant[
|
116
|
+
"code"
|
117
|
+
], # this is the code with the template vars still in place
|
118
|
+
codeLanguage=gen_code_section["codeLanguage"],
|
119
|
+
evRefs=gen_code_section_variant["evRefs"],
|
120
|
+
templateVars=gen_code_section_variant["templateVars"],
|
121
|
+
exporter_obj=exporter_obj,
|
122
|
+
lsp_writers=lsp_writers,
|
123
|
+
folder_path=lsp_writers["full"].project_code_folder(message.projectConfigName),
|
124
|
+
template_var_replacement_values=template_var_replacement_values,
|
125
|
+
var_name_to_decl_rel_position_dict=var_name_to_decl_rel_position_dict,
|
126
|
+
push_var_name=var_name,
|
127
|
+
)
|
128
|
+
|
129
|
+
# 6. Compute the cursor position using the value from step 2, plus the returned var_name_to_decl_rel_position_dict
|
130
|
+
var_decl_rel_position = var_name_to_decl_rel_position_dict[
|
131
|
+
tp(C.SETTA_GENERATED_PYTHON)
|
132
|
+
][var_name][0]
|
133
|
+
gen_code_position = get_gen_code_template_var(
|
134
|
+
ref_template_var_positions["templateVars"]
|
135
|
+
)["startPos"]
|
136
|
+
cursor_position += var_decl_rel_position + gen_code_position
|
137
|
+
|
138
|
+
return evRefs, code, cursor_position, ref_template_var_positions
|
139
|
+
|
140
|
+
|
141
|
+
async def _textFieldCompletion(message, lsp_writers):
|
142
|
+
request_id = message.id
|
143
|
+
message = CodeCompletionContent.parse_obj(message.content)
|
144
|
+
cached = message.cached
|
145
|
+
if cached is None:
|
146
|
+
return {"content": {"data": []}}
|
147
|
+
|
148
|
+
(
|
149
|
+
gen_code_dict,
|
150
|
+
var_name,
|
151
|
+
referencable_var_names,
|
152
|
+
generated_var_names,
|
153
|
+
exporter_obj,
|
154
|
+
fullNameToInfo,
|
155
|
+
) = cached
|
156
|
+
|
157
|
+
(
|
158
|
+
_,
|
159
|
+
code,
|
160
|
+
cursor_position,
|
161
|
+
ref_template_var_positions,
|
162
|
+
) = await get_code_and_cursor_position(
|
163
|
+
message,
|
164
|
+
fullNameToInfo,
|
165
|
+
gen_code_dict,
|
166
|
+
var_name,
|
167
|
+
exporter_obj,
|
168
|
+
lsp_writers,
|
169
|
+
)
|
170
|
+
line, column = position_to_line_col(code, cursor_position)
|
171
|
+
|
172
|
+
code_id = await send_document_open_request_with_diagnostics(
|
173
|
+
lsp_writers["full"],
|
174
|
+
code,
|
175
|
+
exporter_obj,
|
176
|
+
ref_template_var_positions,
|
177
|
+
message.projectConfigName,
|
178
|
+
gen_code_dict["sanitized_full_name"],
|
179
|
+
exporter_obj.code_gen_template_var_section_details["section"]["id"],
|
180
|
+
)
|
181
|
+
await lsp_writers["full"].send_autocomplete_request(
|
182
|
+
line,
|
183
|
+
column,
|
184
|
+
code_id,
|
185
|
+
request_id,
|
186
|
+
referencable_var_names,
|
187
|
+
generated_var_names,
|
188
|
+
cursor_offset=cursor_position - message.position,
|
189
|
+
)
|
190
|
+
|
191
|
+
return None
|
192
|
+
|
193
|
+
|
194
|
+
def read_cache(cache, message):
|
195
|
+
message = message.content
|
196
|
+
message["cached"] = cache.get(
|
197
|
+
get_cache_key(
|
198
|
+
message["projectConfigId"], message["sectionId"], message["paramInfoId"]
|
199
|
+
)
|
200
|
+
)
|
201
|
+
|
202
|
+
|
203
|
+
textFieldCompletion = TaskDefinition(
|
204
|
+
name="textFieldCompletion",
|
205
|
+
return_message_type="textFieldCompletionReturn",
|
206
|
+
fn=_textFieldCompletion,
|
207
|
+
read_cache=read_cache,
|
208
|
+
run_as=RunType.NONE,
|
209
|
+
server_dependencies=["lsp_writers"],
|
210
|
+
)
|