Skip to content

Commit 5405a38

Browse files
committed
chore: code formatting
1 parent 4e6d06d commit 5405a38

23 files changed

+215
-82
lines changed

src/avrae_ls/analysis/diagnostics.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,12 @@ async def _analyze_code(
8383
diagnostics.append(_syntax_from_std(exc))
8484
return diagnostics
8585

86-
diagnostics.extend(
87-
self._check_unknown_names(body, ctx_data, self._settings.semantic_level)
88-
)
86+
diagnostics.extend(self._check_unknown_names(body, ctx_data, self._settings.semantic_level))
8987
diagnostics.extend(await _check_gvars(body, gvar_resolver, self._settings))
9088
diagnostics.extend(_check_imports(body, self._settings.semantic_level))
9189
diagnostics.extend(_check_call_args(body, self._builtin_signatures, self._settings.semantic_level))
9290
diagnostics.extend(_check_private_method_calls(body))
93-
diagnostics.extend(
94-
_check_api_misuse(body, code, ctx_data, self._settings.semantic_level)
95-
)
91+
diagnostics.extend(_check_api_misuse(body, code, ctx_data, self._settings.semantic_level))
9692
if line_shift:
9793
diagnostics = _shift_diagnostics(diagnostics, line_shift, 0)
9894
return diagnostics
@@ -460,7 +456,11 @@ def _uncalled_context_attr_diagnostics(
460456
assigned_names: Set[str],
461457
severity_level: str,
462458
) -> List[types.Diagnostic]:
463-
if isinstance(node.value, ast.Name) and node.value.id in {"character", "combat"} and node.value.id not in assigned_names:
459+
if (
460+
isinstance(node.value, ast.Name)
461+
and node.value.id in {"character", "combat"}
462+
and node.value.id not in assigned_names
463+
):
464464
call_hint = f"{node.value.id}()"
465465
return [
466466
_make_diagnostic(
@@ -599,7 +599,7 @@ def _make_diagnostic(
599599
rng = types.Range(
600600
start=types.Position(line=0, character=0),
601601
end=types.Position(line=0, character=1),
602-
)
602+
)
603603
return types.Diagnostic(
604604
message=message,
605605
range=rng,
@@ -629,8 +629,6 @@ def _shift_diagnostics(diags: List[types.Diagnostic], line_offset: int, char_off
629629
return shifted
630630

631631

632-
633-
634632
def _build_builtin_signatures() -> dict[str, inspect.Signature]:
635633
sigs: dict[str, inspect.Signature] = {}
636634
builtins = _default_builtins()

src/avrae_ls/analysis/parser.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,16 @@ def _block_from_match(match: re.Match[str], inline: bool = False) -> tuple[int,
5757
line_offset += 1
5858
char_offset = 0
5959
line_count = raw.count("\n") + 1 if raw else 1
60-
return match.start(), match.end(), DraconicBlock(
61-
code=raw,
62-
line_offset=line_offset,
63-
char_offset=char_offset,
64-
line_count=line_count,
65-
inline=inline,
60+
return (
61+
match.start(),
62+
match.end(),
63+
DraconicBlock(
64+
code=raw,
65+
line_offset=line_offset,
66+
char_offset=char_offset,
67+
line_count=line_count,
68+
inline=inline,
69+
),
6670
)
6771

6872
blocks: list[DraconicBlock] = []

src/avrae_ls/analysis/symbols.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ def find_references(
8787
ranges.extend(_references_from_code(source_ctx.prepared, name, 0, 0, include_stores))
8888
else:
8989
for block in source_ctx.blocks:
90-
ranges.extend(
91-
_references_from_code(block.code, name, block.line_offset, block.char_offset, include_stores)
92-
)
90+
ranges.extend(_references_from_code(block.code, name, block.line_offset, block.char_offset, include_stores))
9391
return _dedupe_ranges(ranges)
9492

9593

src/avrae_ls/config.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ def _mod(score: int) -> int:
238238
],
239239
"skills": skills,
240240
"saves": saves,
241-
"resistances": {"resist": [{"dtype": "fire", "unless": [], "only": []}], "vuln": [], "immune": [], "neutral": []},
241+
"resistances": {
242+
"resist": [{"dtype": "fire", "unless": [], "only": []}],
243+
"vuln": [],
244+
"immune": [],
245+
"neutral": [],
246+
},
242247
"spellbook": spellbook,
243248
"consumables": consumables,
244249
"cvars": {"favorite_enemy": "goblinoids", "fighting_style": "defense"},
@@ -303,13 +308,29 @@ def _mod(score: int) -> int:
303308
"type": "combatant",
304309
"note": "",
305310
"effects": [],
306-
"stats": {"strength": 8, "dexterity": 14, "constitution": 10, "intelligence": 8, "wisdom": 10, "charisma": 8, "prof_bonus": 2},
311+
"stats": {
312+
"strength": 8,
313+
"dexterity": 14,
314+
"constitution": 10,
315+
"intelligence": 8,
316+
"wisdom": 10,
317+
"charisma": 8,
318+
"prof_bonus": 2,
319+
},
307320
"levels": {},
308321
"skills": {"stealth": {"value": 6, "prof": 1, "bonus": 0, "adv": None}},
309322
"saves": {"dex": 4},
310323
"resistances": {"resist": [], "vuln": [], "immune": [], "neutral": []},
311324
"spellbook": {"spells": []},
312-
"attacks": [{"name": "Scimitar", "verb": "slashes", "proper": False, "activation_type": 1, "raw": {"name": "Scimitar", "bonus": "+4", "damage": "1d6+2 slashing"}}],
325+
"attacks": [
326+
{
327+
"name": "Scimitar",
328+
"verb": "slashes",
329+
"proper": False,
330+
"activation_type": 1,
331+
"raw": {"name": "Scimitar", "bonus": "+4", "damage": "1d6+2 slashing"},
332+
}
333+
],
313334
"max_hp": 11,
314335
"hp": 11,
315336
"temp_hp": 0,
@@ -370,6 +391,7 @@ def _expand_env_vars(data: Any, env: Mapping[str, str], missing_vars: set[str])
370391
if isinstance(data, list):
371392
return [_expand_env_vars(value, env, missing_vars) for value in data]
372393
if isinstance(data, str):
394+
373395
def _replace(match: re.Match[str]) -> str:
374396
var = match.group(1) or match.group(2) or ""
375397
if var in env:
@@ -388,7 +410,9 @@ def _coerce_optional_str(value: Any) -> str | None:
388410
return value_str if value_str.strip() else None
389411

390412

391-
def load_config(workspace_root: Path, *, default_enable_gvar_fetch: bool = False) -> Tuple[AvraeLSConfig, Iterable[str]]:
413+
def load_config(
414+
workspace_root: Path, *, default_enable_gvar_fetch: bool = False
415+
) -> Tuple[AvraeLSConfig, Iterable[str]]:
392416
"""Load `.avraels.json` from the workspace root, returning config and warnings."""
393417
path = workspace_root / CONFIG_FILENAME
394418
if not path.exists():
@@ -448,9 +472,7 @@ def load_config(workspace_root: Path, *, default_enable_gvar_fetch: bool = False
448472

449473
default_profile = str(raw.get("defaultProfile") or "default")
450474
if default_profile not in profiles and profiles:
451-
warnings.append(
452-
f"defaultProfile '{default_profile}' not found; falling back to first profile in file."
453-
)
475+
warnings.append(f"defaultProfile '{default_profile}' not found; falling back to first profile in file.")
454476
default_profile = next(iter(profiles))
455477

456478
if not profiles:

src/avrae_ls/lsp/code_actions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def _rewrite_import_action(
148148
module: str | None,
149149
) -> types.CodeAction:
150150
target = module or "module"
151-
replacement = f"using({target}=\"<gvar-id>\")"
151+
replacement = f'using({target}="<gvar-id>")'
152152
edit = types.TextEdit(range=diag.range, new_text=replacement)
153153
return types.CodeAction(
154154
title="Replace import with using()",

src/avrae_ls/lsp/completions.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ def completion_items_for_position(
141141
return items
142142

143143

144-
def _attribute_completions(receiver: str, prefix: str, code: str, type_map: Dict[str, str] | None = None) -> List[types.CompletionItem]:
144+
def _attribute_completions(
145+
receiver: str, prefix: str, code: str, type_map: Dict[str, str] | None = None
146+
) -> List[types.CompletionItem]:
145147
items: list[types.CompletionItem] = []
146148
type_key = resolve_type_name(receiver, code, type_map)
147149
if IDENT_RE.fullmatch(receiver) and (not type_map or receiver not in type_map) and type_key == receiver:
@@ -384,7 +386,9 @@ def visit_ExceptHandler(self, node: ast.ExceptHandler):
384386
return names
385387

386388

387-
def _attribute_receiver_and_prefix(code: str, line: int, character: int, capture_full_token: bool = False) -> Optional[tuple[str, str]]:
389+
def _attribute_receiver_and_prefix(
390+
code: str, line: int, character: int, capture_full_token: bool = False
391+
) -> Optional[tuple[str, str]]:
388392
lines = code.splitlines()
389393
if line >= len(lines):
390394
return None
@@ -393,7 +397,7 @@ def _attribute_receiver_and_prefix(code: str, line: int, character: int, capture
393397
if capture_full_token:
394398
while end < len(line_text) and (line_text[end].isalnum() or line_text[end] == "_"):
395399
end += 1
396-
line_text = line_text[: end]
400+
line_text = line_text[:end]
397401
dot = line_text.rfind(".")
398402
if dot == -1:
399403
return None

src/avrae_ls/lsp/server.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,13 @@
2222
from avrae_ls.lsp.signature_help import load_signatures, signature_help_for_code
2323
from avrae_ls.lsp.completions import gather_suggestions, completion_items_for_position, hover_for_position
2424
from avrae_ls.lsp.code_actions import code_actions_for_document
25-
from avrae_ls.analysis.symbols import build_symbol_table, document_symbols, find_definition_range, find_references, range_for_word
25+
from avrae_ls.analysis.symbols import (
26+
build_symbol_table,
27+
document_symbols,
28+
find_definition_range,
29+
find_references,
30+
range_for_word,
31+
)
2632

2733
# Prefer package metadata so the server version matches the installed wheel.
2834
try:
@@ -106,9 +112,7 @@ def on_initialize(server: AvraeLanguageServer, params: types.InitializeParams):
106112
@ls.feature(types.INITIALIZED)
107113
async def on_initialized(server: AvraeLanguageServer, params: types.InitializedParams):
108114
for warning in server.state.warnings:
109-
server.window_log_message(
110-
types.LogMessageParams(type=types.MessageType.Warning, message=warning)
111-
)
115+
server.window_log_message(types.LogMessageParams(type=types.MessageType.Warning, message=warning))
112116

113117

114118
@ls.feature(types.TEXT_DOCUMENT_DID_OPEN)
@@ -130,9 +134,7 @@ async def did_save(server: AvraeLanguageServer, params: types.DidSaveTextDocumen
130134
async def did_change_config(server: AvraeLanguageServer, params: types.DidChangeConfigurationParams):
131135
server.load_workspace(server.workspace_root)
132136
for warning in server.state.warnings:
133-
server.window_log_message(
134-
types.LogMessageParams(type=types.MessageType.Warning, message=warning)
135-
)
137+
server.window_log_message(types.LogMessageParams(type=types.MessageType.Warning, message=warning))
136138

137139

138140
@ls.feature(types.TEXT_DOCUMENT_DOCUMENT_SYMBOL)
@@ -336,9 +338,7 @@ async def run_alias(server: AvraeLanguageServer, *args: Any):
336338
if rendered.error:
337339
src = doc.source if doc else text
338340
extra.append(
339-
_runtime_diagnostic_with_source(
340-
rendered.error, server.state.config.diagnostics.runtime_level, src
341-
)
341+
_runtime_diagnostic_with_source(rendered.error, server.state.config.diagnostics.runtime_level, src)
342342
)
343343
await _publish_diagnostics(server, uri, profile=profile, extra=extra)
344344
return response
@@ -393,6 +393,7 @@ def _format_runtime_error(error: BaseException) -> str:
393393
return error.msg
394394
return str(error)
395395

396+
396397
def _runtime_diagnostic_with_source(error: BaseException, level: str, source: str | None) -> types.Diagnostic:
397398
severity = LEVEL_TO_SEVERITY.get(level.lower(), types.DiagnosticSeverity.Error)
398399
if source and hasattr(error, "module"):
@@ -411,7 +412,9 @@ def _runtime_diagnostic_with_source(error: BaseException, level: str, source: st
411412
elif hasattr(error, "node"):
412413
node = getattr(error, "node")
413414
rng = types.Range(
414-
start=types.Position(line=max(getattr(node, "lineno", 1) - 1, 0), character=max(getattr(node, "col_offset", 0), 0)),
415+
start=types.Position(
416+
line=max(getattr(node, "lineno", 1) - 1, 0), character=max(getattr(node, "col_offset", 0), 0)
417+
),
415418
end=types.Position(
416419
line=max(getattr(node, "end_lineno", getattr(node, "lineno", 1)) - 1, 0),
417420
character=max(getattr(node, "end_col_offset", getattr(node, "col_offset", 0) + 1), 0),

src/avrae_ls/lsp/signature_help.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ def _avrae_function_sigs() -> Dict[str, FunctionSig]:
146146
return sigs
147147

148148

149-
def signature_help_for_code(code: str, line: int, character: int, sigs: Dict[str, FunctionSig]) -> Optional[types.SignatureHelp]:
149+
def signature_help_for_code(
150+
code: str, line: int, character: int, sigs: Dict[str, FunctionSig]
151+
) -> Optional[types.SignatureHelp]:
150152
try:
151153
tree = ast.parse(code)
152154
except SyntaxError:

src/avrae_ls/runtime/alias_preview.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ async def render_alias_command(
152152
for kind, match in matches:
153153
if match.start() < pos:
154154
continue
155-
parts.append(body[pos: match.start()])
155+
parts.append(body[pos : match.start()])
156156

157157
if kind in {"block", "inline"}:
158158
code = match.group(1)
@@ -304,7 +304,7 @@ def _validate_field_arg(value: str | None) -> Tuple[bool, str | None, int]:
304304
assert value is not None # for type checker
305305
parts = value.split("|")
306306
if len(parts) < 2 or len(parts) > 3:
307-
return False, "Embed field must be in the form \"Title|Text[|inline]\".", consumed
307+
return False, 'Embed field must be in the form "Title|Text[|inline]".', consumed
308308
if not parts[0] or not parts[1]:
309309
return False, "Embed field title and text cannot be empty.", consumed
310310
if len(parts) == 3 and parts[2].lower() not in ("inline", ""):

src/avrae_ls/runtime/api.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,9 @@ def get_cc_min(self, name: str) -> int:
13521352
"""Minimum value for a custom counter."""
13531353
return self.cc(name).min
13541354

1355-
def set_cc(self, name: str, value: int | None = None, maximum: int | None = None, minimum: int | None = None) -> int:
1355+
def set_cc(
1356+
self, name: str, value: int | None = None, maximum: int | None = None, minimum: int | None = None
1357+
) -> int:
13561358
"""Set value/max/min for a custom counter."""
13571359
con = self._consumable_map().setdefault(str(name), {"name": str(name)})
13581360
if value is not None:
@@ -1697,7 +1699,11 @@ def damage(
16971699
except Exception:
16981700
roll_result = d20.roll("0")
16991701
label = "Damage (CRIT!)" if crit else "Damage"
1700-
return {"damage": f"**{label}**: {roll_result}", "total": roll_result.total, "roll": SimpleRollResult(roll_result)}
1702+
return {
1703+
"damage": f"**{label}**: {roll_result}",
1704+
"total": roll_result.total,
1705+
"roll": SimpleRollResult(roll_result),
1706+
}
17011707

17021708
def set_ac(self, ac: int) -> None:
17031709
"""Set armor class."""
@@ -1856,7 +1862,15 @@ def set_init(self, init: int) -> None:
18561862
class SimpleCombat(_ItemAccessMixin, _DirMixin):
18571863
_data: MutableMapping[str, Any] = field(default_factory=dict)
18581864
ATTRS: ClassVar[list[str]] = ["combatants", "groups", "me", "current", "name", "round_num", "turn_num", "metadata"]
1859-
METHODS: ClassVar[list[str]] = ["get_combatant", "get_group", "set_metadata", "get_metadata", "delete_metadata", "set_round", "end_round"]
1865+
METHODS: ClassVar[list[str]] = [
1866+
"get_combatant",
1867+
"get_group",
1868+
"set_metadata",
1869+
"get_metadata",
1870+
"delete_metadata",
1871+
"set_round",
1872+
"end_round",
1873+
]
18601874

18611875
@property
18621876
def combatants(self) -> list[SimpleCombatant]:

0 commit comments

Comments
 (0)