fix #1 partially

This commit is contained in:
AcerecA 2025-01-28 21:41:37 +01:00
parent 37b746dc48
commit 56fb0982b4
2 changed files with 38 additions and 5 deletions

View File

@ -2,10 +2,11 @@ example = nil
example2 = example
; func2(g_arg1 g_arg2 ?g_args1 1 ?g_argw 2) => nil
(procedure func2(arg1 arg2 @key (args 1) (argw 2) "gggg")
(procedure func2(arg1 arg2 @key (args 1) (argw 2) "ggng")
; some stuff to do
a = some_obj->field1
some_obj->field2 = 2
args = 2
)
(

View File

@ -1,5 +1,6 @@
from collections.abc import Generator
from dataclasses import dataclass, field
from itertools import chain
from logging import INFO, basicConfig, debug, error, getLogger, info, warning
from re import findall, finditer, fullmatch, match as rematch
from time import time
@ -35,6 +36,7 @@ from lsprotocol.types import (
from pygls.server import LanguageServer
from pygls.workspace import TextDocument
from skillls.builtins.common import SkillDataType
from skillls.parsing.iterative import IterativeParser, TokenParser
from .cache import Cache
@ -203,9 +205,9 @@ class SkillLanguageServer(LanguageServer):
)
if any(
in_range(token_range.start, let.range)
and (token in (child.name for child in (let.children or [])))
for let in self.lets
in_range(token_range.start, ns.range)
and (token in (child.name for child in (ns.children or [])))
for ns in chain(self.lets, self.procs)
):
pass
else:
@ -309,11 +311,13 @@ class SkillLanguageServer(LanguageServer):
kwargs: list[DocumentSymbol] = []
rest: list[DocumentSymbol] = []
params_start = found.end() - len(found.group(4))
warning(found.group(4))
for part in finditer(
r"(@(option|key)(\s\(\w+\s+.+\))+|@rest \w+|(\w+\s*))",
rf"(@(option|key)(\s\(\w+\s+.+\))+|@rest \w+|\"[{''.join(dt.value for dt in SkillDataType)}]+\"|(\w+\s*))",
found.group(4),
):
info(part.group(1))
if part.group(1).startswith("@rest"):
rest_var_name = part.group(1).split()[1]
rest_var_range = Range(
@ -362,6 +366,31 @@ class SkillLanguageServer(LanguageServer):
),
)
)
elif fullmatch(
rf'"[{"".join(dt.value for dt in SkillDataType)}]+"',
part.group(1),
):
if not (
len(args) + len(kwargs) + len(rest)
== len(part.group(1)) - 2
):
self.publish_diagnostics(
uri,
[
Diagnostic(
Range(start, Position(row, len(line))),
"type info length mismatches number of arguments",
severity=DiagnosticSeverity.Error,
)
],
)
return
for char, arg in zip(
part.group(1)[1:-1], chain(args, rest, kwargs)
):
typ = SkillDataType(char)
arg.detail = f"{typ.value}_"
break
else:
for arg in finditer(r"(\w+)", part.group(1)):
arg_range = Range(
@ -406,6 +435,9 @@ class SkillLanguageServer(LanguageServer):
for child in proc.children:
yield InlayHint(child.selection_range.end, "|l")
if child.detail:
yield InlayHint(child.selection_range.start, child.detail)
def _hint_globals(self) -> Generator[InlayHint, None, None]:
for glbl in self.globals:
yield InlayHint(glbl.selection_range.end, "|g")