Skip to content

Commit

Permalink
update: language-server api
Browse files Browse the repository at this point in the history
  • Loading branch information
4e6 committed Feb 6, 2025
1 parent 149b14c commit cd7ae28
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
22 changes: 21 additions & 1 deletion docs/language-server/protocol-language-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ transport formats, please look [here](./protocol-architecture).
- [`ProfilingInfo`](#profilinginfo)
- [`ExecutionEnvironment`](#executionenvironment)
- [`ExpressionConfig`](#expressionConfig)
- [`ExpressionType`](#expressiontype)
- [`ExpressionUpdate`](#expressionupdate)
- [`ExpressionUpdatePayload`](#expressionupdatepayload)
- [`VisualizationConfiguration`](#visualizationconfiguration)
Expand Down Expand Up @@ -360,6 +361,24 @@ interface ExpressionConfig {
}
```

### `ExpressionType`

A type of the expression.

```typescript
interface ExpressionType {
/**
* The public type of the expression. The array with multiple values
* represents intersection type.
*/
visibleType: string[];
/**
* The list of types this expression can be converted to.
*/
hiddenTypes: string[];
}
```

### `ExpressionUpdate`

An update about the computed expression.
Expand All @@ -368,14 +387,15 @@ An update about the computed expression.
interface ExpressionUpdate {
/** The id of updated expression. */
expressionId: ExpressionId;
/** The updated type of the expression.
/** @deprecated The updated type of the expression.
*
* Possible values:
* - empty array indicates no type information for this expression
* - array with a single value contains a value of this expression
* - array with multiple values represents an intersetion type
*/
type: string[];
expressionType?: ExpressionType;
/** The updated method call info. */
methodCall?: MethodCall;
/** Profiling information about the expression. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ final class ContextEventsListener(
val computedExpressions = expressionUpdates.map { update =>
ContextRegistryProtocol.ExpressionUpdate(
update.expressionId,
update.expressionTypes.getOrElse(Vector()),
update.expressionType.map(_.visibleType).getOrElse(Vector()),
update.expressionType.map(toProtocolExpressionType),
update.methodCall.map(toProtocolMethodCall),
update.profilingInfo.map(toProtocolProfilingInfo),
update.fromCache,
Expand Down Expand Up @@ -241,6 +242,20 @@ final class ContextEventsListener(
.Panic(message, trace)
}

/** Convert the runtime expression type to the context registry protocol
* representation.
*
* @param expressionType the runtime expression type
* @return the context registry protocol expression type
*/
private def toProtocolExpressionType(
expressionType: Api.ExpressionType
): ContextRegistryProtocol.ExpressionType =
ContextRegistryProtocol.ExpressionType(
expressionType.visibleType,
expressionType.conversionType
)

/** Convert the runtime warnings to the context registry protocol
* representation
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,21 @@ object ContextRegistryProtocol {
updates: Vector[ExpressionUpdate]
)

/** A type of the expression
*
* @param visibleType the public type of the expression
* @param hiddenTypes the available conversions
*/
case class ExpressionType(
visibleType: Vector[String],
hiddenTypes: Vector[String]
)

/** An update about computed expression.
*
* @param expressionId the id of updated expression
* @param type the updated type of expression
* @param expressionType the full expression type of the expression
* @param methodCall the updated method call
* @param profilingInfo profiling information about the expression
* @param fromCache whether the expression's value came from the cache
Expand All @@ -185,6 +196,7 @@ object ContextRegistryProtocol {
case class ExpressionUpdate(
expressionId: UUID,
`type`: Vector[String],
expressionType: Option[ExpressionType],
methodCall: Option[MethodCall],
profilingInfo: Vector[ProfilingInfo],
fromCache: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ class ContextEventsListenerSpec
Set(
Api.ExpressionUpdate(
Suggestions.method.externalId.get,
Some(Vector(Suggestions.method.returnType)),
Some(
Api.ExpressionType(
Vector(Suggestions.method.returnType),
Vector(Suggestions.method.selfType)
)
),
Some(methodCall),
Vector(),
false,
Expand All @@ -87,6 +92,12 @@ class ContextEventsListenerSpec
ContextRegistryProtocol.ExpressionUpdate(
Suggestions.method.externalId.get,
Vector(Suggestions.method.returnType),
Some(
ContextRegistryProtocol.ExpressionType(
Vector(Suggestions.method.returnType),
Vector(Suggestions.method.selfType)
)
),
Some(toProtocolMethodCall(methodCall)),
Vector(),
false,
Expand Down Expand Up @@ -137,6 +148,7 @@ class ContextEventsListenerSpec
Suggestions.method.externalId.get,
Vector(),
None,
None,
Vector(),
false,
ContextRegistryProtocol.ExpressionUpdate.Payload
Expand Down Expand Up @@ -175,6 +187,7 @@ class ContextEventsListenerSpec
Suggestions.method.externalId.get,
Vector(),
None,
None,
Vector(),
false,
ContextRegistryProtocol.ExpressionUpdate.Payload
Expand Down Expand Up @@ -231,6 +244,7 @@ class ContextEventsListenerSpec
Suggestions.method.externalId.get,
Vector(),
None,
None,
Vector(),
false,
ContextRegistryProtocol.ExpressionUpdate.Payload
Expand All @@ -240,6 +254,7 @@ class ContextEventsListenerSpec
Suggestions.local.externalId.get,
Vector(),
None,
None,
Vector(),
false,
ContextRegistryProtocol.ExpressionUpdate.Payload
Expand Down

0 comments on commit cd7ae28

Please sign in to comment.