wafer-lsp 0.1.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.
Files changed (40) hide show
  1. wafer_lsp/__init__.py +1 -0
  2. wafer_lsp/__main__.py +9 -0
  3. wafer_lsp/analyzers/__init__.py +0 -0
  4. wafer_lsp/analyzers/compiler_integration.py +16 -0
  5. wafer_lsp/analyzers/docs_index.py +36 -0
  6. wafer_lsp/handlers/__init__.py +0 -0
  7. wafer_lsp/handlers/code_action.py +48 -0
  8. wafer_lsp/handlers/code_lens.py +48 -0
  9. wafer_lsp/handlers/completion.py +6 -0
  10. wafer_lsp/handlers/diagnostics.py +16 -0
  11. wafer_lsp/handlers/document_symbol.py +87 -0
  12. wafer_lsp/handlers/hover.py +215 -0
  13. wafer_lsp/handlers/inlay_hint.py +65 -0
  14. wafer_lsp/handlers/semantic_tokens.py +124 -0
  15. wafer_lsp/handlers/workspace_symbol.py +87 -0
  16. wafer_lsp/languages/README.md +195 -0
  17. wafer_lsp/languages/__init__.py +17 -0
  18. wafer_lsp/languages/converter.py +88 -0
  19. wafer_lsp/languages/detector.py +34 -0
  20. wafer_lsp/languages/parser_manager.py +33 -0
  21. wafer_lsp/languages/registry.py +99 -0
  22. wafer_lsp/languages/types.py +37 -0
  23. wafer_lsp/parsers/__init__.py +18 -0
  24. wafer_lsp/parsers/base_parser.py +9 -0
  25. wafer_lsp/parsers/cuda_parser.py +95 -0
  26. wafer_lsp/parsers/cutedsl_parser.py +114 -0
  27. wafer_lsp/server.py +58 -0
  28. wafer_lsp/services/__init__.py +21 -0
  29. wafer_lsp/services/analysis_service.py +22 -0
  30. wafer_lsp/services/docs_service.py +40 -0
  31. wafer_lsp/services/document_service.py +20 -0
  32. wafer_lsp/services/hover_service.py +237 -0
  33. wafer_lsp/services/language_registry_service.py +26 -0
  34. wafer_lsp/services/position_service.py +77 -0
  35. wafer_lsp/utils/__init__.py +0 -0
  36. wafer_lsp/utils/lsp_helpers.py +79 -0
  37. wafer_lsp-0.1.0.dist-info/METADATA +57 -0
  38. wafer_lsp-0.1.0.dist-info/RECORD +40 -0
  39. wafer_lsp-0.1.0.dist-info/WHEEL +4 -0
  40. wafer_lsp-0.1.0.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,77 @@
