|
1 | 1 | from functools import lru_cache |
2 | 2 | from sqlglot import Dialect, Tokenizer |
3 | | -from sqlmesh.lsp.custom import AllModelsResponse |
| 3 | +from sqlmesh.lsp.custom import AllModelsResponse, MacroCompletion |
4 | 4 | from sqlmesh import macro |
5 | 5 | import typing as t |
6 | 6 | from sqlmesh.lsp.context import AuditTarget, LSPContext, ModelTarget |
@@ -60,15 +60,23 @@ def get_models(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t. |
60 | 60 | return all_models |
61 | 61 |
|
62 | 62 |
|
63 | | -def get_macros(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t.Set[str]: |
64 | | - """Return a set of all macros with the ``@`` prefix.""" |
65 | | - names = set(macro.get_registry()) |
| 63 | +def get_macros( |
| 64 | + context: t.Optional[LSPContext], file_uri: t.Optional[URI] |
| 65 | +) -> t.List[MacroCompletion]: |
| 66 | + """Return a list of macros with optional descriptions.""" |
| 67 | + macros: t.Dict[str, t.Optional[str]] = {} |
| 68 | + |
| 69 | + for name, m in macro.get_registry().items(): |
| 70 | + macros[name] = getattr(m.func, "__doc__", None) |
| 71 | + |
66 | 72 | try: |
67 | 73 | if context is not None: |
68 | | - names.update(context.context._macros) |
| 74 | + for name, m in context.context._macros.items(): |
| 75 | + macros[name] = getattr(m.func, "__doc__", None) |
69 | 76 | except Exception: |
70 | 77 | pass |
71 | | - return names |
| 78 | + |
| 79 | + return [MacroCompletion(name=name, description=doc) for name, doc in macros.items()] |
72 | 80 |
|
73 | 81 |
|
74 | 82 | def get_keywords(context: t.Optional[LSPContext], file_uri: t.Optional[URI]) -> t.Set[str]: |
|
0 commit comments