Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lsp): complete variables #2755

Closed

Conversation

saiintbrisson
Copy link

@saiintbrisson saiintbrisson commented Mar 18, 2024

Adds a naive implementation of variable name completion for the current scope. Please judge! This was put together in about 1 hour of getting to know the codebase, I have no idea if it is correct.

image
image

@saiintbrisson

This comment was marked as outdated.

@saiintbrisson saiintbrisson force-pushed the feat/lsp/complete-variables branch 2 times, most recently from d3a12a0 to 9a1472f Compare March 18, 2024 18:35
@saiintbrisson
Copy link
Author

Next step is probably some sort of sorting of completions based on the expected type. Better leave it to another PR

@saiintbrisson

This comment was marked as outdated.

@saiintbrisson
Copy link
Author

saiintbrisson commented Mar 19, 2024

r-a has deeper access to information regarding the local variables, like Environment.scope has, but I gather the Gleam LS can't access an Environment?

I wasn't able to make arguments to an anon function work :(

@lpil
Copy link
Member

lpil commented Mar 20, 2024

Aye, the environment is an internal detail of the analysis code, by this point it does not exist. I think we would implement this by building and then inspecting a call graph.

@saiintbrisson
Copy link
Author

@lpil I think I got it working in almost all cases (or at least those I can think of).

But here's the thing, I went with a recursive approach descending all expressions surrounding the cursor, shouldn't be a problem in most cases, but can be inefficient with complex expression chains and long statements. We can build the call graph and than keep it in memory as long as the source is valid, but I don't really know where to start and what it should look like.

Another thing bugging me is that engine.rs will eventually become a mess. Should we relocate completions to something like engine/completions.rs?

Lemme know if the current way of doing things is acceptable for now, or if you prefer we hold the idea until we have a clearer idea of how to implement it.

@saiintbrisson saiintbrisson force-pushed the feat/lsp/complete-variables branch 2 times, most recently from 9d3119f to f636ddd Compare March 28, 2024 22:44
@lpil
Copy link
Member

lpil commented Apr 1, 2024

Hello! The way to implement this is to build a call graph during compilation and persist that, and then perform a lookup on that graph to get what's currently in scope.

Hold off on splitting any modules for now 👍

@lpil
Copy link
Member

lpil commented May 20, 2024

Closing due to inactivity. Please feel free to reopen! Thank you

@lpil lpil closed this May 20, 2024
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.

None yet

2 participants