Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
pyyaml
jsonref
referencing
more-itertools
tree-sitter
tree-sitter-yaml
];
};

Expand Down
2 changes: 1 addition & 1 deletion noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def lint(session: nox.Session) -> None:
)
session.run("ruff", "check", "--fix", "src")
session.run("ruff", "check", "--fix", "tests")
session.run("mypy", "src")
session.run("zuban", "mypy", "src")


@nox.session()
Expand Down
18 changes: 6 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ keywords = [
]
requires-python = ">=3.12"
dependencies = [
"pygls>=1.1.0",
"pygls>=2.1.1",
"lsprotocol>=2025.0.0",
"jsonschema>=4.23.0",
"jsonschema>=4.26.0",
"pyyaml>=6.0.2",
"referencing>=0.36.2",
"jsonref>=1.1.0",
"jsonpath-ng>=1.7.0",
"more-itertools>=10.7.0",
"tree-sitter>=0.25.2",
"tree-sitter-yaml>=0.7.2",
]
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -44,7 +45,7 @@ fmt = [
]
lint = [
"ruff >=0.15.12,<0.16.0",
"mypy >= 1.14.0",
"zuban >= 0.9.0",
"types-pyyaml",
"types-jsonschema",
]
Expand Down Expand Up @@ -94,15 +95,8 @@ known-first-party = ["craft_ls"]
[tool.mypy]
strict = true

[[tool.mypy.overrides]]
module = [
"jsonref",
"jsonpath_ng"
]
ignore_missing_imports = true

[tool.pyright]
enableReachabilityAnalysis = false # unreliable
enableReachabilityAnalysis = false # unreliable

[tool.pytest]
log_cli_level = "INFO"
Expand Down
25 changes: 15 additions & 10 deletions src/craft_ls/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

from lsprotocol import types as lsp

from craft_ls.core import get_diagnostics, get_validator_and_parse, segmentize_nodes
from craft_ls.types_ import ParsedResult
from craft_ls.core import (
get_diagnostics,
get_validator_from_tree,
)
from craft_ls.parser import parser, yaml_tree_to_dict

logging.basicConfig()

Expand All @@ -19,15 +22,17 @@ def check(file_name: str) -> None:
"""Report all violations for a file."""
file = Path(file_name)

diagnostics: list[lsp.Diagnostic] = []
match get_validator_and_parse(file.stem, file.read_text()):
case None:
print(f"Cannot validate '{file}'", file=sys.stderr)
pass
with file.open("rb") as f:
tree = parser.parse(f.read())

case validator, ParsedResult(instance=instance, nodes=nodes):
segments = segmentize_nodes(nodes)
diagnostics.extend(get_diagnostics(validator, instance, dict(segments)))
validator = get_validator_from_tree(file.stem, tree)
instance = yaml_tree_to_dict(tree)

if not validator:
print(f"Cannot validate '{file}'", file=sys.stderr)
sys.exit(1)

diagnostics: list[lsp.Diagnostic] = get_diagnostics(tree, validator, instance)

if diagnostics:
for diag in diagnostics:
Expand Down
Loading
Loading