yuho 5.0.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.
- yuho/__init__.py +16 -0
- yuho/ast/__init__.py +196 -0
- yuho/ast/builder.py +926 -0
- yuho/ast/constant_folder.py +280 -0
- yuho/ast/dead_code.py +199 -0
- yuho/ast/exhaustiveness.py +503 -0
- yuho/ast/nodes.py +907 -0
- yuho/ast/overlap.py +291 -0
- yuho/ast/reachability.py +293 -0
- yuho/ast/scope_analysis.py +490 -0
- yuho/ast/transformer.py +490 -0
- yuho/ast/type_check.py +471 -0
- yuho/ast/type_inference.py +425 -0
- yuho/ast/visitor.py +239 -0
- yuho/cli/__init__.py +14 -0
- yuho/cli/commands/__init__.py +1 -0
- yuho/cli/commands/api.py +431 -0
- yuho/cli/commands/ast_viz.py +334 -0
- yuho/cli/commands/check.py +218 -0
- yuho/cli/commands/config.py +311 -0
- yuho/cli/commands/contribute.py +122 -0
- yuho/cli/commands/diff.py +487 -0
- yuho/cli/commands/explain.py +240 -0
- yuho/cli/commands/fmt.py +253 -0
- yuho/cli/commands/generate.py +316 -0
- yuho/cli/commands/graph.py +410 -0
- yuho/cli/commands/init.py +120 -0
- yuho/cli/commands/library.py +656 -0
- yuho/cli/commands/lint.py +503 -0
- yuho/cli/commands/lsp.py +36 -0
- yuho/cli/commands/preview.py +377 -0
- yuho/cli/commands/repl.py +444 -0
- yuho/cli/commands/serve.py +44 -0
- yuho/cli/commands/test.py +528 -0
- yuho/cli/commands/transpile.py +121 -0
- yuho/cli/commands/wizard.py +370 -0
- yuho/cli/completions.py +182 -0
- yuho/cli/error_formatter.py +193 -0
- yuho/cli/main.py +1064 -0
- yuho/config/__init__.py +46 -0
- yuho/config/loader.py +235 -0
- yuho/config/mask.py +194 -0
- yuho/config/schema.py +147 -0
- yuho/library/__init__.py +84 -0
- yuho/library/index.py +328 -0
- yuho/library/install.py +699 -0
- yuho/library/lockfile.py +330 -0
- yuho/library/package.py +421 -0
- yuho/library/resolver.py +791 -0
- yuho/library/signature.py +335 -0
- yuho/llm/__init__.py +45 -0
- yuho/llm/config.py +75 -0
- yuho/llm/factory.py +123 -0
- yuho/llm/prompts.py +146 -0
- yuho/llm/providers.py +383 -0
- yuho/llm/utils.py +470 -0
- yuho/lsp/__init__.py +14 -0
- yuho/lsp/code_action_handler.py +518 -0
- yuho/lsp/completion_handler.py +85 -0
- yuho/lsp/diagnostics.py +100 -0
- yuho/lsp/hover_handler.py +130 -0
- yuho/lsp/server.py +1425 -0
- yuho/mcp/__init__.py +10 -0
- yuho/mcp/server.py +1452 -0
- yuho/parser/__init__.py +8 -0
- yuho/parser/source_location.py +108 -0
- yuho/parser/wrapper.py +311 -0
- yuho/testing/__init__.py +48 -0
- yuho/testing/coverage.py +274 -0
- yuho/testing/fixtures.py +263 -0
- yuho/transpile/__init__.py +52 -0
- yuho/transpile/alloy_transpiler.py +546 -0
- yuho/transpile/base.py +100 -0
- yuho/transpile/blocks_transpiler.py +338 -0
- yuho/transpile/english_transpiler.py +470 -0
- yuho/transpile/graphql_transpiler.py +404 -0
- yuho/transpile/json_transpiler.py +217 -0
- yuho/transpile/jsonld_transpiler.py +250 -0
- yuho/transpile/latex_preamble.py +161 -0
- yuho/transpile/latex_transpiler.py +406 -0
- yuho/transpile/latex_utils.py +206 -0
- yuho/transpile/mermaid_transpiler.py +357 -0
- yuho/transpile/registry.py +275 -0
- yuho/verify/__init__.py +43 -0
- yuho/verify/alloy.py +352 -0
- yuho/verify/combined.py +218 -0
- yuho/verify/z3_solver.py +1155 -0
- yuho-5.0.0.dist-info/METADATA +186 -0
- yuho-5.0.0.dist-info/RECORD +91 -0
- yuho-5.0.0.dist-info/WHEEL +4 -0
- yuho-5.0.0.dist-info/entry_points.txt +2 -0
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Hover handler for Yuho LSP.
|
|
3
|
+
|
|
4
|
+
Provides hover information for keywords, types, and user-defined symbols.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from typing import List, Optional, TYPE_CHECKING, Callable
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
from lsprotocol import types as lsp
|
|
11
|
+
except ImportError:
|
|
12
|
+
raise ImportError(
|
|
13
|
+
"LSP dependencies not installed. Install with: pip install yuho[lsp]"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
if TYPE_CHECKING:
|
|
17
|
+
from yuho.lsp.server import DocumentState
|
|
18
|
+
from yuho.ast.nodes import TypeNode
|
|
19
|
+
|
|
20
|
+
# Yuho keywords for hover
|
|
21
|
+
YUHO_KEYWORDS = [
|
|
22
|
+
"struct", "fn", "match", "case", "consequence", "pass", "return",
|
|
23
|
+
"statute", "definitions", "elements", "penalty", "illustration",
|
|
24
|
+
"import", "from", "actus_reus", "mens_rea", "circumstance",
|
|
25
|
+
"imprisonment", "fine", "supplementary", "TRUE", "FALSE",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
# Yuho built-in types
|
|
29
|
+
YUHO_TYPES = [
|
|
30
|
+
"int", "float", "bool", "string", "money", "percent", "date", "duration", "void",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
KEYWORD_DOCS = {
|
|
34
|
+
"struct": "Defines a structured type with named fields.",
|
|
35
|
+
"fn": "Defines a function.",
|
|
36
|
+
"match": "Pattern matching expression.",
|
|
37
|
+
"case": "Case arm in a match expression.",
|
|
38
|
+
"statute": "Defines a legal statute with elements and penalties.",
|
|
39
|
+
"elements": "Section containing the elements of an offense.",
|
|
40
|
+
"penalty": "Section specifying the punishment for an offense.",
|
|
41
|
+
"actus_reus": "Physical/conduct element of an offense (guilty act).",
|
|
42
|
+
"mens_rea": "Mental element of an offense (guilty mind).",
|
|
43
|
+
"circumstance": "Circumstantial element required for the offense.",
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
TYPE_DOCS = {
|
|
47
|
+
"int": "Integer number type (whole numbers).",
|
|
48
|
+
"float": "Floating-point number type (decimals).",
|
|
49
|
+
"bool": "Boolean type: TRUE or FALSE.",
|
|
50
|
+
"string": "Text string type.",
|
|
51
|
+
"money": "Monetary amount with currency (e.g., $1000.00 SGD).",
|
|
52
|
+
"percent": "Percentage value (0-100%).",
|
|
53
|
+
"date": "Calendar date (YYYY-MM-DD).",
|
|
54
|
+
"duration": "Time duration (years, months, days, etc.).",
|
|
55
|
+
"void": "No value type (for procedures).",
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def get_hover(
|
|
60
|
+
doc_state: Optional["DocumentState"],
|
|
61
|
+
word: Optional[str],
|
|
62
|
+
type_to_str: Callable[["TypeNode"], str],
|
|
63
|
+
) -> Optional[lsp.Hover]:
|
|
64
|
+
"""Get hover information for word at position."""
|
|
65
|
+
if not word:
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
hover_content: List[str] = []
|
|
69
|
+
|
|
70
|
+
# Check if it's a keyword
|
|
71
|
+
if word in YUHO_KEYWORDS:
|
|
72
|
+
hover_content.append(f"**keyword** `{word}`")
|
|
73
|
+
if word in KEYWORD_DOCS:
|
|
74
|
+
hover_content.append(KEYWORD_DOCS[word])
|
|
75
|
+
|
|
76
|
+
# Check if it's a built-in type
|
|
77
|
+
elif word in YUHO_TYPES:
|
|
78
|
+
hover_content.append(f"**type** `{word}`")
|
|
79
|
+
if word in TYPE_DOCS:
|
|
80
|
+
hover_content.append(TYPE_DOCS[word])
|
|
81
|
+
|
|
82
|
+
# Check AST for user-defined symbols
|
|
83
|
+
elif doc_state and doc_state.ast:
|
|
84
|
+
# Check structs
|
|
85
|
+
for struct in doc_state.ast.type_defs:
|
|
86
|
+
if struct.name == word:
|
|
87
|
+
fields = ", ".join(f"{f.name}: {type_to_str(f.type_annotation)}"
|
|
88
|
+
for f in struct.fields)
|
|
89
|
+
hover_content.append(f"```yuho\nstruct {struct.name} {{\n {fields}\n}}\n```")
|
|
90
|
+
break
|
|
91
|
+
|
|
92
|
+
# Check functions
|
|
93
|
+
for func in doc_state.ast.function_defs:
|
|
94
|
+
if func.name == word:
|
|
95
|
+
params = ", ".join(f"{p.name}: {type_to_str(p.type_annotation)}"
|
|
96
|
+
for p in func.params)
|
|
97
|
+
ret = f" -> {type_to_str(func.return_type)}" if func.return_type else ""
|
|
98
|
+
hover_content.append(f"```yuho\nfn {func.name}({params}){ret}\n```")
|
|
99
|
+
break
|
|
100
|
+
|
|
101
|
+
# Check statutes
|
|
102
|
+
for statute in doc_state.ast.statutes:
|
|
103
|
+
if statute.section_number == word or f"S{statute.section_number}" == word:
|
|
104
|
+
title = statute.title.value if statute.title else "Untitled"
|
|
105
|
+
hover_content.append(f"**Statute Section {statute.section_number}**: {title}")
|
|
106
|
+
|
|
107
|
+
# Add element summary
|
|
108
|
+
if statute.elements:
|
|
109
|
+
hover_content.append("\n**Elements:**")
|
|
110
|
+
for elem in statute.elements:
|
|
111
|
+
hover_content.append(f"- {elem.element_type}: {elem.name}")
|
|
112
|
+
|
|
113
|
+
# Add penalty summary
|
|
114
|
+
if statute.penalty:
|
|
115
|
+
hover_content.append("\n**Penalty:**")
|
|
116
|
+
if statute.penalty.imprisonment_max:
|
|
117
|
+
hover_content.append(f"- Imprisonment: up to {statute.penalty.imprisonment_max}")
|
|
118
|
+
if statute.penalty.fine_max:
|
|
119
|
+
hover_content.append(f"- Fine: up to {statute.penalty.fine_max}")
|
|
120
|
+
break
|
|
121
|
+
|
|
122
|
+
if not hover_content:
|
|
123
|
+
return None
|
|
124
|
+
|
|
125
|
+
return lsp.Hover(
|
|
126
|
+
contents=lsp.MarkupContent(
|
|
127
|
+
kind=lsp.MarkupKind.Markdown,
|
|
128
|
+
value="\n".join(hover_content),
|
|
129
|
+
)
|
|
130
|
+
)
|