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

experiment: allow sideloading files from fs.FS #1160

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

srenatus
Copy link
Member

@srenatus srenatus commented Oct 2, 2024

  1. add a layer of abstraction, fs.FS, into the code path for loading files
  2. expose a new package global, virtualInput
  3. setting virtualInput will load the provided fs.FS directly, and return an input
  4. all calls to NewInput (all commands incl. LSP) will merge with the "virtual input", if provided

The reason for this: in EOPA, we've got a bunch of rego helper functions, and we'd like the LSP to be aware of them for code completion. This would seem like a decent approach to make it aware of them.

(The actual code completion UX still depends on #1145, because that is how the utility methods are advertised to be used.)

@@ -79,14 +83,13 @@ func InputFromPaths(paths []string) (Input, error) {
go func(path string) {
defer wg.Done()

result, err := loader.RegoWithOpts(path, parse.ParserOptions())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this helper did for us isn't much, so I've inlined it below, added the indirection to read from fs.FS.

@srenatus srenatus force-pushed the sr/allow-sideloading-rego-files branch from bb9adee to 33b9c12 Compare October 2, 2024 09:06
@srenatus srenatus changed the title pkg/rules: introduce fs.FS abstraction for reading rego files experiment: allow sideloading files from fs.FS Oct 2, 2024
@srenatus srenatus force-pushed the sr/allow-sideloading-rego-files branch 3 times, most recently from 31bff9a to 61add84 Compare October 2, 2024 10:07
internal/util/util.go Outdated Show resolved Hide resolved
@srenatus srenatus mentioned this pull request Oct 2, 2024
@srenatus srenatus force-pushed the sr/allow-sideloading-rego-files branch from 61add84 to ecc3947 Compare October 2, 2024 12:06
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.

2 participants