Skip to content

Commit 8929291

Browse files
Added fallback language to list snippets (#2984)
1 parent b325728 commit 8929291

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

src/check_community_repo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
]
99

1010
required_actions = [
11+
"code.language",
1112
"user.homophones_get",
1213
"user.insert_snippet_by_name",
1314
"user.reformat_text",

src/snippets/snippet_types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def create(
6262
@dataclass
6363
class ListInsertionSnippet:
6464
type = "list"
65+
fallbackLanguage: str | None
6566
substitutions: dict[str, str] | None
6667
snippets: list[CustomInsertionSnippet]
6768

@@ -98,6 +99,7 @@ def create(snippet: CommunityWrapperSnippet):
9899
@dataclass
99100
class ListWrapperSnippet:
100101
type = "list"
102+
fallbackLanguage: str | None
101103
snippets: list[CustomWrapperSnippet]
102104

103105

src/snippets/snippets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class UserActions:
100100
def insert_snippet_by_name(
101101
name: str, # pyright: ignore [reportGeneralTypeIssues]
102102
# Don't add optional: we need to match the type in community
103-
substitutions: dict[str, str] = None,
103+
substitutions: dict[str, str] = None, # type: ignore
104104
):
105105
action = InsertSnippetAction(
106106
get_list_insertion_snippet(name, substitutions),

src/snippets/snippets_get.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def get_list_insertion_snippet(
3030
raise
3131

3232
return ListInsertionSnippet(
33+
get_fallback_language(),
3334
substitutions,
3435
[CustomInsertionSnippet.create(s) for s in snippets],
3536
)
@@ -49,5 +50,13 @@ def get_list_wrapper_snippet(name: str) -> ListWrapperSnippet | CustomWrapperSni
4950
raise
5051

5152
return ListWrapperSnippet(
53+
get_fallback_language(),
5254
[CustomWrapperSnippet.create(s) for s in snippets],
5355
)
56+
57+
58+
def get_fallback_language():
59+
language = actions.code.language()
60+
if language and isinstance(language, str):
61+
return language
62+
return None

0 commit comments

Comments
 (0)