add vars and function for completion
This commit is contained in:
@@ -3,15 +3,36 @@ import lsprotocol.types as lsp
|
||||
import pathlib
|
||||
|
||||
|
||||
KIND_MAP = {
|
||||
"function": lsp.CompletionItemKind.Function,
|
||||
"method": lsp.CompletionItemKind.Method,
|
||||
"class": lsp.CompletionItemKind.Class,
|
||||
"variable": lsp.CompletionItemKind.Variable,
|
||||
"field": lsp.CompletionItemKind.Field,
|
||||
"module": lsp.CompletionItemKind.Module,
|
||||
"namespace": lsp.CompletionItemKind.Class,
|
||||
}
|
||||
|
||||
|
||||
class StandardCompletionItems:
|
||||
def __init__(self):
|
||||
self.__tcl_keyword_list = self.load_tcl_keyword()
|
||||
self.__tcl_keyword_list = self.__load_tcl_keyword()
|
||||
self.__nx_procs = self.__load_nx_procs()
|
||||
self.__nx_variables = self.__load_nx_variables()
|
||||
|
||||
@property
|
||||
def tcl_keyword_list(self):
|
||||
return self.__tcl_keyword_list
|
||||
|
||||
def load_tcl_keyword(self) -> list[lsp.CompletionItem]:
|
||||
@property
|
||||
def nx_procs(self):
|
||||
return self.__nx_procs
|
||||
|
||||
@property
|
||||
def nx_variables(self):
|
||||
return self.__nx_variables
|
||||
|
||||
def __load_tcl_keyword(self) -> list[lsp.CompletionItem]:
|
||||
with open(
|
||||
pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r"
|
||||
) as f:
|
||||
@@ -24,5 +45,94 @@ class StandardCompletionItems:
|
||||
)
|
||||
return items
|
||||
|
||||
def __load_nx_variables(self):
|
||||
with open(
|
||||
pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r"
|
||||
) as f:
|
||||
data = json.load(f)
|
||||
items = []
|
||||
for var in data.get("mom_variables", []):
|
||||
label = var.get("label", "")
|
||||
kind_str = var.get("kind", "").lower()
|
||||
kind_enum = KIND_MAP.get(kind_str, lsp.CompletionItemKind.Text)
|
||||
doc_md = f"""\
|
||||
**MOM variable**
|
||||
{label}
|
||||
|
||||
**Description**
|
||||
{var.get("description", "")}
|
||||
|
||||
**Possible Values:**
|
||||
{var.get("possible_values", "any")}
|
||||
|
||||
**Data type**
|
||||
{var.get("data_type", "")}
|
||||
"""
|
||||
items.append(
|
||||
lsp.CompletionItem(
|
||||
label=label,
|
||||
kind=kind_enum,
|
||||
detail=f"{label}",
|
||||
documentation=lsp.MarkupContent(
|
||||
kind=lsp.MarkupKind.Markdown, value=doc_md
|
||||
),
|
||||
)
|
||||
)
|
||||
return items
|
||||
|
||||
def __load_nx_procs(self) -> list[lsp.CompletionItem]:
|
||||
with open(
|
||||
pathlib.Path(__file__).parent.joinpath("completion_list.json"), "r"
|
||||
) as f:
|
||||
data = json.load(f)
|
||||
|
||||
items = []
|
||||
for proc in data.get("MOM_procs", []):
|
||||
label = proc.get("label", "")
|
||||
kind_str = proc.get("kind", "").lower()
|
||||
kind_enum = KIND_MAP.get(kind_str, lsp.CompletionItemKind.Text)
|
||||
|
||||
parameters = proc.get("parameters", [])
|
||||
param_lines = (
|
||||
"\n".join(f"- `{p['name']}`: {p['desc']}" for p in parameters)
|
||||
or "_None_"
|
||||
)
|
||||
|
||||
example_data = proc.get("example", [])
|
||||
example_md = "\n".join(f"{line}" for line in example_data)
|
||||
|
||||
returns_data = proc.get("returns", ["None"])
|
||||
returns_md = "\n".join(f"- {line}" for line in returns_data)
|
||||
|
||||
doc_md = f"""\
|
||||
### 📘 {label}
|
||||
|
||||
**Purpose**
|
||||
{proc.get("description", "No description available.")}
|
||||
|
||||
**Format**
|
||||
`{proc.get("format", label)}`
|
||||
|
||||
**Parameters**
|
||||
{param_lines}
|
||||
|
||||
**Return value**
|
||||
{returns_md}
|
||||
|
||||
**Example**
|
||||
```tcl
|
||||
{example_md}"""
|
||||
items.append(
|
||||
lsp.CompletionItem(
|
||||
label=label,
|
||||
kind=kind_enum,
|
||||
detail=f"{label} – {proc.get('description', '').split('.')[0]}",
|
||||
documentation=lsp.MarkupContent(
|
||||
kind=lsp.MarkupKind.Markdown, value=doc_md
|
||||
),
|
||||
)
|
||||
)
|
||||
return items
|
||||
|
||||
|
||||
standard_items = StandardCompletionItems()
|
||||
|
||||
Reference in New Issue
Block a user