Skip to content

Initial snippets for salt states #6

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

Merged
merged 8 commits into from
Apr 17, 2020

Conversation

mchugh19
Copy link
Contributor

@mchugh19 mchugh19 commented Apr 14, 2020

Here's some initial work to support state module autocompletion in sls files.
Fixes: #2

A python generate script creates basic snippet json files for each salt state's functions. Since the arguments for each function are highly variable, these autogenerated functions only complete the name, and move the cursor to the next line. But the json files can be further updated by hand to include more function specific defaults where they make sense.

I've added basic arguments for the functions in the test state as an example.

Usage is as follows:
image
Typing test. and pressing ctrl-space brings up the menu for the test state.

Selecting the first test. entry prompts for a specific function:
image
Pressing tab will complete the snippet prompting and move the cursor to the end of the line.

Pressing ctrl-space again, will pickup the full function definition, and add additional attributes:
image
image
Again, any default entries which require filling out, are cycled through with the tab key. After all entries have been filled out, the cursor is again brought to the end of the input.

VSCode will offer all matching state options, so you can also skip the first prompting step and simply select the specific function from the initial prompt. The basic initial selector has since been removed in favor of using the full function lists.

So far only the test state has been configured besides the basic listing, but it's a start and can as fancy as people want.
image

Human edited snippets:

  • test
  • saltcheck tests (.tst files)
  • file
  • cron
  • docker_container
  • docker_image
  • host
  • http
  • keystore

@xiaohuazi123
Copy link

awesome!

@marek-obuchowicz
Copy link
Contributor

I'm fine with releasing that, together with #7 - or do you plan any other PRs soon, which should be part of the release as well?

Thanks a lot, @mchugh19

@marek-obuchowicz marek-obuchowicz changed the base branch from master to develop April 16, 2020 20:50
@marek-obuchowicz
Copy link
Contributor

@mchugh19 I'm also thinking about running snippet generator on CI builds (preferably within docker container, without OS dependencies), what do you think?

@mchugh19
Copy link
Contributor Author

@marek-obuchowicz I've just added states from a Windows minion. With that done, that's all I've got! Sounds good!

I tried adding sane defaults for:

  • saltcheck tests (.tst files)
  • file
  • cron
  • docker_container
  • docker_image
  • host
  • http
  • keystore

So getting an extra set of eyes on those in particular would be helpful.

As for running the generator, that's not bad as it won't touch any entries which have been hand edited -- it just ensures that the names exist. But this probably only needs to be run for each salt release in order to catch newly added functions.

Finally, since the generator uses salt to list out state functions, the states being called (and the modules used) must be able to be loaded. So we're probably missing some state data due to missing dependencies. Because of that, it's perhaps not the most useful to run the generator locally, unless you have an image with a lot of dependencies needed for salt modules (perhaps one of the salt PR testing images?).

@marek-obuchowicz marek-obuchowicz merged commit b1e0bae into korekontrol:develop Apr 17, 2020
@marek-obuchowicz
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: module autocompletion
4 participants