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

Better completion handling on field/var declaration = n #283

Merged
merged 1 commit into from
Sep 4, 2024

Conversation

kjonescertinia
Copy link
Contributor

@kjonescertinia kjonescertinia commented Aug 23, 2024

This changes code completion handling for when the new keyword can be used. If it is preceded by typeName identifier = and the typeName to a type with either a no arg constructor or an SObject then we replace the keyword suggestions by new typeName();

It might be possible to support other uses cases where new is being used, such as just assigning to vars, but this matches the feature request and is probably the most common case so I have just supported on declarations.

The PR has some improvements for typeName parsing as we were not handling whitespace very well.

@kjonescertinia kjonescertinia linked an issue Aug 23, 2024 that may be closed by this pull request
@@ -95,6 +93,13 @@ trait CompletionProvider {
.map(keyword => CompletionItemLink(keyword, "Keyword"))
.toArray

val creatorCompletions =
if (classDetails._2.nonEmpty && keywords.map(_.label).contains("new")) {
getEmptyCreatorCompletionItems(classDetails._2.get, terminatedContent._3)
Copy link
Contributor

Choose a reason for hiding this comment

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

the tuple accessors aren't so pretty with no IDE telling you what it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I try and write XXXAndYYY when I notice that but didn't spot this.

val trimmed = idAssignPattern.replaceFirstIn(line, "")
if (trimmed == line)
return emptyCompletions

Copy link
Contributor

Choose a reason for hiding this comment

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

Does it continue to work if you half write things like new Ob ? Are we able to do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Kind of, VSCode asks for completion on the 'n' and continues to show the completion if you type 'e' etc. If you type something other than 'e' it will ask for completion again if we did not provide any matches the first time around.

We have a bit of a mismatch here in that when you press 'n' we give a reply as though the 'n' wasn't there because of how we interface to C3. We could post-process that to just returning things starting with 'n' but VSCode does that for us anyway. I don't think this causes any issues but not completely sure.

@kjonescertinia kjonescertinia merged commit ec5a4c8 into main Sep 4, 2024
1 check passed
@kjonescertinia kjonescertinia deleted the 282-enhance-completion-support-of-creator-use branch September 4, 2024 14:24
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.

Enhance completion support of creator use
2 participants