Skip to content

Commit 8eccfec

Browse files
committed
[IMP] server: add manual symbol for odoo.tests.common.Form
1 parent 99de437 commit 8eccfec

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

server/core/odoo.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self):
3535
self.version_major = 0
3636
self.version_minor = 0
3737
self.version_micro = 0
38+
self.full_version = ""
3839
self.stop_init = False
3940

4041
self.refreshMode = "afterDelay"
@@ -215,6 +216,7 @@ def build_base(self, ls, used_config):
215216
self.version_major = int(res[0].split("saas~")[-1].replace("'", "").replace('"', ''))
216217
self.version_minor = int(res[1])
217218
self.version_micro = int(res[2])
219+
self.full_version = ".".join(str(x) for x in [self.version_major, self.version_minor, self.version_micro])
218220
else:
219221
self.version_major, self.version_minor, self.version_micro = 14, 0, 0
220222
ls.show_message("Unable to detect the Odoo version. Running the tool for the version 14", MessageType.Error)

server/core/python_arch_builder.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ def load_arch(self, require_module=False):
103103
fileInfo.publish_diagnostics(self.ls)
104104
if self.filePath.endswith("__init__.py"):
105105
PythonArchBuilderOdooHooks.on_package_declaration(self.symStack[-1])
106+
if self.symStack[-1].type == SymType.FILE:
107+
PythonArchBuilderOdooHooks.on_file_declaration(self.symStack[-1])
106108
#print("END arch: " + self.filePath + " " + (str(type(self.ast_node)) if self.ast_node else "") )
107109
self.symStack[-1].archStatus = 2
108110
return self.symStack[-1]

server/core/python_arch_builder_odoo_hooks.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,23 @@ def on_package_declaration(symbol):
3636
instance = True
3737
)
3838

39+
@staticmethod
40+
def on_file_declaration(symbol):
41+
from .odoo import Odoo
42+
if symbol.name == "common":
43+
if symbol.get_tree() == (["odoo", "tests", "common"], []):
44+
if Odoo.get().full_version >= "16.3":
45+
form_var = Symbol("Form", SymType.VARIABLE)
46+
getattr_sym = symbol.get_symbol([], ["__getattr__"])
47+
if not getattr_sym:
48+
return #TODO should never happen
49+
form_var.start_pos = getattr_sym.start_pos
50+
form_var.end_pos = getattr_sym.end_pos
51+
symbol.add_symbol(form_var)
52+
3953
@staticmethod
4054
def on_class_declaration(symbol):
4155
""" called when ArchBuilder create a new class Symbol """
42-
from .odoo import Odoo
4356
if symbol.name == "BaseModel": #fast, basic check
4457
if symbol.get_tree() == (["odoo", "models"], ["BaseModel"]): #slower but more precise verification
4558
# ---------- env ----------
@@ -89,4 +102,4 @@ def on_class_declaration(symbol):
89102
if symbol.get_tree() in [(["odoo", "fields"], ["Many2one"]),
90103
(["odoo", "fields"], ["Many2many"]),
91104
(["odoo", "fields"], ["One2many"]),]:
92-
symbol.get_context = Relational_get_context.__get__(symbol, symbol.__class__)
105+
symbol.get_context = Relational_get_context.__get__(symbol, symbol.__class__)

server/core/python_arch_eval_odoo_hooks.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import ast
12
from ..constants import *
23
from .evaluation import Evaluation
34
from .odoo import Odoo
45
from .symbol import Symbol
56
from ..references import RegisteredRef
7+
from .import_resolver import *
8+
from ..odoo_language_server import OdooLanguageServer
69

710

811
class EvaluationTestCursor(Evaluation):
@@ -49,6 +52,9 @@ def on_file_eval(symbol):
4952
if envClass:
5053
PythonArchEvalOdooHooks.on_env_eval(envClass)
5154
elif symbol.get_tree() == (["odoo", "tests", "common"], []):
55+
form_sym = symbol.get_symbol([], ["Form"])
56+
if form_sym:
57+
PythonArchEvalOdooHooks.on_form_eval(form_sym)
5258
transactionClass = symbol.get_symbol([], ["TransactionCase"])
5359
if transactionClass:
5460
PythonArchEvalOdooHooks.on_transactionCase_eval(transactionClass)
@@ -117,3 +123,10 @@ def on_transactionCase_eval(symbol):
117123
env_var.eval.context["test_mode"] = True # used to define the Cursor type
118124
env_var.add_dependency(envModel, BuildSteps.ARCH_EVAL, BuildSteps.ARCH)
119125
env_var.doc = ""
126+
127+
@staticmethod
128+
def on_form_eval(symbol):
129+
if not Odoo.get().full_version >= "16.3":
130+
return
131+
fileSymbol = symbol.get_in_parents([SymType.FILE])
132+
symbols = resolve_import_stmt(OdooLanguageServer.get(), fileSymbol, fileSymbol, "form", [ast.alias("Form", "")], 1, symbol.start_pos, symbol.end_pos)

server/odoo_language_server.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ def get():
4040
def set(instance):
4141
OdooLanguageServer.instance.set(instance)
4242

43-
odoo_server = OdooLanguageServer()
43+
odoo_server = OdooLanguageServer()
44+
OdooLanguageServer.set(odoo_server)

0 commit comments

Comments
 (0)