Skip to content
Merged
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
15 changes: 13 additions & 2 deletions src/craft_ls/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,11 @@ def get_snapcraft_validator(tree: Tree) -> Validator:
)

case _:
validator = MissingTypeSnapcraftValidator()
validator = MissingTypeSnapcraftValidator(
schema=snapcraft_registry.resolver()
.lookup("urn:snapcraft:core26")
.contents
)

return cast(Validator, validator)

Expand All @@ -194,7 +198,14 @@ def get_validator_from_tree(file_stem: str, tree: Tree) -> Validator | None:
else:
# by elimination, file_stem is charmcraft
if get_charm_type(tree) != "charm":
return cast(Validator, MissingTypeCharmcraftValidator())
return cast(
Validator,
MissingTypeCharmcraftValidator(
charmcraft_registry.resolver()
.lookup("urn:charmcraft:platformcharm")
.contents
),
)

validator = cast(
Validator,
Expand Down
7 changes: 7 additions & 0 deletions src/craft_ls/types_.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from __future__ import annotations

from collections import deque
from dataclasses import dataclass
from typing import Any, Generator, NamedTuple, NewType, TypeAlias

from jsonschema import ValidationError, Validator
Expand All @@ -26,12 +27,15 @@ class IndexEntry(NamedTuple):
DocumentsIndex: TypeAlias = dict[str, IndexEntry]


@dataclass
class MissingTypeCharmcraftValidator:
"""No op implementation.

Used if charmcraft.yaml is missing the 'type' key or is set to 'bundle'.
"""

schema: Any

def iter_errors(
self, instance: Any, _schema: Any = None
) -> Generator[ValidationError, None, None]:
Expand All @@ -47,6 +51,7 @@ def iter_errors(
MISSING_TYPE_MSG = "Missing or unsupported 'base' and/or 'build-base' key(s)."


@dataclass
class MissingTypeSnapcraftValidator:
"""No op implementation.

Expand All @@ -55,6 +60,8 @@ class MissingTypeSnapcraftValidator:
- using an unsupported base
"""

schema: Any

def iter_errors(
self, instance: Any, _schema: Any = None
) -> Generator[ValidationError, None, None]:
Expand Down
11 changes: 7 additions & 4 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ async def test_diagnostic_on_open(client: LanguageClient):

@pytest.mark.asyncio
async def test_completion_at_root_key(client: LanguageClient):
"""Verify incomplete keys successfully suggest top-level fields (like confinement)."""
"""Verify incomplete keys successfully suggest top-level fields (like confinement).

In addition, we check that we get some minimal level of feature even if we don't have
fully determined the schema to use.
"""
# Given
uri = "file:///workspace/snapcraft.yaml"
text_content = dedent(
"""
base: core24
confi
"""
)
Expand All @@ -81,11 +84,11 @@ async def test_completion_at_root_key(client: LanguageClient):
)
)

# Trigger completion right at the tip of 'confi' at line 1 (+offset 1)) col 5
# Trigger completion right at the tip of 'confi' at line 0 (+offset 1)) col 5
response = await client.text_document_completion_async(
types.CompletionParams(
text_document=types.TextDocumentIdentifier(uri=uri),
position=types.Position(line=2, character=5),
position=types.Position(line=1, character=5),
)
)

Expand Down
Loading