Skip to content

Commit

Permalink
Put all reexports of given entry in Suggestion Database (#9454)
Browse files Browse the repository at this point in the history
close #9351

Changelog:
- update: deprecate the `reexport` suggestion field
- add: `reexports` suggestion field containing the list of modules re-exporting this symbol
- update: exports logic to gather all the symbols exported from a given module
  • Loading branch information
4e6 authored Mar 26, 2024
1 parent 09a6ab7 commit fb0559e
Show file tree
Hide file tree
Showing 18 changed files with 326 additions and 354 deletions.
32 changes: 28 additions & 4 deletions docs/language-server/protocol-language-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,14 @@ interface Module {
/** The documentation string. */
documentation?: string;

/** The fully qualified module name re-exporting this module. */
/** The fully qualified module name re-exporting this module.
*
* @deprecated use reexports field instead
*/
reexport?: string;

/** The list of fully qualified module names re-exporting this module. */
reexports: string[];
}

interface Type {
Expand All @@ -520,9 +526,15 @@ interface Type {
/** Qualified name of the parent type. */
parentType?: string;

/** The fully qualified module name re-exporting this type. */
/** The fully qualified module name re-exporting this type.
*
* @deprecated use reexports field instead
*/
reexport?: string;

/** The list of fully qualified module names re-exporting this type. */
reexports: string[];

/** The documentation string. */
documentation?: string;
}
Expand All @@ -543,9 +555,15 @@ interface Constructor {
/** The type of the constructor. */
returnType: string;

/** The fully qualified module name re-exporting this constructor. */
/** The fully qualified module name re-exporting this constructor.
*
* @deprecated use reexports field instead
*/
reexport?: string;

/** The list of fully qualified module names re-exporting this constructor. */
reexports: string[];

/** The documentation string. */
documentation?: string;

Expand Down Expand Up @@ -575,9 +593,15 @@ interface Method {
/** The flag indicating whether this method is static or instance. */
isStatic: boolean;

/** The fully qualified module name re-exporting this method. */
/** The fully qualified module name re-exporting this method.
*
* @deprecated use reexports field instead
*/
reexport?: string;

/** The list of fully qualified module names re-exporting this method. */
reexports: string[];

/** The documentation string. */
documentation?: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ object SearchProtocol {
val Documentation = "documentation"

val Reexport = "reexport"

val Reexports = "reexports"
}

private object CodecType {
Expand Down Expand Up @@ -64,15 +66,21 @@ object SearchProtocol {
case module: Suggestion.Module =>
Encoder[Suggestion.Module]
.apply(module)
.deepMerge(Json.obj(CodecField.Type -> SuggestionType.Module.asJson))
.deepMerge(
Json.obj(
CodecField.Type -> SuggestionType.Module.asJson,
CodecField.Reexport -> module.reexports.headOption.asJson
)
)

case tpe: Suggestion.Type =>
Encoder[Suggestion.Type]
.apply(tpe)
.deepMerge(
Json.obj(
CodecField.Type -> SuggestionType.Type.asJson,
CodecField.ReturnType -> Json.Null
CodecField.ReturnType -> Json.Null,
CodecField.Reexport -> tpe.reexports.headOption.asJson
)
)
.dropNullValues
Expand All @@ -81,31 +89,43 @@ object SearchProtocol {
Encoder[Suggestion.Constructor]
.apply(constructor)
.deepMerge(
Json.obj(CodecField.Type -> SuggestionType.Constructor.asJson)
Json.obj(
CodecField.Type -> SuggestionType.Constructor.asJson,
CodecField.Reexport -> constructor.reexports.headOption.asJson
)
)
.dropNullValues

case conversion: Suggestion.Conversion =>
Encoder[Suggestion.DefinedMethod]
.apply(conversionToMethod(conversion))
.deepMerge(
Json.obj(CodecField.Type -> SuggestionType.Method.asJson)
Json.obj(
CodecField.Type -> SuggestionType.Method.asJson,
CodecField.Reexport -> conversion.reexports.headOption.asJson
)
)
.dropNullValues

case getter: Suggestion.Getter =>
Encoder[Suggestion.DefinedMethod]
.apply(getterToMethod(getter))
.deepMerge(
Json.obj(CodecField.Type -> SuggestionType.Method.asJson)
Json.obj(
CodecField.Type -> SuggestionType.Method.asJson,
CodecField.Reexport -> getter.reexports.headOption.asJson
)
)
.dropNullValues

case method: Suggestion.DefinedMethod =>
Encoder[Suggestion.DefinedMethod]
.apply(method)
.deepMerge(
Json.obj(CodecField.Type -> SuggestionType.Method.asJson)
Json.obj(
CodecField.Type -> SuggestionType.Method.asJson,
CodecField.Reexport -> method.reexports.headOption.asJson
)
)
.dropNullValues

Expand Down Expand Up @@ -137,7 +157,7 @@ object SearchProtocol {
conversion.isStatic,
conversion.documentation,
conversion.annotations,
conversion.reexport
conversion.reexports
)

private def getterToMethod(
Expand All @@ -153,7 +173,7 @@ object SearchProtocol {
getter.isStatic,
getter.documentation,
getter.annotations,
getter.reexport
getter.reexports
)

private val suggestionTypeDecoder: Decoder[Suggestion.Type] =
Expand All @@ -171,7 +191,7 @@ object SearchProtocol {
documentation <- cursor
.downField(CodecField.Documentation)
.as[Option[String]]
reexport <- cursor.downField(CodecField.Reexport).as[Option[String]]
reexports <- cursor.downField(CodecField.Reexports).as[Set[String]]
} yield {
val returnType =
QualifiedName.fromString(module).createChild(name).toString
Expand All @@ -183,7 +203,7 @@ object SearchProtocol {
returnType,
parentType,
documentation,
reexport
reexports
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ final class SuggestionsHandler(
for {
actionResults <- suggestionsRepo.applyActions(msg.actions)
treeResults <- suggestionsRepo.applyTree(msg.updates.toVector)
exportResults <- suggestionsRepo.applyExports(msg.exports)
exportResults <- suggestionsRepo.getExportedSymbols(msg.exports)
version <- suggestionsRepo.currentVersion
} yield {
val actionUpdates = actionResults.flatMap {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ class SuggestionsHandlerSpec
DeliverToJsonController(
clientId,
SearchProtocol.SuggestionsDatabaseUpdateNotification(
updates1.size.toLong + 1,
updates1.size.toLong,
updates2
)
)
Expand Down Expand Up @@ -690,7 +690,7 @@ class SuggestionsHandlerSpec
DeliverToJsonController(
clientId,
SearchProtocol.SuggestionsDatabaseUpdateNotification(
updates1.size.toLong + 2,
updates1.size.toLong,
updates3
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class SuggestionsHandlerEventsTest
"tagValues" : null
}
],
"parentType" : "Any"
"parentType" : "Any",
"reexports" : []
}
}
],
Expand Down Expand Up @@ -117,7 +118,8 @@ class SuggestionsHandlerEventsTest
],
"returnType" : "MyAtom",
"documentation" : " PRIVATE\n\n A key-value store. This type assumes all keys are pairwise comparable,\n using the `<`, `>` and `==` operators.\n\n Arguments:\n - one: The first.\n - two_three: The *second*.\n\n ? Info\n Here is a thing.",
"annotations" : ["a"]
"annotations" : ["a"],
"reexports" : []
}
}
],
Expand Down Expand Up @@ -161,7 +163,8 @@ class SuggestionsHandlerEventsTest
"selfType" : "MyType",
"returnType" : "Any",
"isStatic" : false,
"annotations" : [ ]
"annotations" : [ ],
"reexports" : [ ]
}
}
],
Expand Down Expand Up @@ -232,7 +235,8 @@ class SuggestionsHandlerEventsTest
"returnType" : "Number",
"isStatic" : false,
"documentation" : "Lovely",
"annotations" : ["foo"]
"annotations" : ["foo"],
"reexports" : []
}
}
],
Expand Down Expand Up @@ -578,7 +582,7 @@ class SuggestionsHandlerEventsTest
}
}
],
"currentVersion" : 9
"currentVersion" : 8
}
}
""")
Expand Down Expand Up @@ -625,7 +629,7 @@ class SuggestionsHandlerEventsTest
"id" : 6
}
],
"currentVersion" : 9
"currentVersion" : 8
}
}
""")
Expand Down
Loading

0 comments on commit fb0559e

Please sign in to comment.