-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Anders Eknert <[email protected]> Signed-off-by: Charlie Egan <[email protected]> Co-authored-by: Anders Eknert <[email protected]>
- Loading branch information
1 parent
e9a2ab6
commit 0536573
Showing
9 changed files
with
131 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package regal.lsp.completion.providers["import"] | ||
|
||
import rego.v1 | ||
|
||
import data.regal.lsp.completion.kind | ||
import data.regal.lsp.completion.location | ||
|
||
items contains item if { | ||
position := location.to_position(input.regal.context.location) | ||
line := input.regal.file.lines[position.line] | ||
word := location.word_at(line, input.regal.context.location.col) | ||
|
||
invoke_suggestion(line) | ||
|
||
item := { | ||
"label": "import", | ||
"kind": kind.keyword, | ||
"detail": "import <path>", | ||
"textEdit": { | ||
"range": location.word_range(word, position), | ||
"newText": "import ", | ||
}, | ||
} | ||
} | ||
|
||
invoke_suggestion("") | ||
|
||
invoke_suggestion(line) if startswith("import", line) |
65 changes: 65 additions & 0 deletions
65
bundle/regal/lsp/completion/providers/import/import_test.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package regal.lsp.completion.providers.import_test | ||
|
||
import rego.v1 | ||
|
||
import data.regal.lsp.completion.providers["import"] as provider | ||
|
||
test_import_completion_empty_line if { | ||
policy := `package policy | ||
import rego.v1 | ||
` | ||
|
||
regal_module := {"regal": { | ||
"file": { | ||
"name": "p.rego", | ||
"lines": split(policy, "\n"), | ||
}, | ||
"context": {"location": {"row": 5, "col": 1}}, | ||
}} | ||
items := provider.items with input as regal_module | ||
|
||
items == {{ | ||
"label": "import", | ||
"detail": "import <path>", | ||
"kind": 14, | ||
"textEdit": { | ||
"newText": "import ", | ||
"range": { | ||
"start": {"character": 0, "line": 4}, | ||
"end": {"character": 0, "line": 4}, | ||
}, | ||
}, | ||
}} | ||
} | ||
|
||
test_import_completion_on_typing if { | ||
policy := `package policy | ||
import rego.v1 | ||
imp` | ||
|
||
regal_module := {"regal": { | ||
"file": { | ||
"name": "p.rego", | ||
"lines": split(policy, "\n"), | ||
}, | ||
"context": {"location": {"row": 5, "col": 3}}, | ||
}} | ||
items := provider.items with input as regal_module | ||
|
||
items == {{ | ||
"label": "import", | ||
"detail": "import <path>", | ||
"kind": 14, | ||
"textEdit": { | ||
"newText": "import ", | ||
"range": { | ||
"start": {"character": 0, "line": 4}, | ||
"end": {"character": 3, "line": 4}, | ||
}, | ||
}, | ||
}} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package regal.lsp.completion.providers.utils_test | ||
|
||
import rego.v1 | ||
|
||
parsed_modules(workspace) := {file_uri: parsed_module | | ||
some file_uri, contents in workspace | ||
parsed_module := regal.parse_module(file_uri, contents) | ||
} | ||
|
||
expect_item(items, label, range) if { | ||
expected := {"detail": "local variable", "kind": 6} | ||
|
||
item := object.union(expected, { | ||
"label": label, | ||
"textEdit": { | ||
"newText": label, | ||
"range": range, | ||
}, | ||
}) | ||
|
||
item in items | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters