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

Drop-down widgets for extension functions via UnresolvedSymbol #7115

Merged
merged 32 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a097109
Specify visualisation_module when attaching a visualisation
JaroslavTulach Jun 23, 2023
d33c42c
Accept UnresolvedSymbol as a parameter to Meta.get_annotation
JaroslavTulach Jun 23, 2023
ff4af7d
Provide visualisationModule in tests
JaroslavTulach Jun 23, 2023
673c49e
Adjust tests to new parameter of Api.VisualisationConfiguration
JaroslavTulach Jun 23, 2023
ebcb98c
Formatting can compilation fixes
JaroslavTulach Jun 23, 2023
ad953f4
Proper visualisationModule name
JaroslavTulach Jun 24, 2023
47733ff
Merge remote-tracking branch 'origin/develop' into wip/jtulach/Unreso…
JaroslavTulach Jun 24, 2023
ef9ee73
Adding missing EOL at EOF
JaroslavTulach Jun 24, 2023
83b7d45
Generate visualisationModule attribute
JaroslavTulach Jun 24, 2023
06226b7
result of javafmtAll
JaroslavTulach Jun 24, 2023
09254d3
Check request and response includes visualisationModule
JaroslavTulach Jun 26, 2023
236c612
Few more visualisation modules specified in tests
JaroslavTulach Jun 26, 2023
15b9639
cargo in root of the repository compiles
JaroslavTulach Jun 26, 2023
6982bb1
Another test to fix
JaroslavTulach Jun 26, 2023
4274080
Suggestions by Adam
JaroslavTulach Jun 26, 2023
1223fba
Adjusting description to one used in execution_context
JaroslavTulach Jun 26, 2023
8f60565
Use QualifiedName for identification of modules
JaroslavTulach Jun 26, 2023
3ffb6e3
Use format macro to format arg
JaroslavTulach Jun 26, 2023
429001e
Making project field non-pub again
JaroslavTulach Jun 26, 2023
d966407
Use qualified name in the test
JaroslavTulach Jun 26, 2023
b2076bc
Fixing the tests to use QualifiedName as a module
JaroslavTulach Jun 27, 2023
3e031bb
Merging to accommodate visualization rename
JaroslavTulach Jun 27, 2023
58f5d6c
scalafmtAll
JaroslavTulach Jun 27, 2023
6365b25
More of visualizationModule usages
JaroslavTulach Jun 27, 2023
b0a86fb
Need module.to_string_with_main_segment
JaroslavTulach Jun 27, 2023
1042ac9
Documenting the new method parameters
JaroslavTulach Jun 27, 2023
7b27188
visualizationModule is compulsory parameter
JaroslavTulach Jun 27, 2023
8806646
Typo in executed.rs
JaroslavTulach Jun 27, 2023
883b17d
Require Unresolved_Symbol as identification of a method in get_annota…
JaroslavTulach Jun 27, 2023
eba65de
Module to be used to evaluate the arguments
JaroslavTulach Jun 27, 2023
38c486e
Evaluate expression in expressionModule
JaroslavTulach Jun 27, 2023
83b0057
Just call it: method
JaroslavTulach Jun 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ fn test_execution_context() {
};
let positional_arguments_expressions = vec![1, 2, 3].iter().map(|x| x.to_string()).collect();
let visualisation_config = VisualisationConfiguration {
visualisation_module: "Foo.Bar.Baz".to_string(),
execution_context_id: context_id,
expression,
positional_arguments_expressions,
Expand All @@ -453,6 +454,7 @@ fn test_execution_context() {
"definedOnType" : "[Foo.Bar.Baz]",
"name" : "foo"
},
"visualisationModule" : "Foo.Bar.Baz",
"positionalArgumentsExpressions" : ["1", "2", "3"]
}
}),
Expand All @@ -479,6 +481,7 @@ fn test_execution_context() {
};
let positional_arguments_expressions = vec!["foo"].iter().map(|x| x.to_string()).collect();
let visualisation_config = VisualisationConfiguration {
visualisation_module: "Foo.Bar.Baz".to_string(),
execution_context_id: context_id,
expression,
positional_arguments_expressions,
Expand All @@ -495,6 +498,7 @@ fn test_execution_context() {
"definedOnType" : "[Foo.Bar.Baz]",
"name" : "foo"
},
"visualisationModule" : "Foo.Bar.Baz",
"positionalArgumentsExpressions" : ["foo"]
}
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,8 @@ pub type ExpressionId = Uuid;
#[serde(rename_all = "camelCase")]
#[allow(missing_docs)]
pub struct VisualisationConfiguration {
/// FQN of module to use the visualisation from
pub visualisation_module: String,
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
/// An execution context of the visualization.
pub execution_context_id: ContextId,
/// An enso function that will transform the data into expected format.
Expand Down
2 changes: 1 addition & 1 deletion app/gui/src/controller/graph/executed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct Handle {
execution_ctx: model::ExecutionContext,
/// The handle to project controller is necessary, as entering nodes might need to switch
/// modules, and only the project can provide their controllers.
project: model::Project,
pub project: model::Project,
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
/// The publisher allowing sending notification to subscribed entities. Note that its outputs
/// is merged with publishers from the stored graph and execution controllers.
notifier: notification::Publisher<Notification>,
Expand Down
6 changes: 5 additions & 1 deletion app/gui/src/controller/graph/widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl QueryData {
/// Generate visualization metadata for this query.
fn visualization_metadata(&self) -> Metadata {
let arguments: Vec<Code> = vec![
Self::escape_visualization_argument(&self.method_name).into(),
Self::as_unresolved_symbol(&self.method_name).into(),
Self::arg_sequence(&self.arguments).into(),
];

Expand All @@ -410,6 +410,10 @@ impl QueryData {
Ast::raw_text_literal(arg).repr()
}

fn as_unresolved_symbol(arg: &str) -> String {
".".to_string() + arg
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
}

/// Escape a list of strings to be used as a visualization argument. Transforms the strings into
/// an enso expression with a list of string literals.
fn arg_sequence(args: &[ImString]) -> String {
Expand Down
3 changes: 2 additions & 1 deletion app/gui/src/controller/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,8 @@ impl Searcher {
"Standard.Visualization.AI",
"build_ai_prompt",
)?;
let vis = Visualization::new(this.id, vis_ptr, vec![]);
let vis =
Visualization::new("Standard.Visualization.AI".to_string(), this.id, vis_ptr, vec![]);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
let mut result = graph.attach_visualization(vis.clone()).await?;
let next = result.next().await.ok_or(NoAIVisualizationDataReceived)?;
let prompt = std::str::from_utf8(&next)?;
Expand Down
12 changes: 10 additions & 2 deletions app/gui/src/controller/visualization/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ impl Default for Status {
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Desired {
pub module: String,
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
pub visualization_id: VisualizationId,
pub expression_id: ast::Id,
pub metadata: Metadata,
Expand Down Expand Up @@ -285,11 +286,15 @@ impl Manager {
// Early return: requested to remove visualization that was already removed.
return;
};
let prj = self.executed_graph.module_qualified_name(&*self.executed_graph.project);
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
let graph = self.executed_graph.graph();
let module = prj.to_string() + "." + graph.module.name();
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
let current_id = current.as_ref().and_then(|current| current.latest_id());
let new_desired = new_desired.map(|new_desired| Desired {
expression_id: target,
module,
expression_id: target,
visualization_id: current_id.unwrap_or_else(VisualizationId::new_v4),
metadata: new_desired,
metadata: new_desired,
});
self.write_new_desired(target, new_desired)
}
Expand Down Expand Up @@ -332,6 +337,7 @@ impl Manager {
Ok(Visualization {
id: desired.visualization_id,
expression_id: desired.expression_id,
module: desired.module,
method_pointer,
arguments,
})
Expand Down Expand Up @@ -563,6 +569,7 @@ mod tests {
let faux_vis = Visualization {
id: default(),
expression_id: default(),
module: "local.Widgets.Main".to_string(),
method_pointer,
arguments,
};
Expand Down Expand Up @@ -666,6 +673,7 @@ mod tests {
// We don't attach it separately, as Manager identifies visualizations by their
// expression ID rather than visualization ID.
let desired_vis_3 = Desired {
module: "local.Widgets.Main".to_string(),
visualization_id: VisualizationId::from_u128(900),
expression_id: node_id,
metadata: desired_vis_1,
Expand Down
6 changes: 5 additions & 1 deletion app/gui/src/model/execution_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,8 @@ pub struct Visualization {
pub id: VisualizationId,
/// Expression that is to be visualized.
pub expression_id: ExpressionId,
/// module to evaluate visualization in context of
pub module: String,
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
/// A pointer to the enso method that will transform the data into expected format.
pub method_pointer: QualifiedMethodPointer,
/// Enso expressions for positional arguments
Expand All @@ -313,19 +315,21 @@ impl Visualization {
/// Creates a new visualization description. The visualization will get a randomly assigned
/// identifier.
pub fn new(
module: String,
expression_id: ExpressionId,
method_pointer: QualifiedMethodPointer,
arguments: Vec<String>,
) -> Visualization {
let id = VisualizationId::new_v4();
Visualization { id, expression_id, method_pointer, arguments }
Visualization { id, expression_id, module, method_pointer, arguments }
}

/// Creates a `VisualisationConfiguration` that is used in communication with language server.
pub fn config(&self, execution_context_id: Uuid) -> VisualisationConfiguration {
let expression = self.method_pointer.clone().into();
let positional_arguments_expressions = self.arguments.clone();
VisualisationConfiguration {
visualisation_module: self.module.to_owned(),
execution_context_id,
expression,
positional_arguments_expressions,
Expand Down
4 changes: 4 additions & 0 deletions app/gui/src/model/execution_context/synchronized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ pub mod test {
let arguments = vec![];
let vis = Visualization {
id: model::execution_context::VisualizationId::new_v4(),
module: method_pointer.module.to_string(),
expression_id: model::execution_context::ExpressionId::new_v4(),
method_pointer,
arguments,
Expand Down Expand Up @@ -581,6 +582,7 @@ pub mod test {
let arguments = vec!["foo".to_owned()];
let vis = Visualization {
id: model::execution_context::VisualizationId::new_v4(),
module: method_pointer.module.to_string(),
expression_id: model::execution_context::ExpressionId::new_v4(),
method_pointer,
arguments,
Expand Down Expand Up @@ -618,6 +620,7 @@ pub mod test {
let arguments = vec!["bar".to_owned()];
let vis = Visualization {
id: model::execution_context::VisualizationId::new_v4(),
module: method_pointer.module.to_string(),
expression_id: model::execution_context::ExpressionId::new_v4(),
method_pointer,
arguments: arguments.clone(),
Expand All @@ -634,6 +637,7 @@ pub mod test {

let expected_config = language_server::types::VisualisationConfiguration {
execution_context_id: data.context_id,
visualisation_module: MockData::new().module_qualified_name().to_string(),
expression: new_expression.clone().into(),
positional_arguments_expressions: arguments.clone(),
};
Expand Down
9 changes: 8 additions & 1 deletion app/gui/tests/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ async fn ls_text_protocol_test() {
execution_context_id,
expression,
positional_arguments_expressions,
visualisation_module: visualization_module.to_string(),
};
let response =
client.attach_visualisation(&visualisation_id, &expression_id, &visualisation_config);
Expand All @@ -157,6 +158,7 @@ async fn ls_text_protocol_test() {
execution_context_id,
expression,
positional_arguments_expressions,
visualisation_module: visualization_module.to_string(),
};
let response = client.modify_visualisation(&visualisation_id, &visualisation_config).await;
response.expect("Couldn't modify visualisation.");
Expand Down Expand Up @@ -375,7 +377,12 @@ async fn binary_visualization_updates_test_hlp() {
module_qualified_name,
Identifier::from_text("quux").unwrap(),
);
let visualization = Visualization::new(the_node.id(), method_pointer, vec![]);
let visualization = Visualization::new(
method_pointer.module.to_string(),
the_node.id(),
method_pointer,
vec![],
);
let stream = graph_executed.attach_visualization(visualization.clone()).await.unwrap();
info!("Attached the visualization {}", visualization.id);
let mut stream = stream.boxed_local();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ import java.util.UUID
*
* @param executionContextId an execution context of the visualisation
* @param expression an expression that creates a visualisation
* @param visualisationModule the name of a module to execute expression at
*/
case class VisualisationConfiguration(
executionContextId: UUID,
expression: VisualisationExpression
expression: VisualisationExpression,
visualisationModule: String
) extends ToLogString {

/** A qualified module name containing the expression. */
def visualisationModule: String =
expression.module

/** @inheritdoc */
override def toLogString(shouldMask: Boolean): String =
s"VisualisationConfiguration(" +
Expand All @@ -31,8 +29,9 @@ case class VisualisationConfiguration(
/** Convert to corresponding [[Api]] message. */
def toApi: Api.VisualisationConfiguration =
Api.VisualisationConfiguration(
executionContextId = executionContextId,
expression = expression.toApi
executionContextId = executionContextId,
expression = expression.toApi,
visualisationModule = visualisationModule
)

}
Expand All @@ -52,7 +51,8 @@ object VisualisationConfiguration {
): VisualisationConfiguration =
new VisualisationConfiguration(
contextId,
VisualisationExpression.Text(module, expression)
VisualisationExpression.Text(module, expression),
module
)

/** Create a visualisation configuration.
Expand All @@ -65,6 +65,7 @@ object VisualisationConfiguration {
*/
def apply(
contextId: UUID,
module: String,
expression: MethodPointer,
positionalArgumentsExpressions: Vector[String]
): VisualisationConfiguration =
Expand All @@ -73,7 +74,8 @@ object VisualisationConfiguration {
VisualisationExpression.ModuleMethod(
expression,
positionalArgumentsExpressions
)
),
module
)

private object CodecField {
Expand All @@ -99,11 +101,15 @@ object VisualisationConfiguration {
expression <- cursor
.downField(CodecField.Expression)
.as[MethodPointer]
visualisationModule <- cursor
.downField(CodecField.VisualisationModule)
.as[String]
arguments <- cursor
.downField(CodecField.Arguments)
.as[Option[Vector[String]]]
} yield VisualisationConfiguration(
contextId,
visualisationModule,
expression,
arguments.getOrElse(Vector())
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ object ExecutionContextJsonMessages {
"expressionId": $expressionId,
"visualisationConfig": {
"executionContextId": ${configuration.executionContextId},
"visualisationModule": ${configuration.visualisationModule},
"expression": {
"module": ${methodPointer.module},
"definedOnType": ${methodPointer.definedOnType},
Expand All @@ -223,6 +224,7 @@ object ExecutionContextJsonMessages {
"expressionId": $expressionId,
"visualisationConfig": {
"executionContextId": ${configuration.executionContextId},
"visualisationModule": ${methodPointer.module},
"expression": {
"module": ${methodPointer.module},
"definedOnType": ${methodPointer.definedOnType},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class VisualisationOperationsTest extends BaseServerTest {
val visualisationConfig =
VisualisationConfiguration(
contextId,
visualisationModule,
MethodPointer(
visualisationModule,
visualisationModule,
Expand Down Expand Up @@ -120,6 +121,7 @@ class VisualisationOperationsTest extends BaseServerTest {
val visualisationConfig =
VisualisationConfiguration(
contextId,
visualisationModule,
MethodPointer(
visualisationModule,
visualisationModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,18 +618,16 @@ object Runtime {
*/
case class VisualisationConfiguration(
executionContextId: ContextId,
expression: VisualisationExpression
expression: VisualisationExpression,
visualisationModule: String
) extends ToLogString {

/** A qualified module name containing the expression. */
def visualisationModule: String =
expression.module

/** @inheritdoc */
override def toLogString(shouldMask: Boolean): String =
s"VisualisationConfiguration(" +
s"executionContextId=$executionContextId," +
s"expression=${expression.toLogString(shouldMask)})"
s"expression=${expression.toLogString(shouldMask)})" +
s"visualisationModule=${visualisationModule})"
}

/** An operation applied to the suggestion argument. */
Expand Down
Loading