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: Auto-completion of @-attributes for the language server #5846

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

MikaelMayer
Copy link
Member

@MikaelMayer MikaelMayer commented Oct 18, 2024

Description

This PR adds the ability for detecting that the user presses @ when after a space, which is the signature of an attribute. It then provides auto-complete of the attribute name.

How has this been tested?

Tests added in DafnyLanguageServer.Tests

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

Comment on lines 206 to 207
InsertText = attributeName, // TODO: Parentheses
Detail = "" // TODO: Details of attribute name
Copy link
Member

Choose a reason for hiding this comment

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

These look more like unfinished PR todos rather than planned improvements for the next iteration

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm actually going to create a new PR for these todos and added empty details for now, and just attribute name to be inserted. The inserted name is probably not going to change since I don't know how to instruct VSCode to place the caret inside parentheses. But the details about showing up argument names, types and default value is much more complicated than I though (e.g. for fuel, the high fuel should be low fuel + 1 by default) and needs to be thoroughly tested. Let's do one thing at a time.

@@ -86,11 +93,81 @@ public CompletionList Process() {
return new CompletionList();
}

private string GetLastTwoCharactersBeforePositionIncluded(TextReader fileContent, DafnyPosition position) {
Copy link
Member

Choose a reason for hiding this comment

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

I would think this would be a lot simpler if you located the index of the current position and then grabbed the previous two characters. It doesn't seem like processing anything line-by-line buys you anything - "\n@" will still be processed correctly since \n is whitespace.

if (projectManager == null) {
return false;
}
var fileContent = projectManager.ReadFile(request.TextDocument.Uri.ToUri());
Copy link
Member

Choose a reason for hiding this comment

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

Reading the whole file doesn't scale for large files. Please use already processed file contents where the relevant location can be found in O(1) time.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll get back to this soon, but meantime, do you have a hint about where the already processed file contents is? I thought ReadFile would just give me the current string

Copy link
Member

@keyboardDrummer keyboardDrummer Oct 22, 2024

Choose a reason for hiding this comment

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

I've pushed a commit Use a TextBuffer instead of a FileReader, that addresses this comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know why your commit breaks some tests? For example:

Could not close file file:///tmp/z3sq5jsc.kyh/DocumentStaysUnloadedWhenClosed.dfy because it was not open.


private CompletionList CreateAtAttributeCompletionList() {
var completionItems =
Attributes.BuiltinAtAttributes.Select(b =>
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be filtered to the part of the attribute that is already typed? Or are you only providing code completion upon writing the @, but not afterwards?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm only providing instant code completion upon writing the @, not afterwards. The IDE will then filter the list according to what is being typed.

@@ -126,6 +127,10 @@ public ProjectManager(

private const int MaxRememberedChanges = 100;

public TextReader ReadFile(Uri fileToRead) {
Copy link
Member

Choose a reason for hiding this comment

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

This method here makes no sense to me. Why not use a filesystem directly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Your update for reading the last two characters forgot the test case when the position is given in line zero but the column is the number of characters. That fails the test slowlytypefile

Copy link
Member

@keyboardDrummer keyboardDrummer Oct 25, 2024

Choose a reason for hiding this comment

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

I added a fix for slowlytypefile

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.

3 participants