avrae-ls 0.4.0__py3-none-any.whl → 0.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,41 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: avrae-ls
3
- Version: 0.4.0
3
+ Version: 0.5.0
4
4
  Summary: Language server for Avrae draconic aliases
5
5
  Author: 1drturtle
6
- Requires-Python: >=3.11
7
- Description-Content-Type: text/markdown
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
8
27
  License-File: LICENSE
9
- Requires-Dist: pygls>=1.3.1
10
- Requires-Dist: lsprotocol>=2023.0.1
11
- Requires-Dist: httpx>=0.27
28
+ Requires-Python: >=3.11
12
29
  Requires-Dist: d20>=1.1.2
30
+ Requires-Dist: httpx>=0.27
31
+ Requires-Dist: lsprotocol>=2023.0.1
32
+ Requires-Dist: pygls>=1.3.1
13
33
  Provides-Extra: dev
14
- Requires-Dist: pytest>=8.3; extra == "dev"
15
- Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
16
- Requires-Dist: pytest-cov>=7.0.0; extra == "dev"
17
- Requires-Dist: ruff>=0.6; extra == "dev"
18
- Dynamic: license-file
34
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
35
+ Requires-Dist: pytest-cov>=7.0.0; extra == 'dev'
36
+ Requires-Dist: pytest>=8.3; extra == 'dev'
37
+ Requires-Dist: ruff>=0.6; extra == 'dev'
38
+ Description-Content-Type: text/markdown
19
39
 
20
40
  # Avrae Draconic Alias Language Server
21
41
 
