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

Add support for LSP completion using the surrounding context #1057

Merged
merged 24 commits into from
Jan 27, 2023

Conversation

ebresafegaga
Copy link
Contributor

@ebresafegaga ebresafegaga commented Jan 19, 2023

This pull request adds support for auto-completion based on the context (from a record, type, or contract.)

Case 1

Say we have the following:

{
[.]
} | SchemaFromNix

With this change, if the contract SchemaFromNix, represents a record or dictionary contract, we will get completion corresponding to its fields.

Case 2

This will for work not only for basic records, but also for nested records:

let Tf = import "./contract.ncl" in
{
  config = {
    data.dhall.my_dhall_resource = {
      [.]
    }
  }
} | Tf.Config

Here, we would get a completion based on the fields of Tf.Config.config.data.dhall.my_dhall_resource, if it is a record dictionary contract.

Case 3

This also includes support for nested record completion based on the context contract.

let Tf = import "./contract.ncl" in
{
  config[.]
} | Tf.Config

In this case, we would get completion based on the fields of Tf.Config.config, if it is a record or dictionary contract.

Additional improvements

1. Adds error recovery if parsing record fields fails

2. Adds support for completion when we have a dictionary contract: say we have the following:

let foo | {_: {a: Str, b: Str}} = <record definition> in 
foo[.] 

This doesn't get a completion, becuase the dictionary has dynamic fields, but when we do this:

foo.random_dynamic_field[.]

We will get a completion

3. Adds support for contracts represented by variables or static record access (See #998)


Closes #995, Closes #998

@ebresafegaga ebresafegaga marked this pull request as ready for review January 23, 2023 13:44
@github-actions github-actions bot temporarily deployed to pull request January 24, 2023 19:04 Inactive
@github-actions github-actions bot temporarily deployed to pull request January 25, 2023 11:32 Inactive
@github-actions github-actions bot temporarily deployed to pull request January 26, 2023 12:36 Inactive
Copy link
Member

@yannham yannham left a comment

Choose a reason for hiding this comment

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

LGTM. Nice trick to get the parent node by just looking on the left, giving a logarithmic time algo at worst.

lsp/nls/src/requests/completion.rs Outdated Show resolved Hide resolved
lsp/nls/src/requests/completion.rs Outdated Show resolved Hide resolved
src/parser/grammar.lalrpop Outdated Show resolved Hide resolved
src/term/mod.rs Outdated Show resolved Hide resolved
src/parser/grammar.lalrpop Outdated Show resolved Hide resolved
@github-actions github-actions bot temporarily deployed to pull request January 26, 2023 19:02 Inactive
@ebresafegaga ebresafegaga merged commit 8488202 into master Jan 27, 2023
@ebresafegaga ebresafegaga deleted the lsp/context-completion branch January 27, 2023 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants