grain icon indicating copy to clipboard operation
grain copied to clipboard

feat(lsp): Add autocomplete

Open spotandjake opened this issue 11 months ago • 3 comments

This pr adds autocomplete to the grain language. I think we may want to expand this in the future. Possibly with a better parser to improve finding the current context of completion. Right now we just treat = as indicating you want value completions and : as indicating you want type completions There are a few issues with this approach though, such as ew do not currently trigger completions 1 + <here> in the position of <here> and other similar cases. we also mistreat type T = as value completions currently, so some more consideration may need to be given on parsing rules. Im opening the pr now though as I am hoping to get feedback on parsing rules here.

Another possible addition would be to try and use the sourceTree to give context, I didnt take this approach as in most cases sourceTree is very far behind where your autocompleting and not very helpful, it would have to be used in addition to the half parser though rather than as an alternative.

Another possible future expansion is adding autocompletes to includes that scan the directory for .gr files and suggest them. I think this could come in a later pr though, maybe after we determine the new include syntax.

Another possible future expansion would be adding snippet completions to keywords. but i feel this can come in a later pr.

This pr replaces: #1262, Thanks to marcus for the initial implementation from that pr.

spotandjake avatar Jul 23 '23 16:07 spotandjake

I think we need to go ahead and handle the cases for completion a little better—going ahead and looking for the let ... = for value completions and type ... = for type completions. We can fall back to just = but we should look for the let first.

ospencer avatar Aug 11 '23 14:08 ospencer

I made that change and improved the way detection is done.

spotandjake avatar Aug 20 '23 18:08 spotandjake

@ospencer if you get a chance would you be willing to review the new implementation. It needs more work before its good so im going to convert this to a draft.

spotandjake avatar Feb 27 '24 23:02 spotandjake