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

Add New Service Designer APIs #528

Merged
merged 28 commits into from
Jan 16, 2025
Merged

Add New Service Designer APIs #528

merged 28 commits into from
Jan 16, 2025

Conversation

TharmiganK
Copy link
Contributor

Purpose

$Subject

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email [email protected] to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to [email protected] and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.


public record MetaData(String label, String description, String groupName, int groupNo) {
public record MetaData(String label, String description) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public record MetaData(String label, String description) {
public record Metadata(String label, String description) {

public record CommonSourceResponse(Map<String, List<TextEdit>> textEdits, String errorMsg, String stacktrace) {

public CommonSourceResponse() {
this(Map.of(), null, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the AbstractFlowModelResponse, can we isolate the error handling logic in the super class?

Comment on lines +126 to +130
StringBuilder sb = new StringBuilder();
for (String errorMessage : errorMessages) {
sb.append(DiagnosticSeverity.ERROR).append(": ").append(errorMessage).append(System.lineSeparator());
}
throw new BallerinaOpenApiException(sb.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
StringBuilder sb = new StringBuilder();
for (String errorMessage : errorMessages) {
sb.append(DiagnosticSeverity.ERROR).append(": ").append(errorMessage).append(System.lineSeparator());
}
throw new BallerinaOpenApiException(sb.toString());
String errorMessage = String.join(System.lineSeparator(), errorMessages);
throw new BallerinaOpenApiException(DiagnosticSeverity.ERROR + ": " + errorMessage);

Comment on lines +348 to +363
private String getDefaultRecordValue(RecordTypeSymbol recordTypeSymbol) {
StringBuilder sb = new StringBuilder();
sb.append(OPEN_BRACE);
Map<String, RecordFieldSymbol> fieldDescriptors = recordTypeSymbol.fieldDescriptors();
for (Map.Entry<String, RecordFieldSymbol> fieldDescriptor : fieldDescriptors.entrySet()) {
String key = fieldDescriptor.getKey();
if (key.contains("status") || key.contains("mediaType") || key.contains("headers")) {
continue;
}
sb.append(key).append(COLON).append(SPACE)
.append(getDefaultValue(fieldDescriptor.getValue().typeDescriptor())).append(COMMA)
.append(SPACE);
}
sb.append(DEFAULT_HTTP_RESPONSE_VALUE).append(CLOSE_BRACE);
return sb.toString();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this method instead of directly calling RecordUtil.getFillAllRecordFieldInsertText

Comment on lines +160 to +163
Package currentPackage = project.currentPackage();
Module module = currentPackage.module(ModuleName.from(currentPackage.packageName()));
ModuleId moduleId = module.moduleId();
SemanticModel semanticModel = currentPackage.getCompilation().getSemanticModel(moduleId);
Copy link
Contributor

Choose a reason for hiding this comment

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

We can get the semantic model directly from the workspace manager using this.workspacemanager.semanticModel()

Comment on lines +222 to +223
String importText = String.format("%simport %s/%s;%s", System.lineSeparator(),
listener.getOrgName(), listener.getModuleName(), System.lineSeparator());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
String importText = String.format("%simport %s/%s;%s", System.lineSeparator(),
listener.getOrgName(), listener.getModuleName(), System.lineSeparator());
String importText = String.format("%nimport %s/%s;%n", listener.getOrgName(), listener.getModuleName());


public void addValue(String value) {
if (Objects.isNull(this.values)) {
this.values = List.of(value);
Copy link
Contributor

Choose a reason for hiding this comment

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

The list is immutable, and and you cannot call addValue afterwards.

TextEdit serviceEdit = new TextEdit(Utils.toRange(lineRange.endLine()),
System.lineSeparator() + serviceDeclaration);
if (!importExists(node, service.getOrgName(), service.getModuleName())) {
String importText = String.format("%simport %s/%s;%s", System.lineSeparator(), service.getOrgName(),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this to a util method since there is another usage?

Comment on lines +380 to +382
if (document.isEmpty()) {
return new CommonSourceResponse();
}
Copy link
Contributor

@nipunayf nipunayf Jan 12, 2025

Choose a reason for hiding this comment

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

When the API attempts to add a resource to the service but finds a missing document, this indicates a program error. The error should be sent to the front end for debugging, and an exception should be thrown.

return new CommonSourceResponse();
}
NonTerminalNode parentService = functionDefinitionNode.parent();
if (!(parentService.kind().equals(SyntaxKind.SERVICE_DECLARATION))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!(parentService.kind().equals(SyntaxKind.SERVICE_DECLARATION))) {
if (parentService.kind() != SyntaxKind.SERVICE_DECLARATION) {

@KavinduZoysa
Copy link
Contributor

@TharmiganK, Let's fix the comments in a separate PR.

@KavinduZoysa KavinduZoysa merged commit 23e74ee into main Jan 16, 2025
7 checks passed
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.

4 participants