@@ -0,0 +1,6 @@
1
+ draconic/LICENSE,sha256=Fzvu32_DafLKKn2mzxhEdlmrKZzAsigDZ87O7uoVqZI,1067
2
+ avrae_ls-0.5.0.dist-info/METADATA,sha256=Cl5rYWKuTLOoom3cjo4BV9ah4dMurBJ39nwJMsKBO4s,5916
3
+ avrae_ls-0.5.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
4
+ avrae_ls-0.5.0.dist-info/entry_points.txt,sha256=OtYXipMQzqmxpMoApgo0MeJYFmMbkbFN51Ibhpb8hF4,52
5
+ avrae_ls-0.5.0.dist-info/licenses/LICENSE,sha256=O-0zMbcEi6wXz1DiSdVgzMlQjJcNqNe5KDv08uYzqR0,1055
6
+ avrae_ls-0.5.0.dist-info/RECORD,,
@@ -1,5 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: hatchling 1.27.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
-
avrae_ls/__init__.py DELETED
@@ -1,3 +0,0 @@
1
- from .server import create_server
2
-
3
- __all__ = ["create_server"]
avrae_ls/__main__.py DELETED
@@ -1,108 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import argparse
4
- import asyncio
5
- import logging
6
- import sys
7
- from pathlib import Path
8
- from typing import Iterable
9
-
10
- from lsprotocol import types
11
-
12
- from .config import CONFIG_FILENAME, load_config
13
- from .context import ContextBuilder
14
- from .diagnostics import DiagnosticProvider
15
- from .runtime import MockExecutor
16
- from .server import create_server
17
-
18
-
19
- def main(argv: list[str] | None = None) -> None:
20
- parser = argparse.ArgumentParser(description="Avrae draconic alias language server")
21
- parser.add_argument("--tcp", action="store_true", help="Run in TCP mode instead of stdio")
22
- parser.add_argument("--host", default="127.0.0.1", help="TCP host (when --tcp is set)")
23
- parser.add_argument("--port", type=int, default=2087, help="TCP port (when --tcp is set)")
24
- parser.add_argument("--stdio", action="store_true", help="Accept stdio flag for VS Code clients (ignored)")
25
- parser.add_argument("--log-level", default="WARNING", help="Logging level (DEBUG, INFO, WARNING, ERROR)")
26
- parser.add_argument("--analyze", metavar="FILE", help="Run diagnostics for a file and print them to stdout")
27
- args = parser.parse_args(argv)
28
-
29
- _configure_logging(args.log_level)
30
-
31
- if args.analyze:
32
- if args.tcp:
33
- parser.error("--analyze cannot be combined with --tcp")
34
- sys.exit(_run_analysis(Path(args.analyze)))
35
-
36
- server = create_server()
37
- if args.tcp:
38
- server.start_tcp(args.host, args.port)
39
- else:
40
- server.start_io()
41
-
42
-
43
- def _configure_logging(level: str) -> None:
44
- numeric = getattr(logging, level.upper(), logging.WARNING)
45
- if not isinstance(numeric, int):
46
- numeric = logging.WARNING
47
- logging.basicConfig(
48
- level=numeric,
49
- format="%(levelname)s %(name)s: %(message)s",
50
- )
51
-
52
-
53
- def _run_analysis(path: Path) -> int:
54
- if not path.exists():
55
- print(f"File not found: {path}", file=sys.stderr)
56
- return 2
57
-
58
- workspace_root = _discover_workspace_root(path)
59
- log = logging.getLogger(__name__)
60
- log.info("Analyzing %s (workspace root: %s)", path, workspace_root)
61
-
62
- config, warnings = load_config(workspace_root)
63
- for warning in warnings:
64
- log.warning(warning)
65
-
66
- builder = ContextBuilder(config)
67
- ctx_data = builder.build()
68
- executor = MockExecutor(config.service)
69
- diagnostics = DiagnosticProvider(executor, config.diagnostics)
70
-
71
- source = path.read_text()
72
- results = asyncio.run(diagnostics.analyze(source, ctx_data, builder.gvar_resolver))
73
- _print_diagnostics(path, results)
74
- return 1 if results else 0
75
-
76
-
77
- def _discover_workspace_root(target: Path) -> Path:
78
- current = target if target.is_dir() else target.parent
79
- for folder in [current, *current.parents]:
80
- if (folder / CONFIG_FILENAME).exists():
81
- return folder
82
- return current
83
-
84
-
85
- def _print_diagnostics(path: Path, diagnostics: Iterable[types.Diagnostic]) -> None:
86
- diags = list(diagnostics)
87
- if not diags:
88
- print(f"{path}: no issues found")
89
- return
90
-
91
- for diag in diags:
92
- start = diag.range.start
93
- severity = _severity_label(diag.severity)
94
- source = diag.source or "avrae-ls"
95
- print(f"{path}:{start.line + 1}:{start.character + 1}: {severity} [{source}] {diag.message}")
96
-
97
-
98
- def _severity_label(severity: types.DiagnosticSeverity | None) -> str:
99
- if severity is None:
100
- return "info"
101
- try:
102
- return types.DiagnosticSeverity(severity).name.lower()
103
- except Exception:
104
- return str(severity).lower()
105
-
106
-
107
- if __name__ == "__main__":
108
- main()
avrae_ls/alias_preview.py DELETED
@@ -1,180 +0,0 @@
1
- from __future__ import annotations
2
-
3
- import re
4
- import shlex
5
- from dataclasses import dataclass
6
- from typing import Any, Optional, Tuple
7
-
8
- from .parser import DRACONIC_RE
9
- from .runtime import ExecutionResult, MockExecutor
10
- from .context import ContextData, GVarResolver
11
- from .argument_parsing import apply_argument_parsing
12
-
13
-
14
- @dataclass
15
- class RenderedAlias:
16
- command: str
17
- stdout: str
18
- error: Optional[BaseException]
19
- last_value: Any | None = None
20
-
21
-
22
- def _strip_alias_header(text: str) -> str:
23
- lines = text.splitlines()
24
- if lines and lines[0].lstrip().startswith("!alias"):
25
- first = lines[0].lstrip()
26
- parts = first.split(maxsplit=2)
27
- remainder = parts[2] if len(parts) > 2 else ""
28
- body = "\n".join(lines[1:])
29
- if remainder:
30
- return remainder + ("\n" + body if body else "")
31
- return body
32
- return text
33
-
34
-
35
- async def render_alias_command(
36
- text: str,
37
- executor: MockExecutor,
38
- ctx_data: ContextData,
39
- resolver: GVarResolver,
40
- args: list[str] | None = None,
41
- ) -> RenderedAlias:
42
- """Replace <drac2> blocks with their evaluated values and return final command."""
43
- body = _strip_alias_header(text)
44
- body = apply_argument_parsing(body, args)
45
- stdout_parts: list[str] = []
46
- parts: list[str] = []
47
- last_value = None
48
- error: BaseException | None = None
49
-
50
- pos = 0
51
- for match in DRACONIC_RE.finditer(body):
52
- parts.append(body[pos: match.start()])
53
- code = match.group(1)
54
- result: ExecutionResult = await executor.run(code, ctx_data, resolver)
55
- if result.stdout:
56
- stdout_parts.append(result.stdout)
57
- if result.error:
58
- error = result.error
59
- break
60
- last_value = result.value
61
- parts.append("" if result.value is None else str(result.value))
62
- pos = match.end()
63
-
64
- if error is None:
65
- parts.append(body[pos:])
66
-
67
- final_command = "".join(parts)
68
- return RenderedAlias(command=final_command, stdout="".join(stdout_parts), error=error, last_value=last_value)
69
-
70
-
71
- def validate_embed_payload(payload: str) -> Tuple[bool, str | None]:
72
- """
73
- Light validation for embed previews using Avrae-style flags.
74
-
75
- Accepts strings such as "-title Foo -f \"T|Body\"" and validates arguments.
76
- Returns (is_valid, error_message) without attempting to parse JSON objects.
77
- """
78
- text = payload.strip()
79
- if not text:
80
- return False, "Embed payload is empty."
81
-
82
- return _validate_embed_flags(text)
83
-
84
-
85
- def _validate_embed_flags(text: str) -> Tuple[bool, str | None]:
86
- """Validate embed flags according to Avrae's help text."""
87
- if not text:
88
- return False, "Embed payload is empty."
89
-
90
- try:
91
- tokens = shlex.split(text)
92
- except ValueError as exc: # pragma: no cover - defensive only
93
- return False, f"Embed payload could not be parsed: {exc}"
94
-
95
- flag_handlers = {
96
- "-title": lambda val: _require_value("-title", val),
97
- "-desc": lambda val: _require_value("-desc", val),
98
- "-thumb": lambda val: _require_value("-thumb", val),
99
- "-image": lambda val: _require_value("-image", val),
100
- "-footer": lambda val: _require_value("-footer", val),
101
- "-f": _validate_field_arg,
102
- "-color": _validate_color_arg,
103
- "-t": _validate_timeout_arg,
104
- }
105
-
106
- i = 0
107
- while i < len(tokens):
108
- tok = tokens[i]
109
- key = tok.lower()
110
- if not tok.startswith("-"):
111
- i += 1
112
- continue
113
- if key not in flag_handlers:
114
- return False, f"Embed payload contains unknown flag '{tok}'."
115
- next_val = tokens[i + 1] if i + 1 < len(tokens) else None
116
- ok, err, consumed = flag_handlers[key](next_val)
117
- if not ok:
118
- return False, err
119
- i += consumed + 1
120
- return True, None
121
-
122
-
123
- def _require_value(flag: str, value: str | None) -> Tuple[bool, str | None, int]:
124
- if value is None or value.startswith("-"):
125
- return False, f"Embed flag '{flag}' requires a value.", 0
126
- return True, None, 1
127
-
128
-
129
- def _validate_field_arg(value: str | None) -> Tuple[bool, str | None, int]:
130
- ok, err, consumed = _require_value("-f", value)
131
- if not ok:
132
- return ok, err, consumed
133
- assert value is not None # for type checker
134
- parts = value.split("|")
135
- if len(parts) < 2 or len(parts) > 3:
136
- return False, "Embed field must be in the form \"Title|Text[|inline]\".", consumed
137
- if not parts[0] or not parts[1]:
138
- return False, "Embed field title and text cannot be empty.", consumed
139
- if len(parts) == 3 and parts[2].lower() not in ("inline", ""):
140
- return False, "Embed field inline value must be 'inline' or omitted.", consumed
141
- return True, None, consumed
142
-
143
-
144
- def _validate_color_arg(value: str | None) -> Tuple[bool, str | None, int]:
145
- if value is None or value.startswith("-"):
146
- # Random color is allowed when omitted
147
- return True, None, 0
148
- if not re.match(r"^(?:#|0x)?[0-9a-fA-F]{6}$", value):
149
- return False, "Embed color must be a 6-hex value (e.g. #ff00ff).", 1
150
- return True, None, 1
151
-
152
-
153
- def _validate_timeout_arg(value: str | None) -> Tuple[bool, str | None, int]:
154
- ok, err, consumed = _require_value("-t", value)
155
- if not ok:
156
- return ok, err, consumed
157
- assert value is not None # for type checker
158
- try:
159
- num = int(value)
160
- except ValueError:
161
- return False, "Embed timeout (-t) must be an integer.", consumed
162
- if num < 0 or num > 600:
163
- return False, "Embed timeout (-t) must be between 0 and 600 seconds.", consumed
164
- return True, None, consumed
165
-
166
-
167
- def simulate_command(command: str) -> tuple[str | None, str | None, str | None]:
168
- """Very small shim to preview common commands."""
169
- text = command.strip()
170
- if not text:
171
- return None, None, None
172
- head, *rest = text.split(maxsplit=1)
173
- payload = rest[0] if rest else ""
174
- lowered = head.lower()
175
- if lowered == "echo":
176
- return payload, "echo", None
177
- if lowered == "embed":
178
- valid, error = validate_embed_payload(payload)
179
- return payload, "embed", error
180
- return None, head, None