Skip to content

Commit e6c5b3b

Browse files
committed
[IMP] server: add deprecation warning on odoo.tests.common.Form
1 parent 8eccfec commit e6c5b3b

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

server/core/python_arch_builder_odoo_hooks.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def on_file_declaration(symbol):
4848
return #TODO should never happen
4949
form_var.start_pos = getattr_sym.start_pos
5050
form_var.end_pos = getattr_sym.end_pos
51+
form_var.deprecated_reason = "Use odoo.tests.Form instead of odoo.tests.common.Form"
5152
symbol.add_symbol(form_var)
5253

5354
@staticmethod

server/core/python_arch_eval_odoo_hooks.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,8 @@ def on_form_eval(symbol):
130130
return
131131
fileSymbol = symbol.get_in_parents([SymType.FILE])
132132
symbols = resolve_import_stmt(OdooLanguageServer.get(), fileSymbol, fileSymbol, "form", [ast.alias("Form", "")], 1, symbol.start_pos, symbol.end_pos)
133+
_, form_symbol, _ = symbols[0]
134+
symbol.eval = Evaluation(
135+
symbol = RegisteredRef(form_symbol),
136+
instance=True
137+
)

server/core/symbol.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Symbol(RegisterableObject):
4646
__slots__ = ("name", "type", "eval", "ast_node", "value", "symbols", "moduleSymbols",
4747
"localSymbols", "dependencies", "dependents", "parent",
4848
"modelData", "external", "start_pos", "end_pos", "archStatus", "odooStatus", "validationStatus",
49-
"not_found_paths", "i_ext", "doc")
49+
"not_found_paths", "i_ext", "doc", "deprecated_reason")
5050

5151
def __init__(self, name, type):
5252
super().__init__()
@@ -112,6 +112,7 @@ def __init__(self, name, type):
112112
self.odooStatus = 0 #0: not loaded, 1: building, 2: loaded
113113
self.validationStatus = 0 #0: not validated, 1: in validation, 2: validated
114114
self.not_found_paths = []
115+
self.deprecated_reason: str = None #if not None, the symbol is deprecated and the reason is given
115116
self.doc = None
116117

117118
def __str__(self):

server/features/validation/python_validator.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ...python_utils import PythonUtils
88
from ...core.file_mgr import FileMgr
99
from ...core.import_resolver import resolve_import_stmt
10-
from lsprotocol.types import (Diagnostic,Position, Range)
10+
from lsprotocol.types import (Diagnostic,DiagnosticTag,Position, Range)
1111

1212
class ClassContentCacheValidator():
1313

@@ -275,6 +275,19 @@ def create_symbol(name, type, lineno):
275275

276276
def validate_structure(self):
277277
for symbol in self.symStack[0].get_ordered_symbols():
278+
if symbol.eval and symbol.eval.get_symbol() and symbol.eval.get_symbol().deprecated_reason: #not follow_ref because we only want to raise on first ref
279+
position = (symbol.start_pos, symbol.end_pos)
280+
self.diagnostics.append(Diagnostic(
281+
range = Range(
282+
start=Position(line=position[0][0]-1, character=position[0][1]),
283+
end=Position(line=position[0][0]-1, character=1) if sys.version_info < (3, 8) else \
284+
Position(line=position[0][0]-1, character=position[1][0])
285+
),
286+
message = symbol.eval.get_symbol().name + " is deprecated: " + symbol.eval.get_symbol().deprecated_reason,
287+
source = EXTENSION_NAME,
288+
tags=[DiagnosticTag.Deprecated],
289+
severity = 3
290+
))
278291
if symbol.type == SymType.CLASS:
279292
if symbol.modelData:
280293
position = (symbol.start_pos, symbol.end_pos)

0 commit comments

Comments
 (0)