systemrdl-lsp 0.15.0__tar.gz
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.
- systemrdl_lsp-0.15.0/.gitignore +37 -0
- systemrdl_lsp-0.15.0/PKG-INFO +90 -0
- systemrdl_lsp-0.15.0/README.md +63 -0
- systemrdl_lsp-0.15.0/homebrew/systemrdl-lsp.rb +44 -0
- systemrdl_lsp-0.15.0/pyproject.toml +41 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/__init__.py +3 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/__main__.py +39 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/_generated_types.py +94 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/_uri.py +17 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/code_actions.py +91 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/compile.py +439 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/completion.py +311 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/definition.py +416 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/diagnostics.py +255 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/dump.py +105 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/formatting.py +57 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/hover.py +374 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/links.py +113 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/outline.py +372 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/semantic.py +187 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/serialize.py +360 -0
- systemrdl_lsp-0.15.0/src/systemrdl_lsp/server.py +1362 -0
- systemrdl_lsp-0.15.0/tests/__init__.py +0 -0
- systemrdl_lsp-0.15.0/tests/test_server.py +1185 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Editor / IDE
|
|
2
|
+
.vscode/
|
|
3
|
+
.idea/
|
|
4
|
+
*.swp
|
|
5
|
+
|
|
6
|
+
# AI / tooling
|
|
7
|
+
.claude/
|
|
8
|
+
.gstack/
|
|
9
|
+
|
|
10
|
+
# Python
|
|
11
|
+
__pycache__/
|
|
12
|
+
*.py[cod]
|
|
13
|
+
*$py.class
|
|
14
|
+
*.egg-info/
|
|
15
|
+
.venv/
|
|
16
|
+
venv/
|
|
17
|
+
.python-version
|
|
18
|
+
.pytest_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
.mypy_cache/
|
|
21
|
+
dist/
|
|
22
|
+
build/
|
|
23
|
+
*.whl
|
|
24
|
+
|
|
25
|
+
# Node / Bun
|
|
26
|
+
node_modules/
|
|
27
|
+
*.tsbuildinfo
|
|
28
|
+
bun.lockb
|
|
29
|
+
.turbo/
|
|
30
|
+
|
|
31
|
+
# VSCode extension
|
|
32
|
+
*.vsix
|
|
33
|
+
|
|
34
|
+
# Logs / temp
|
|
35
|
+
*.log
|
|
36
|
+
.DS_Store
|
|
37
|
+
/tmp-*
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: systemrdl-lsp
|
|
3
|
+
Version: 0.15.0
|
|
4
|
+
Summary: Language Server for SystemRDL 2.0 — diagnostics, hover, outline (powered by systemrdl-compiler)
|
|
5
|
+
Project-URL: Homepage, https://github.com/seimei-d/systemrdl-pro
|
|
6
|
+
Project-URL: Issues, https://github.com/seimei-d/systemrdl-pro/issues
|
|
7
|
+
Project-URL: Source, https://github.com/seimei-d/systemrdl-pro/tree/main/packages/systemrdl-lsp
|
|
8
|
+
Author: seimei-d
|
|
9
|
+
License: MIT
|
|
10
|
+
Keywords: hardware,language-server,lsp,registers,systemrdl
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Compilers
|
|
17
|
+
Classifier: Topic :: Text Editors :: Integrated Development Environments (IDE)
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Requires-Dist: lsprotocol>=2024.0.0b1
|
|
20
|
+
Requires-Dist: pygls>=1.3.1
|
|
21
|
+
Requires-Dist: systemrdl-compiler>=1.29.0
|
|
22
|
+
Provides-Extra: dev
|
|
23
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
|
|
24
|
+
Requires-Dist: pytest>=8.0; extra == 'dev'
|
|
25
|
+
Requires-Dist: ruff>=0.6; extra == 'dev'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# systemrdl-lsp
|
|
29
|
+
|
|
30
|
+
Language Server Protocol implementation for SystemRDL 2.0 — backed by
|
|
31
|
+
[systemrdl-compiler](https://github.com/SystemRDL/systemrdl-compiler).
|
|
32
|
+
|
|
33
|
+
> **Status:** v0.1 walking skeleton. Only `textDocument/publishDiagnostics` is implemented.
|
|
34
|
+
> Hover, document symbols, goto definition, completion, and the custom `rdl/elaboratedTree`
|
|
35
|
+
> push come in Week 2-5. See [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install systemrdl-lsp
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Or with `uv`:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
uv pip install systemrdl-lsp
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Use
|
|
50
|
+
|
|
51
|
+
The server speaks LSP over stdio. Editor integrations call:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
systemrdl-lsp
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
For VSCode users, install the [`vscode-systemrdl-pro`](https://marketplace.visualstudio.com/items?itemName=seimei-d.vscode-systemrdl-pro)
|
|
58
|
+
extension — it manages the LSP for you.
|
|
59
|
+
|
|
60
|
+
For Vim/Neovim/Helix/Emacs, configure your client to launch `systemrdl-lsp` for files matching
|
|
61
|
+
`*.rdl`. Example for Neovim with `nvim-lspconfig` (config name `systemrdl_lsp` will be added in Week 2):
|
|
62
|
+
|
|
63
|
+
```lua
|
|
64
|
+
-- nvim-lspconfig snippet (Week 2 PR)
|
|
65
|
+
require'lspconfig'.systemrdl_lsp.setup{}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Configuration
|
|
69
|
+
|
|
70
|
+
| Setting | Default | What |
|
|
71
|
+
|---------|---------|------|
|
|
72
|
+
| `systemrdl-lsp.includePaths` | `[]` | List of directories searched by `` `include `` (Week 2). |
|
|
73
|
+
|
|
74
|
+
## What works in v0.1
|
|
75
|
+
|
|
76
|
+
- Detect SystemRDL files (extension `.rdl`)
|
|
77
|
+
- On open / change: run parse + elaboration via `systemrdl-compiler`, publish diagnostics
|
|
78
|
+
with file/line/column from `RDLCompileError`
|
|
79
|
+
- Stdio LSP framing via `pygls`
|
|
80
|
+
|
|
81
|
+
## What does NOT work yet
|
|
82
|
+
|
|
83
|
+
See [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md). All of: hover, goto definition,
|
|
84
|
+
document symbols, completion, the elaborated-tree push, multi-root `incl_search_paths`,
|
|
85
|
+
LSP supervisor + restart, and Perl preprocessor support. They are scheduled — none have
|
|
86
|
+
been forgotten.
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT — see [`../../LICENSE`](../../LICENSE).
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# systemrdl-lsp
|
|
2
|
+
|
|
3
|
+
Language Server Protocol implementation for SystemRDL 2.0 — backed by
|
|
4
|
+
[systemrdl-compiler](https://github.com/SystemRDL/systemrdl-compiler).
|
|
5
|
+
|
|
6
|
+
> **Status:** v0.1 walking skeleton. Only `textDocument/publishDiagnostics` is implemented.
|
|
7
|
+
> Hover, document symbols, goto definition, completion, and the custom `rdl/elaboratedTree`
|
|
8
|
+
> push come in Week 2-5. See [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md).
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install systemrdl-lsp
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or with `uv`:
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
uv pip install systemrdl-lsp
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Use
|
|
23
|
+
|
|
24
|
+
The server speaks LSP over stdio. Editor integrations call:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
systemrdl-lsp
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
For VSCode users, install the [`vscode-systemrdl-pro`](https://marketplace.visualstudio.com/items?itemName=seimei-d.vscode-systemrdl-pro)
|
|
31
|
+
extension — it manages the LSP for you.
|
|
32
|
+
|
|
33
|
+
For Vim/Neovim/Helix/Emacs, configure your client to launch `systemrdl-lsp` for files matching
|
|
34
|
+
`*.rdl`. Example for Neovim with `nvim-lspconfig` (config name `systemrdl_lsp` will be added in Week 2):
|
|
35
|
+
|
|
36
|
+
```lua
|
|
37
|
+
-- nvim-lspconfig snippet (Week 2 PR)
|
|
38
|
+
require'lspconfig'.systemrdl_lsp.setup{}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Configuration
|
|
42
|
+
|
|
43
|
+
| Setting | Default | What |
|
|
44
|
+
|---------|---------|------|
|
|
45
|
+
| `systemrdl-lsp.includePaths` | `[]` | List of directories searched by `` `include `` (Week 2). |
|
|
46
|
+
|
|
47
|
+
## What works in v0.1
|
|
48
|
+
|
|
49
|
+
- Detect SystemRDL files (extension `.rdl`)
|
|
50
|
+
- On open / change: run parse + elaboration via `systemrdl-compiler`, publish diagnostics
|
|
51
|
+
with file/line/column from `RDLCompileError`
|
|
52
|
+
- Stdio LSP framing via `pygls`
|
|
53
|
+
|
|
54
|
+
## What does NOT work yet
|
|
55
|
+
|
|
56
|
+
See [`../../docs/ROADMAP.md`](../../docs/ROADMAP.md). All of: hover, goto definition,
|
|
57
|
+
document symbols, completion, the elaborated-tree push, multi-root `incl_search_paths`,
|
|
58
|
+
LSP supervisor + restart, and Perl preprocessor support. They are scheduled — none have
|
|
59
|
+
been forgotten.
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
MIT — see [`../../LICENSE`](../../LICENSE).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Homebrew formula for systemrdl-lsp.
|
|
2
|
+
#
|
|
3
|
+
# Place in a tap (e.g. github.com/seimei-d/homebrew-tap/Formula/systemrdl-lsp.rb)
|
|
4
|
+
# and install with:
|
|
5
|
+
#
|
|
6
|
+
# brew tap seimei-d/tap
|
|
7
|
+
# brew install systemrdl-lsp
|
|
8
|
+
#
|
|
9
|
+
# When packaging a new release, update `url` to the PyPI tarball, regenerate
|
|
10
|
+
# `sha256` (`shasum -a 256 systemrdl_lsp-*.tar.gz`), and bump the version.
|
|
11
|
+
class SystemrdlLsp < Formula
|
|
12
|
+
include Language::Python::Virtualenv
|
|
13
|
+
|
|
14
|
+
desc "Language Server for SystemRDL 2.0 (diagnostics, hover, outline)"
|
|
15
|
+
homepage "https://github.com/seimei-d/systemrdl-pro"
|
|
16
|
+
url "https://files.pythonhosted.org/packages/source/s/systemrdl-lsp/systemrdl_lsp-0.14.7.tar.gz"
|
|
17
|
+
sha256 "0000000000000000000000000000000000000000000000000000000000000000"
|
|
18
|
+
license "MIT"
|
|
19
|
+
|
|
20
|
+
depends_on "python@3.12"
|
|
21
|
+
|
|
22
|
+
resource "pygls" do
|
|
23
|
+
url "https://files.pythonhosted.org/packages/source/p/pygls/pygls-2.0.0.tar.gz"
|
|
24
|
+
sha256 "0000000000000000000000000000000000000000000000000000000000000000"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
resource "lsprotocol" do
|
|
28
|
+
url "https://files.pythonhosted.org/packages/source/l/lsprotocol/lsprotocol-2024.0.0.tar.gz"
|
|
29
|
+
sha256 "0000000000000000000000000000000000000000000000000000000000000000"
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
resource "systemrdl-compiler" do
|
|
33
|
+
url "https://files.pythonhosted.org/packages/source/s/systemrdl-compiler/systemrdl_compiler-1.32.2.tar.gz"
|
|
34
|
+
sha256 "0000000000000000000000000000000000000000000000000000000000000000"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def install
|
|
38
|
+
virtualenv_install_with_resources
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test do
|
|
42
|
+
assert_match "systemrdl-lsp", shell_output("#{bin}/systemrdl-lsp --version")
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "systemrdl-lsp"
|
|
3
|
+
version = "0.15.0"
|
|
4
|
+
description = "Language Server for SystemRDL 2.0 — diagnostics, hover, outline (powered by systemrdl-compiler)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
license = { text = "MIT" }
|
|
8
|
+
authors = [{ name = "seimei-d" }]
|
|
9
|
+
keywords = ["systemrdl", "lsp", "language-server", "hardware", "registers"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 3 - Alpha",
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Programming Language :: Python :: 3.10",
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
15
|
+
"Programming Language :: Python :: 3.12",
|
|
16
|
+
"Topic :: Software Development :: Compilers",
|
|
17
|
+
"Topic :: Text Editors :: Integrated Development Environments (IDE)",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [
|
|
20
|
+
"pygls>=1.3.1",
|
|
21
|
+
"systemrdl-compiler>=1.29.0",
|
|
22
|
+
"lsprotocol>=2024.0.0b1",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = ["pytest>=8.0", "pytest-asyncio>=0.23", "ruff>=0.6"]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
systemrdl-lsp = "systemrdl_lsp.__main__:main"
|
|
30
|
+
|
|
31
|
+
[project.urls]
|
|
32
|
+
Homepage = "https://github.com/seimei-d/systemrdl-pro"
|
|
33
|
+
Issues = "https://github.com/seimei-d/systemrdl-pro/issues"
|
|
34
|
+
Source = "https://github.com/seimei-d/systemrdl-pro/tree/main/packages/systemrdl-lsp"
|
|
35
|
+
|
|
36
|
+
[build-system]
|
|
37
|
+
requires = ["hatchling"]
|
|
38
|
+
build-backend = "hatchling.build"
|
|
39
|
+
|
|
40
|
+
[tool.hatch.build.targets.wheel]
|
|
41
|
+
packages = ["src/systemrdl_lsp"]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Entry point: `systemrdl-lsp` (stdio LSP) and `python -m systemrdl_lsp`."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import logging
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from systemrdl_lsp import __version__
|
|
10
|
+
from systemrdl_lsp.server import build_server
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main() -> int:
|
|
14
|
+
parser = argparse.ArgumentParser(
|
|
15
|
+
prog="systemrdl-lsp",
|
|
16
|
+
description="Language Server for SystemRDL 2.0 (stdio).",
|
|
17
|
+
)
|
|
18
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {__version__}")
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--log-level",
|
|
21
|
+
default="WARNING",
|
|
22
|
+
choices=["DEBUG", "INFO", "WARNING", "ERROR"],
|
|
23
|
+
help="Logging verbosity (default: WARNING). Logs go to stderr.",
|
|
24
|
+
)
|
|
25
|
+
args = parser.parse_args()
|
|
26
|
+
|
|
27
|
+
logging.basicConfig(
|
|
28
|
+
level=getattr(logging, args.log_level),
|
|
29
|
+
format="%(asctime)s [%(levelname)s] %(name)s: %(message)s",
|
|
30
|
+
stream=sys.stderr,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
server = build_server()
|
|
34
|
+
server.start_io()
|
|
35
|
+
return 0
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
raise SystemExit(main())
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# ruff: noqa: E501, UP007, UP037
|
|
2
|
+
"""Auto-generated from ``schemas/elaborated-tree.json``. DO NOT EDIT.
|
|
3
|
+
|
|
4
|
+
Regenerate via ``bun run codegen`` (Decision 9A).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from typing import Literal, TypedDict, Union
|
|
10
|
+
|
|
11
|
+
try:
|
|
12
|
+
from typing import NotRequired # Python 3.11+
|
|
13
|
+
except ImportError:
|
|
14
|
+
from typing_extensions import NotRequired # type: ignore[assignment]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# $defs ---------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
HexU64 = str
|
|
20
|
+
|
|
21
|
+
class SourceLoc(TypedDict):
|
|
22
|
+
uri: str
|
|
23
|
+
line: int
|
|
24
|
+
column: NotRequired[int]
|
|
25
|
+
endLine: NotRequired[int]
|
|
26
|
+
endColumn: NotRequired[int]
|
|
27
|
+
|
|
28
|
+
AccessMode = Literal['rw', 'ro', 'wo', 'w1c', 'w0c', 'w1s', 'w0s', 'rclr', 'rset', 'wclr', 'wset', 'na']
|
|
29
|
+
|
|
30
|
+
class EncodeEntry(TypedDict):
|
|
31
|
+
name: str
|
|
32
|
+
displayName: NotRequired[str]
|
|
33
|
+
value: "HexU64"
|
|
34
|
+
desc: NotRequired[str]
|
|
35
|
+
|
|
36
|
+
class Field(TypedDict):
|
|
37
|
+
name: str
|
|
38
|
+
displayName: NotRequired[str]
|
|
39
|
+
lsb: int
|
|
40
|
+
msb: int
|
|
41
|
+
access: "AccessMode"
|
|
42
|
+
reset: NotRequired["HexU64"]
|
|
43
|
+
desc: NotRequired[str]
|
|
44
|
+
source: NotRequired["SourceLoc"]
|
|
45
|
+
isCounter: NotRequired[bool]
|
|
46
|
+
isIntr: NotRequired[bool]
|
|
47
|
+
encode: NotRequired[list["EncodeEntry"]]
|
|
48
|
+
|
|
49
|
+
class Reg(TypedDict):
|
|
50
|
+
kind: Literal['reg']
|
|
51
|
+
name: str
|
|
52
|
+
type: NotRequired[str]
|
|
53
|
+
displayName: NotRequired[str]
|
|
54
|
+
address: "HexU64"
|
|
55
|
+
width: Literal[8, 16, 32, 64]
|
|
56
|
+
accessWidth: NotRequired[Literal[8, 16, 32, 64]]
|
|
57
|
+
reset: NotRequired["HexU64"]
|
|
58
|
+
accessSummary: NotRequired[str]
|
|
59
|
+
desc: NotRequired[str]
|
|
60
|
+
source: NotRequired["SourceLoc"]
|
|
61
|
+
fields: list["Field"]
|
|
62
|
+
|
|
63
|
+
class Regfile(TypedDict):
|
|
64
|
+
kind: Literal['regfile']
|
|
65
|
+
name: str
|
|
66
|
+
type: NotRequired[str]
|
|
67
|
+
displayName: NotRequired[str]
|
|
68
|
+
address: "HexU64"
|
|
69
|
+
size: "HexU64"
|
|
70
|
+
desc: NotRequired[str]
|
|
71
|
+
source: NotRequired["SourceLoc"]
|
|
72
|
+
children: list[Union["Regfile", "Reg"]]
|
|
73
|
+
|
|
74
|
+
class Addrmap(TypedDict):
|
|
75
|
+
kind: Literal['addrmap']
|
|
76
|
+
name: str
|
|
77
|
+
type: NotRequired[str]
|
|
78
|
+
displayName: NotRequired[str]
|
|
79
|
+
address: "HexU64"
|
|
80
|
+
size: "HexU64"
|
|
81
|
+
desc: NotRequired[str]
|
|
82
|
+
isBridge: NotRequired[bool]
|
|
83
|
+
source: NotRequired["SourceLoc"]
|
|
84
|
+
children: list[Union["Addrmap", "Regfile", "Reg"]]
|
|
85
|
+
|
|
86
|
+
# Top-level envelope ----------------------------------------------------
|
|
87
|
+
|
|
88
|
+
class ElaboratedTree(TypedDict):
|
|
89
|
+
schemaVersion: Literal['0.1.0']
|
|
90
|
+
version: NotRequired[int]
|
|
91
|
+
unchanged: NotRequired[bool]
|
|
92
|
+
elaboratedAt: NotRequired[str]
|
|
93
|
+
stale: NotRequired[bool]
|
|
94
|
+
roots: list["Addrmap"]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""URI ↔ filesystem path conversion."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import pathlib
|
|
6
|
+
import urllib.parse
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def _uri_to_path(uri: str) -> pathlib.Path:
|
|
10
|
+
parsed = urllib.parse.urlparse(uri)
|
|
11
|
+
if parsed.scheme not in ("file", ""):
|
|
12
|
+
raise ValueError(f"Only file:// URIs are supported, got {uri!r}")
|
|
13
|
+
return pathlib.Path(urllib.parse.unquote(parsed.path))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _path_to_uri(p: pathlib.Path) -> str:
|
|
17
|
+
return p.resolve().as_uri()
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""textDocument/codeAction: surface quick fixes the user can invoke from the
|
|
2
|
+
lightbulb.
|
|
3
|
+
|
|
4
|
+
For now, one fix:
|
|
5
|
+
|
|
6
|
+
- **Add missing reset**. SystemRDL fields without an explicit reset value are
|
|
7
|
+
legal but typically a mistake — undefined hardware reset is a frequent bug
|
|
8
|
+
source. The action inserts ``= 0`` before the closing ``;`` on the field's
|
|
9
|
+
instantiation line.
|
|
10
|
+
|
|
11
|
+
The quick fix is offered when the cursor sits on a field instantiation line
|
|
12
|
+
that ends with ``[N:N];`` or ``[N:N]\s*;`` (no ``=`` after the bit range).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import re
|
|
18
|
+
|
|
19
|
+
from lsprotocol.types import (
|
|
20
|
+
CodeAction,
|
|
21
|
+
CodeActionKind,
|
|
22
|
+
Position,
|
|
23
|
+
Range,
|
|
24
|
+
TextEdit,
|
|
25
|
+
WorkspaceEdit,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# Field instantiation: end of line is ``[msb:lsb] ;`` with no ``=`` between
|
|
29
|
+
# the closing bracket and the semicolon. We capture the position of ``;`` so
|
|
30
|
+
# we can insert ``= 0`` immediately before it.
|
|
31
|
+
_FIELD_NO_RESET_RE = re.compile(
|
|
32
|
+
r"\][^=;]*?(?<!=)(\s*);"
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _add_missing_reset_action(
|
|
37
|
+
uri: str, text: str, line_0b: int, _char_0b: int
|
|
38
|
+
) -> CodeAction | None:
|
|
39
|
+
"""Build the "Add missing reset" CodeAction for the line under cursor.
|
|
40
|
+
|
|
41
|
+
Returns None when the line doesn't end with a field instantiation that's
|
|
42
|
+
missing its reset.
|
|
43
|
+
"""
|
|
44
|
+
lines = text.splitlines()
|
|
45
|
+
if line_0b < 0 or line_0b >= len(lines):
|
|
46
|
+
return None
|
|
47
|
+
line = lines[line_0b]
|
|
48
|
+
if "=" in line and re.search(r"=\s*[0-9xXbB]", line.split("//", 1)[0]):
|
|
49
|
+
# Already has a numeric reset somewhere on the line — bail.
|
|
50
|
+
return None
|
|
51
|
+
m = _FIELD_NO_RESET_RE.search(line)
|
|
52
|
+
if m is None:
|
|
53
|
+
return None
|
|
54
|
+
# Insert ``= 0`` immediately before the semicolon. Use a zero-width
|
|
55
|
+
# range at the semicolon position; LSP TextEdit treats zero-width
|
|
56
|
+
# ranges as insertions.
|
|
57
|
+
semi_col = m.end() - 1
|
|
58
|
+
# Indent-aware: drop a single space if there isn't one already so the
|
|
59
|
+
# output reads ``[0:0] = 0;`` rather than ``[0:0]= 0;``.
|
|
60
|
+
needs_space = semi_col == 0 or line[semi_col - 1] != " "
|
|
61
|
+
new_text = (" = 0" if needs_space else "= 0") if not needs_space else " = 0"
|
|
62
|
+
edit = TextEdit(
|
|
63
|
+
range=Range(
|
|
64
|
+
start=Position(line=line_0b, character=semi_col),
|
|
65
|
+
end=Position(line=line_0b, character=semi_col),
|
|
66
|
+
),
|
|
67
|
+
new_text=new_text,
|
|
68
|
+
)
|
|
69
|
+
return CodeAction(
|
|
70
|
+
title="Add `= 0` reset value",
|
|
71
|
+
kind=CodeActionKind.QuickFix,
|
|
72
|
+
edit=WorkspaceEdit(changes={uri: [edit]}),
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _code_actions_for_range(uri: str, text: str, rng: Range) -> list[CodeAction]:
|
|
77
|
+
"""Produce the list of applicable CodeActions for the given range.
|
|
78
|
+
|
|
79
|
+
LSP sends a Range; we iterate every line in it and collect any actions
|
|
80
|
+
that apply. Most invocations come with a zero-width range at the cursor
|
|
81
|
+
so this is usually a one-line scan.
|
|
82
|
+
"""
|
|
83
|
+
actions: list[CodeAction] = []
|
|
84
|
+
for line_0b in range(rng.start.line, rng.end.line + 1):
|
|
85
|
+
action = _add_missing_reset_action(uri, text, line_0b, rng.start.character)
|
|
86
|
+
if action is not None:
|
|
87
|
+
actions.append(action)
|
|
88
|
+
return actions
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
__all__ = ["_add_missing_reset_action", "_code_actions_for_range"]
|