Compare commits

...

2 Commits

Author SHA1 Message Date
AcerecA 56fb0982b4 fix #1 partially 2025-01-28 21:41:37 +01:00
AcerecA 37b746dc48 fix #2 2025-01-28 21:18:19 +01:00
2 changed files with 42 additions and 6 deletions

View File

@ -2,10 +2,11 @@ example = nil
example2 = example example2 = example
; func2(g_arg1 g_arg2 ?g_args1 1 ?g_argw 2) => nil ; 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 ; some stuff to do
a = some_obj->field1 a = some_obj->field1
some_obj->field2 = 2 some_obj->field2 = 2
args = 2
) )
( (

View File

@ -1,5 +1,6 @@
from collections.abc import Generator from collections.abc import Generator
from dataclasses import dataclass, field from dataclasses import dataclass, field
from itertools import chain
from logging import INFO, basicConfig, debug, error, getLogger, info, warning from logging import INFO, basicConfig, debug, error, getLogger, info, warning
from re import findall, finditer, fullmatch, match as rematch from re import findall, finditer, fullmatch, match as rematch
from time import time from time import time
@ -35,6 +36,7 @@ from lsprotocol.types import (
from pygls.server import LanguageServer from pygls.server import LanguageServer
from pygls.workspace import TextDocument from pygls.workspace import TextDocument
from skillls.builtins.common import SkillDataType
from skillls.parsing.iterative import IterativeParser, TokenParser from skillls.parsing.iterative import IterativeParser, TokenParser
from .cache import Cache from .cache import Cache
@ -192,7 +194,10 @@ class SkillLanguageServer(LanguageServer):
def _parse_assigns(self, lines: list[str]) -> None: def _parse_assigns(self, lines: list[str]) -> None:
for row, line in enumerate(lines): for row, line in enumerate(lines):
for found in finditer(r"([a-zA-Z_][a-zA-Z0-9_]*)\s*=\s+", line): for found in finditer(
r"\b([a-zA-Z_][a-zA-Z0-9_]*)((-|~)>[a-zA-Z_][a-zA-Z0-9_]*)?\s*=\s+",
line,
):
token = found.group(1) token = found.group(1)
token_range = Range( token_range = Range(
Position(row, found.start()), Position(row, found.start()),
@ -200,9 +205,9 @@ class SkillLanguageServer(LanguageServer):
) )
if any( if any(
in_range(token_range.start, let.range) in_range(token_range.start, ns.range)
and (token in (child.name for child in (let.children or []))) and (token in (child.name for child in (ns.children or [])))
for let in self.lets for ns in chain(self.lets, self.procs)
): ):
pass pass
else: else:
@ -306,11 +311,13 @@ class SkillLanguageServer(LanguageServer):
kwargs: list[DocumentSymbol] = [] kwargs: list[DocumentSymbol] = []
rest: list[DocumentSymbol] = [] rest: list[DocumentSymbol] = []
params_start = found.end() - len(found.group(4)) params_start = found.end() - len(found.group(4))
warning(found.group(4))
for part in finditer( 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), found.group(4),
): ):
info(part.group(1))
if part.group(1).startswith("@rest"): if part.group(1).startswith("@rest"):
rest_var_name = part.group(1).split()[1] rest_var_name = part.group(1).split()[1]
rest_var_range = Range( rest_var_range = Range(
@ -359,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: else:
for arg in finditer(r"(\w+)", part.group(1)): for arg in finditer(r"(\w+)", part.group(1)):
arg_range = Range( arg_range = Range(
@ -403,6 +435,9 @@ class SkillLanguageServer(LanguageServer):
for child in proc.children: for child in proc.children:
yield InlayHint(child.selection_range.end, "|l") 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]: def _hint_globals(self) -> Generator[InlayHint, None, None]:
for glbl in self.globals: for glbl in self.globals:
yield InlayHint(glbl.selection_range.end, "|g") yield InlayHint(glbl.selection_range.end, "|g")