Skip to content

Commit

Permalink
Add state_name completion function to be used to complete state names
Browse files Browse the repository at this point in the history
  • Loading branch information
ekacnet committed Jan 14, 2024
1 parent b92f524 commit fc5a97c
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions salt_lsp/base_types.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Tuple


SLS_LANGUAGE_ID = "sls"

StateName = str
StateDoc = str
ActualCompletion = Tuple[StateName, Optional[StateDoc]]
ActualCompletions = List[ActualCompletion]


@dataclass(frozen=True)
class StateParameters:
parameters: Any
Expand Down Expand Up @@ -41,7 +41,29 @@ def __init__(

self.state_sub_names: List[str] = list(self.state_params.keys())

def provide_subname_completion(self, prefix: str = None) -> Tuple[bool, ActualCompletions]:
def provide_name_completion(
self, prefix: str = None
) -> Tuple[bool, ActualCompletions]:

"""
This function provides the names and docstrings of the submodules of
this state.
If prefix is specified only return completion that starts with this prefix
E.g. for the file state, it returns:
[("absent", "doc of absent"), ("accumulated", "doc of accumulated"), ]
The documentation is not guaranteed to be present and can be None.
"""
completions = [(self.state_name, self.state_docs)]
if prefix is None:
return True, completions
return False, list(
filter(lambda x: x[0].startswith(prefix), completions)
)

def provide_subname_completion(
self, prefix: str = None
) -> Tuple[bool, ActualCompletions]:
"""
This function provides the names and docstrings of the submodules of
this state.
Expand All @@ -57,7 +79,9 @@ def provide_subname_completion(self, prefix: str = None) -> Tuple[bool, ActualCo
]
if prefix is None:
return True, completions
return False, list(filter(lambda x: x[0].startswith(prefix), completions))
return False, list(
filter(lambda x: x[0].startswith(prefix), completions)
)

def provide_param_completion(self, submod_name: str) -> List[str]:
return list(self.state_params[submod_name].parameters.keys())
Expand Down

0 comments on commit fc5a97c

Please sign in to comment.