Skip to content

Commit

Permalink
Don't suggest completions for internal rules or functions (#754)
Browse files Browse the repository at this point in the history
Fixes #751

Signed-off-by: Anders Eknert <anders@styra.com>
  • Loading branch information
anderseknert authored May 28, 2024
1 parent 10aa4b7 commit e10ec82
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internal/lsp/completions/providers/rulerefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ func (*RuleFromImportedPackageRefs) Run(
continue
}

// don't suggest refs of "private" rules, even
// if only just by naming convention
if strings.Contains(ref.Label, "._") {
continue
}

isFromImportedPackage := false

for _, i := range mod.Imports {
Expand Down
2 changes: 2 additions & 0 deletions internal/lsp/completions/providers/rulerefs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func TestRuleFromImportedPackageRefs(t *testing.T) {
"file:///foo/foo.rego": `package foo
bar := true
_internal := true
`,
"file:///bar/bar.rego": `package bar
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/completions/refs/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"slices"
"strings"

"gopkg.in/yaml.v2"
"gopkg.in/yaml.v3"

"github.com/open-policy-agent/opa/ast"

Expand Down
6 changes: 3 additions & 3 deletions internal/lsp/completions/refs/refs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ A package that's for things
%s
foo: bar
tags:
- a
- b
- c
- a
- b
- c
%s
`, "```yaml", "```"),
},
Expand Down
2 changes: 1 addition & 1 deletion internal/lsp/types/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Ref struct {
Label string
// Detail is a small amount of additional information about the object.
Detail string
// Description is a longer description of the object and us markdown formatted.
// Description is a longer description of the object and uses Markdown formatting.
Description string
}

Expand Down

0 comments on commit e10ec82

Please # to comment.