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

Initial and *extremely* basic completions #435

Merged
merged 1 commit into from
Sep 5, 2020

Conversation

majastrz
Copy link
Member

@majastrz majastrz commented Sep 3, 2020

Added (as the title says) extremely basic completions support. The suggested completions currently include keywords, existing keyword snippets, primitive types and names of accessible symbols (vars, params, resources, and functions).

Limitations:

  • The completions are not at all context aware. In other words, it will list the same completions everywhere regardless if they are valid in that place or not.
  • No completions are offered for properties of objects anywhere.

We have to start here because implementing a completion handler in the language server completely removes the built-in completions which provide some help right now.

Next steps:

  • Incrementally build up context awareness to reduce the set of completions being returned.
  • Add object property completions.
  • Make snippets more contextual
  • More snippets in specific contexts (for example, we could have snippets that are offered only for parameter types and nowhere else).
  • Implementing dynamic snippets. For example, we could auto generate a minimum resource snippet for resources with accurate required metadata in swaggers.
  • Tests!

return Task.FromResult(new CompletionList(completions, isIncomplete: false));
}

public override Task<CompletionItem> Handle(CompletionItem request, CancellationToken cancellationToken)
Copy link
Member Author

Choose a reason for hiding this comment

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

The handle and can resolve are not used by us. They are intended to delay construction of documentation. Right now, we don't need it.

Copy link

Choose a reason for hiding this comment

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

H he h

Copy link
Member Author

Choose a reason for hiding this comment

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

@mymo2202

@codecov-commenter
Copy link

codecov-commenter commented Sep 3, 2020

Codecov Report

Merging #435 into master will decrease coverage by 0.86%.
The diff coverage is 18.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #435      +/-   ##
==========================================
- Coverage   91.93%   91.06%   -0.87%     
==========================================
  Files         199      201       +2     
  Lines        6708     6784      +76     
==========================================
+ Hits         6167     6178      +11     
- Misses        541      606      +65     
Flag Coverage Δ
#dotnet 91.06% <18.75%> (-0.87%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Bicep.Core/Emit/TemplateWriter.cs 100.00% <ø> (ø)
...c/Bicep.LangServer/Completions/SymbolExtensions.cs 0.00% <0.00%> (ø)
...icep.LangServer/Handlers/BicepCompletionHandler.cs 17.85% <17.85%> (ø)
src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs 100.00% <100.00%> (ø)
src/Bicep.Core/LanguageConstants.cs 98.07% <100.00%> (ø)
src/Bicep.LangServer/Server.cs 90.32% <100.00%> (+0.32%) ⬆️


private IEnumerable<CompletionItem> GetPrimitiveTypeCompletions() => LanguageConstants.DeclarationTypes.Values.Select(CreateTypeCompletion);

private IEnumerable<Symbol> GetAccessibleSymbols(SemanticModel model)
Copy link
Member Author

Choose a reason for hiding this comment

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

Next iterations will move this code into the core because it's related to how namespace lookups work during name binding. The dictionary is here to effectively remove inaccessible symbols from completion list. (Declaring a parameter called concat will prevent the concat() function from appearing in the list of completions.

@majastrz majastrz merged commit d1f4bd9 into master Sep 5, 2020
@majastrz majastrz deleted the majastrz/omg-completions!!! branch September 5, 2020 00:46
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.

4 participants