I can validate formatting in editor
This commit is contained in:
@@ -10,6 +10,9 @@ from rich.table import Table
|
||||
from starlette.routing import Mount
|
||||
|
||||
from myfasthtml.core.constants import Routes, ROUTE_ROOT
|
||||
from myfasthtml.core.dsl.types import Position
|
||||
from myfasthtml.core.dsls import DslsManager
|
||||
from myfasthtml.core.formatting.dsl import DSLSyntaxError
|
||||
from myfasthtml.test.MyFT import MyFT
|
||||
|
||||
utils_app, utils_rt = fast_app()
|
||||
@@ -383,12 +386,41 @@ def post(session, b_id: str, values: dict):
|
||||
|
||||
|
||||
@utils_rt(Routes.Completions)
|
||||
def get(session, c_id, text: str, line: int, ch: int):
|
||||
def get(session, e_id: str, text: str, line: int, ch: int):
|
||||
"""
|
||||
Default routes for Domaine Specific Languages completion
|
||||
:param session:
|
||||
:param c_id:
|
||||
:param values:
|
||||
:param e_id: engine_id
|
||||
:param text:
|
||||
:param line:
|
||||
:param ch:
|
||||
:return:
|
||||
"""
|
||||
logger.debug(f"Entering {Routes.Bindings} with {session=}, {c_id=}, {values=}")
|
||||
logger.debug(f"Entering {Routes.Completions} with {session=}, {e_id=}, {text=}, {line=}, {ch}")
|
||||
completion = DslsManager.get_completion_engine(e_id)
|
||||
result = completion.get_completions(text, Position(line, ch))
|
||||
return result.to_dict()
|
||||
|
||||
|
||||
@utils_rt(Routes.Validations)
|
||||
def get(session, e_id: str, text: str, line: int, ch: int):
|
||||
"""
|
||||
Default routes for Domaine Specific Languages syntax validation
|
||||
:param session:
|
||||
:param e_id:
|
||||
:param text:
|
||||
:param line:
|
||||
:param ch:
|
||||
:return:
|
||||
"""
|
||||
logger.debug(f"Entering {Routes.Validations} with {session=}, {e_id=}, {text=}, {line=}, {ch}")
|
||||
validation = DslsManager.get_validation_parser(e_id)
|
||||
try:
|
||||
validation.parse(text)
|
||||
return {"errors": []}
|
||||
except DSLSyntaxError as e:
|
||||
return {"errors": [{
|
||||
"line": e.line or 1,
|
||||
"column": e.column or 1,
|
||||
"message": e.message
|
||||
}]}
|
||||
|
||||
Reference in New Issue
Block a user