-
Notifications
You must be signed in to change notification settings - Fork 2
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 code completion for chained value factories #11
Conversation
9a2dffa
to
31db1d8
Compare
31db1d8
to
fd499f9
Compare
lsp/src/main/kotlin/org/gradle/declarative/lsp/DeclarativeTextDocumentService.kt
Outdated
Show resolved
Hide resolved
dataClass: DataClass, | ||
analysisSchema: AnalysisSchema | ||
): List<CompletionItem> { | ||
fun indexValueFactories(analysisSchema: AnalysisSchema, type: DataClass, namePrefix: String): Map<FqName, List<LabelAndInsertText>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Given that with a big enough schema this might be an expensive operation, I would suggest finding a way to build the index once (or maybe precompute/memoize some parts of it) and invalidate it on schema changes.
For instance, some precomputed or memoized state could include:
- For each value type, all value factories of that type grouped by the container type.
- For each container type, the set of paths like
layout.settingsDirectory
starting from that type (along with the type oflayout.settingsDirectory
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've addressed this, please take a look.
lsp/src/main/kotlin/org/gradle/declarative/lsp/DeclarativeTextDocumentService.kt
Outdated
Show resolved
Hide resolved
return factoryIndex | ||
} | ||
|
||
val factories = indexValueFactories(analysisSchema, analysisSchema.topLevelReceiverType, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 Currently, in addition to the top-level type, you can use the members of the nested containers. For instance, in
foo {
bar {
baz = qux.quux()
}
}
qux
could be a member of:
bar
's receiverfoo
's receiver- the top-level receiver
We should probably discuss if we want to keep it that way, but if we do, these nested receivers should also contribute the value factory groups to completion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As it works now, qux
will be found regardless which of those receivers it's on and will be proposed as a potential value for properties with the same type as the return type of the quux()
function.
I think the real problem we should think about is that qux.quux()
will be proposed as a potential value for baz
even if qux
comes from a totally unrelated block, which is part of the top-level receiver, but is unrelated to foo
(thus by extension unrelated to bar
and baz
too).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a TODO.
lsp/src/test/kotlin/org/gradle/declarative/lsp/DeclarativeTextDocumentServiceTest.kt
Show resolved
Hide resolved
2bf0a4b
to
6047401
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
No description provided.