Skip to content

lsp/completions: Handle hyphenated package names#1625

Merged
charlieegan3 merged 2 commits intoopen-policy-agent:mainfrom
charlieegan3:hyp-pack-names
Jul 22, 2025
Merged

lsp/completions: Handle hyphenated package names#1625
charlieegan3 merged 2 commits intoopen-policy-agent:mainfrom
charlieegan3:hyp-pack-names

Conversation

@charlieegan3
Copy link
Copy Markdown
Contributor

Fixes #1391

Copy link
Copy Markdown
Member

@anderseknert anderseknert left a comment

Choose a reason for hiding this comment

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

Very nice! Thanks Charlie. Hyphens are likely the most common char that requires quoting, but I think we could have this updated to support any char quoted path part.

path := concat(".", array.slice(parts, n, len_p))
formatted_parts := [p |
some index, part in array.slice(parts, n, len_p)
p := _format_part(part, contains(part, "-"))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rather than checking for -, should we not check for any character outside ascii and _? So that we can provide suggestions for any path that has special characters quoted?

path != ""

# it's not valid Rego to have a hypenated first part
not startswith(path, `[""`)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure I follow here... ["" doesn't have a hyphen in it. But might want to rewrite this anyway for the change suggested above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ahh, that looks like a typo, I think it was meant to be: ["

Charlie Egan added 2 commits July 22, 2025 10:45
Fixes open-policy-agent#1391

Signed-off-by: Charlie Egan <charlie@styra.com>
Signed-off-by: Charlie Egan <charlie@styra.com>
@charlieegan3 charlieegan3 merged commit 4959712 into open-policy-agent:main Jul 22, 2025
6 checks passed
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.

Completions: suggested package name isn't quoted where necessary

2 participants