Skip to content

Commit 3577efe

Browse files
authored
lsp/completion/input: don't suggest 'input' following dot (#1603)
While it's perhaps possible to have something like `data.foo.input.bar`, that `input` wouldn't be the same `input` as suggested here: we're explicitly documenting it as "the input document". This should fix the situation where you can use suggestions to come up with input.input.input.input Signed-off-by: Stephan Renatus <stephan@styra.com>
1 parent 981d8d2 commit 3577efe

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

bundle/regal/lsp/completion/providers/input/input.rego

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ items contains item if {
1818

1919
startswith("input", word.text)
2020

21+
# input, as we mean it here, cannot follow dot (like data.input or input.input)
22+
before := trim_suffix(line, word.text)
23+
not endswith(before, ".")
24+
2125
item := {
2226
"label": "input",
2327
"kind": kind.keyword,

bundle/regal/lsp/completion/providers/input/input_test.rego

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ allow if {
3434
},
3535
}}
3636
}
37+
38+
test_no_input_completion_on_[typed] if {
39+
template := `allow if {
40+
%s
41+
}`
42+
43+
some typed in ["foo.", "data.", "input."]
44+
45+
policy := _with_header(sprintf(template, [typed]))
46+
47+
items := provider.items with input as util.input_with_location(policy, {"row": 6, "col": 1 + count(typed)})
48+
items == set()
49+
}
50+
51+
_with_header(policy) := concat("\n\n", ["package policy", "import rego.v1", policy])

0 commit comments

Comments
 (0)