Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unit type recognition when file edited using systemctl edit cmd #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion systemd_language_server/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,11 @@ def get_directives(unit_type: UnitType, section: UnitFileSection | None) -> list


def get_unit_type(document):
return UnitType(Path(document.uri).suffix.strip("."))
unit_types_pattern = "|".join([i.value for i in UnitType])
file_extension = Path(document.uri).suffix.removeprefix(".")
unit_type_match = re.match(unit_types_pattern, file_extension)
unit_type = unit_type_match[0] if unit_type_match else None
return UnitType(unit_type)


def get_current_section(
Expand Down