1
+ import ast
2
+
3
+ from lsprotocol.types import Position
4
+
5
+
6
+ class PositionService:
7
+
8
+ def get_word_at_position(self, content: str, position: Position) -> str:
9
+ lines = content.split("\n")
10
+ if position.line >= len(lines):
11
+ return ""
12
+
13
+ line = lines[position.line]
14
+ if position.character >= len(line):
15
+ return ""
16
+
17
+ start = position.character
18
+ while start > 0 and (line[start - 1].isalnum() or line[start - 1] == "_" or line[start - 1] == "."):
19
+ start -= 1
20
+
21
+ end = position.character
22
+ while end < len(line) and (line[end].isalnum() or line[end] == "_" or line[end] == "."):
23
+ end += 1
24
+
25
+ return line[start:end]
26
+
27
+ def get_decorator_at_position(self, content: str, position: Position) -> tuple[str, int] | None:
28
+ lines = content.split("\n")
29
+ if position.line >= len(lines):
30
+ return None
31
+
32
+ line = lines[position.line]
33
+ line_stripped = line.strip()
34
+
35
+ if not line_stripped.startswith("@"):
36
+ return None
37
+
38
+ at_pos = line.find("@")
39
+ if at_pos != -1 and position.character < at_pos:
40
+ return None
41
+
42
+ try:
43
+ tree = ast.parse(line_stripped, mode="eval")
44
+ if isinstance(tree.body, ast.Attribute):
45
+ if isinstance(tree.body.value, ast.Name):
46
+ decorator_name = f"{tree.body.value.id}.{tree.body.attr}"
47
+ for i in range(position.line + 1, len(lines)):
48
+ next_line = lines[i].strip()
49
+ if next_line.startswith("def ") or next_line.startswith("class "):
50
+ return (decorator_name, i)
51
+ elif isinstance(tree.body, ast.Name):
52
+ decorator_name = tree.body.id
53
+ for i in range(position.line + 1, len(lines)):
54
+ next_line = lines[i].strip()
55
+ if next_line.startswith("def ") or next_line.startswith("class "):
56
+ return (decorator_name, i)
57
+ except SyntaxError:
58
+ pass
59
+
60
+ if "@cute.kernel" in line_stripped:
61
+ decorator_name = "cute.kernel"
62
+ for i in range(position.line + 1, len(lines)):
63
+ next_line = lines[i].strip()
64
+ if next_line.startswith("def ") or next_line.startswith("class "):
65
+ return (decorator_name, i)
66
+ elif "@cute.struct" in line_stripped:
67
+ decorator_name = "cute.struct"
68
+ for i in range(position.line + 1, len(lines)):
69
+ next_line = lines[i].strip()
70
+ if next_line.startswith("def ") or next_line.startswith("class "):
71
+ return (decorator_name, i)
72
+
73
+ return None
74
+
75
+
76
+ def create_position_service() -> PositionService:
77
+ return PositionService()
File without changes
@@ -0,0 +1,79 @@
1
+ import ast
2
+
3
+ from lsprotocol.types import Position, Range
4
+
5
+
6
+ def get_word_at_position(content: str, position: Position) -> str:
7
+ lines = content.split("\n")
8
+ if position.line >= len(lines):
9
+ return ""
10
+
11
+ line = lines[position.line]
12
+ if position.character >= len(line):
13
+ return ""
14
+
15
+ start = position.character
16
+ while start > 0 and (line[start - 1].isalnum() or line[start - 1] == "_" or line[start - 1] == "."):
17
+ start -= 1
18
+
19
+ end = position.character
20
+ while end < len(line) and (line[end].isalnum() or line[end] == "_" or line[end] == "."):
21
+ end += 1
22
+
23
+ return line[start:end]
24
+
25
+
26
+ def get_decorator_at_position(content: str, position: Position) -> tuple[str, int] | None:
27
+ lines = content.split("\n")
28
+ if position.line >= len(lines):
29
+ return None
30
+
31
+ line = lines[position.line]
32
+ line_stripped = line.strip()
33
+
34
+ if not line_stripped.startswith("@"):
35
+ return None
36
+
37
+ at_pos = line.find("@")
38
+ if at_pos != -1 and position.character < at_pos:
39
+ return None
40
+
41
+ try:
42
+ tree = ast.parse(line_stripped, mode="eval")
43
+ if isinstance(tree.body, ast.Attribute):
44
+ if isinstance(tree.body.value, ast.Name):
45
+ decorator_name = f"{tree.body.value.id}.{tree.body.attr}"
46
+ for i in range(position.line + 1, len(lines)):
47
+ next_line = lines[i].strip()
48
+ if next_line.startswith("def ") or next_line.startswith("class "):
49
+ return (decorator_name, i)
50
+ elif isinstance(tree.body, ast.Name):
51
+ decorator_name = tree.body.id
52
+ for i in range(position.line + 1, len(lines)):
53
+ next_line = lines[i].strip()
54
+ if next_line.startswith("def ") or next_line.startswith("class "):
55
+ return (decorator_name, i)
56
+ except SyntaxError:
57
+ pass
58
+
59
+ if "@cute.kernel" in line_stripped:
60
+ decorator_name = "cute.kernel"
61
+ for i in range(position.line + 1, len(lines)):
62
+ next_line = lines[i].strip()
63
+ if next_line.startswith("def ") or next_line.startswith("class "):
64
+ return (decorator_name, i)
65
+ elif "@cute.struct" in line_stripped:
66
+ decorator_name = "cute.struct"
67
+ for i in range(position.line + 1, len(lines)):
68
+ next_line = lines[i].strip()
69
+ if next_line.startswith("def ") or next_line.startswith("class "):
70
+ return (decorator_name, i)
71
+
72
+ return None
73
+
74
+
75
+ def create_range(start_line: int, start_char: int, end_line: int, end_char: int) -> Range:
76
+ return Range(
77
+ start=Position(line=start_line, character=start_char),
78
+ end=Position(line=end_line, character=end_char),
79
+ )
@@ -0,0 +1,57 @@
1
+ Metadata-Version: 2.4
2
+ Name: wafer-lsp
3
+ Version: 0.1.0
4
+ Summary: Language Server Protocol server for GPU programming languages
5
+ Author-email: Wafer <support@wafer.ai>
6
+ License: MIT
7
+ Keywords: c++,cuda,cutedsl,gpu,language-server,lsp
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Classifier: Topic :: Text Editors :: Integrated Development Environments (IDE)
15
+ Requires-Python: >=3.12
16
+ Requires-Dist: lsprotocol>=2024.0.0
17
+ Requires-Dist: pygls>=1.0.0
18
+ Requires-Dist: wafer-core
19
+ Description-Content-Type: text/markdown
20
+
21
+ # Wafer LSP
22
+
23
+ Language Server Protocol server for CuTeDSL (Python GPU programming).
24
+
25
+ **Beta Feature**: Currently only available when Beta Mode is enabled in VS Code settings.
26
+
27
+ ## Features
28
+
29
+ - **Hover Information**: Shows kernel and layout information with compiler analysis when hovering over CuTeDSL code
30
+
31
+ ## Installation
32
+
33
+ ```bash
34
+ pip install wafer-lsp
35
+ ```
36
+
37
+ ## Usage
38
+
39
+ ### VS Code Extension
40
+
41
+ The LSP server is integrated into the `wevin-extension` VS Code extension. It starts automatically when Beta Mode is enabled.
42
+
43
+ ### Standalone
44
+
45
+ For Neovim or other editors:
46
+
47
+ ```bash
48
+ python -m wafer_lsp
49
+ ```
50
+
51
+ ## Supported Languages
52
+
53
+ - **CuTeDSL**: Python files with `@cute.kernel` decorators
54
+
55
+ ## Architecture
56
+
57
+ The LSP server uses a modular language registry system. Currently supports CuTeDSL only. See `languages/README.md` for details on adding more languages.
@@ -0,0 +1,40 @@
1
+ wafer_lsp/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
2
+ wafer_lsp/__main__.py,sha256=6J_zJGlexw3ASzI-MRpCzMwzaq_hTdIe12JWg97pLRQ,112
3
+ wafer_lsp/server.py,sha256=ZGFXghuPdKJH7aLhrYvOiKp6zfOdtoqWavdtDwg8Bk4,1938
4
+ wafer_lsp/analyzers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ wafer_lsp/analyzers/compiler_integration.py,sha256=SLyIZXk52nKP1b04s9Wo77cRLFn5auc4jGRo59Vl9Wc,341
6
+ wafer_lsp/analyzers/docs_index.py,sha256=hrrBgPzIM_mJewCzHyw-2YEWdIchuB3SAMXI8PhtDq0,1309
7
+ wafer_lsp/handlers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ wafer_lsp/handlers/code_action.py,sha256=PTWs4X3CkfprMmzqC3cg7uEWdfivNNH9thU4E-c6ztQ,1411
9
+ wafer_lsp/handlers/code_lens.py,sha256=mhdJtbS2LMNHGOirJbXUfatqhqMBess5wndfBBOLnok,1301
10
+ wafer_lsp/handlers/completion.py,sha256=qz36GIJXu2fG6K-FdbFNGCCTYSpyV5A6-WOHHNne7QI,142
11
+ wafer_lsp/handlers/diagnostics.py,sha256=gapTVWObW9xwqLkZbjEn4dhuvaqduD9ozNZDEALnumM,378
12
+ wafer_lsp/handlers/document_symbol.py,sha256=u-SUAjZgLVEs3nkhBmd6icfAqIiqYP6TfDas3JHdiD0,3165
13
+ wafer_lsp/handlers/hover.py,sha256=uTp190gvwOJyRVpJ0Y8VpP-8D5E5V67-GwzuVZ81dpU,7632
14
+ wafer_lsp/handlers/inlay_hint.py,sha256=usPK7a6Z55tHGdd6LrHDO7RHL_UG0G1IGBSVrTF3nHo,1932
15
+ wafer_lsp/handlers/semantic_tokens.py,sha256=w90P__qqCeCe1yDZkPNPHj_vxHVzcUylGmgYqPkfaWs,3427
16
+ wafer_lsp/handlers/workspace_symbol.py,sha256=YGSkf6doChh1BjVezEQFgIsI2NsQHhOjLchoF5bfBK4,2934
17
+ wafer_lsp/languages/README.md,sha256=hLBqOBvKSqeCrNH9Wrr6XAHa8eBnd81IargPDurodU8,5527
18
+ wafer_lsp/languages/__init__.py,sha256=5cXQkPRsh4JLyZd2QubvTxvuip10695Hb2zjyGF6Frc,472
19
+ wafer_lsp/languages/converter.py,sha256=LPKJfkUV-rNXyJg7Tr5AZ1AlREKH4ulfjDHWlUNvyXU,2487
20
+ wafer_lsp/languages/detector.py,sha256=B2YrRN3KaSwcTM5UHMQkamRaqcQgySXYbHD71cN2bP8,1109
21
+ wafer_lsp/languages/parser_manager.py,sha256=RBYS0w2wIRkKlrEDYvMEGKbsTkOSEpfUB3fjH_9X0Hk,945
22
+ wafer_lsp/languages/registry.py,sha256=g8WuTIuwsssHTqM-t3QLsLsUqL0zFUGq3qnBbVxX6sY,2869
23
+ wafer_lsp/languages/types.py,sha256=c22sDECraXHvazqJSF7WC1ntFNyf9Mbx60EXA9jrbWk,624
24
+ wafer_lsp/parsers/__init__.py,sha256=7DUHQE1aA14zXF_3piSqVGr9wBSmDDa7PHtmHzhGkXs,345
25
+ wafer_lsp/parsers/base_parser.py,sha256=RQjk5QOHrS398CrUGP2ZtSsisSl6Kh0KgWLPssSv8ss,176
26
+ wafer_lsp/parsers/cuda_parser.py,sha256=X2EX8gFcZCK8-lSsedby1-vSgYsl2CHLxRxzwr5yIlI,2621
27
+ wafer_lsp/parsers/cutedsl_parser.py,sha256=1r2gdAuwFrp4fQQNEQCRpkwtfunus-hq4h92j2MZyFE,3711
28
+ wafer_lsp/services/__init__.py,sha256=ILqsbYVzyOUXZqAy1FBkyP860vrSoAhCBW3VpanTDio,773
29
+ wafer_lsp/services/analysis_service.py,sha256=J6jcg0YQZh9iQYyOXO9bF5NqaJDfnIKhwssCLNcUJjA,619
30
+ wafer_lsp/services/docs_service.py,sha256=ltjkPuQ4DUmuc95AZVfQ6GSWgpjKqv_6-Luh2CFPocQ,1393
31
+ wafer_lsp/services/document_service.py,sha256=gdQ-leIUSK7tiffFsi4UsseIyBx2TO_WIlBPFh57GU8,559
32
+ wafer_lsp/services/hover_service.py,sha256=Zby2lhMO4US2IVTAVuU-ntkRKWrrR7HEjWdlGFSRQj4,9743
33
+ wafer_lsp/services/language_registry_service.py,sha256=qvMR9oI1pUrSv09Q-WRF5-sEu2Nma2fZeUhdydIWaqg,864
34
+ wafer_lsp/services/position_service.py,sha256=Nx-_AuBEr_yUXjAYPfJ_wmeGM_Gy5vbIUW163GqblCU,2831
35
+ wafer_lsp/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
36
+ wafer_lsp/utils/lsp_helpers.py,sha256=pXYvm_gJiJ_TAwwyGxhqvWJQx6CBecYK1c6tVY7gUF8,2739
37
+ wafer_lsp-0.1.0.dist-info/METADATA,sha256=gLx1YqnfAhI55s3EeaIMXb_Jm8xJoD1vBHXHcCDSv0A,1622
38
+ wafer_lsp-0.1.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
39
+ wafer_lsp-0.1.0.dist-info/entry_points.txt,sha256=XHcM0QZy6GzCYY2ajejqL0tZ2X6y6zYWP0Lg1egxGW4,54
40
+ wafer_lsp-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ wafer-lsp = wafer_lsp.__main__:main