-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'flow_model' of https://github.com/ballerina-platform/ba…
…llerina-dev-tools into open-api-support
- Loading branch information
Showing
28 changed files
with
1,605 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,4 +244,5 @@ public static String getVariableName(Node node) { | |
} | ||
return node.toString().strip(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,7 @@ public enum Kind { | |
BODY, | ||
NEW_DATA, | ||
UPDATE_DATA, | ||
XML_PAYLOAD, | ||
STOP, | ||
FOREACH, | ||
DATA_MAPPER, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...erator-core/src/main/java/io/ballerina/flowmodelgenerator/core/model/node/XMLPayload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.flowmodelgenerator.core.model.node; | ||
|
||
import io.ballerina.flowmodelgenerator.core.model.FlowNode; | ||
import io.ballerina.flowmodelgenerator.core.model.NodeBuilder; | ||
import io.ballerina.flowmodelgenerator.core.model.Property; | ||
import io.ballerina.flowmodelgenerator.core.model.SourceBuilder; | ||
import org.eclipse.lsp4j.TextEdit; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
/** | ||
* Represents the properties of a xml payload node. | ||
* | ||
* @since 1.4.0 | ||
*/ | ||
public class XMLPayload extends NodeBuilder { | ||
|
||
public static final String LABEL = "XML Payload"; | ||
public static final String DESCRIPTION = LABEL; | ||
public static final String XML_PAYLOAD_DOC = "Create new XML payload"; | ||
private static final String DUMMY_XML_PAYLOAD = "xml `<dummy>Dummy XML value</dummy>`"; | ||
|
||
@Override | ||
public void setConcreteConstData() { | ||
metadata().label(LABEL); | ||
codedata().node(FlowNode.Kind.XML_PAYLOAD); | ||
} | ||
|
||
@Override | ||
public void setConcreteTemplateData(TemplateContext context) { | ||
properties().xmlPayload(null) | ||
.expression(DUMMY_XML_PAYLOAD, XML_PAYLOAD_DOC); | ||
} | ||
|
||
@Override | ||
public Map<Path, List<TextEdit>> toSource(SourceBuilder sourceBuilder) { | ||
sourceBuilder.newVariable(); | ||
|
||
Optional<Property> exprProperty = sourceBuilder.flowNode.getProperty(Property.EXPRESSION_KEY); | ||
exprProperty.ifPresent(value -> sourceBuilder.token().expression(value).endOfStatement()); | ||
|
||
return sourceBuilder.textEdit(false).build(); | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...sion/src/main/java/io/ballerina/flowmodelgenerator/extension/ExpressionEditorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com) | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
|
||
package io.ballerina.flowmodelgenerator.extension; | ||
|
||
import io.ballerina.flowmodelgenerator.extension.request.ExpressionEditorCompletionRequest; | ||
import io.ballerina.projects.Document; | ||
import io.ballerina.tools.text.TextDocument; | ||
import io.ballerina.tools.text.TextDocumentChange; | ||
import io.ballerina.tools.text.TextEdit; | ||
import io.ballerina.tools.text.TextRange; | ||
import org.ballerinalang.annotation.JavaSPIService; | ||
import org.ballerinalang.langserver.commons.service.spi.ExtendedLanguageServerService; | ||
import org.ballerinalang.langserver.commons.workspace.WorkspaceManager; | ||
import org.eclipse.lsp4j.CompletionItem; | ||
import org.eclipse.lsp4j.CompletionList; | ||
import org.eclipse.lsp4j.CompletionParams; | ||
import org.eclipse.lsp4j.Position; | ||
import org.eclipse.lsp4j.TextDocumentIdentifier; | ||
import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonRequest; | ||
import org.eclipse.lsp4j.jsonrpc.services.JsonSegment; | ||
import org.eclipse.lsp4j.services.LanguageServer; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
@JavaSPIService("org.ballerinalang.langserver.commons.service.spi.ExtendedLanguageServerService") | ||
@JsonSegment("expressionEditor") | ||
public class ExpressionEditorService implements ExtendedLanguageServerService { | ||
|
||
private WorkspaceManager workspaceManager; | ||
private LanguageServer langServer; | ||
|
||
@Override | ||
public void init(LanguageServer langServer, WorkspaceManager workspaceManager) { | ||
this.workspaceManager = workspaceManager; | ||
this.langServer = langServer; | ||
} | ||
|
||
@Override | ||
public Class<?> getRemoteInterface() { | ||
return null; | ||
} | ||
|
||
@JsonRequest | ||
public CompletableFuture<Either<List<CompletionItem>, CompletionList>> completion( | ||
ExpressionEditorCompletionRequest request) { | ||
return CompletableFuture.supplyAsync(() -> { | ||
try { | ||
// Load the project | ||
Path filePath = Path.of(request.filePath()); | ||
this.workspaceManager.loadProject(filePath); | ||
Path projectPath = this.workspaceManager.projectRoot(filePath); | ||
|
||
// Create a temporary directory and load the project | ||
ProjectCacheManager projectCacheManager = new ProjectCacheManager(projectPath, filePath); | ||
projectCacheManager.createTempDirectory(); | ||
Path destination = projectCacheManager.getDestination(); | ||
this.workspaceManager.loadProject(destination); | ||
|
||
// Get the document | ||
Optional<Document> document = this.workspaceManager.document(destination); | ||
if (document.isEmpty()) { | ||
return Either.forLeft(List.of()); | ||
} | ||
TextDocument textDocument = document.get().textDocument(); | ||
|
||
// Determine the cursor position | ||
int textPosition = textDocument.textPositionFrom(request.startLine()); | ||
String statement = String.format("_ = %s;%n", request.expression()); | ||
TextEdit textEdit = TextEdit.from(TextRange.from(textPosition, 0), statement); | ||
TextDocument newTextDocument = | ||
textDocument.apply(TextDocumentChange.from(List.of(textEdit).toArray(new TextEdit[0]))); | ||
projectCacheManager.writeContent(newTextDocument); | ||
document.get().modify() | ||
.withContent(String.join(System.lineSeparator(), newTextDocument.textLines())) | ||
.apply(); | ||
|
||
// Generate the completion params | ||
Position position = | ||
new Position(request.startLine().line(), request.startLine().offset() + 4 + request.offset()); | ||
TextDocumentIdentifier identifier = new TextDocumentIdentifier(destination.toUri().toString()); | ||
CompletionParams params = new CompletionParams(identifier, position, request.context()); | ||
|
||
// Get the completions | ||
CompletableFuture<Either<List<CompletionItem>, CompletionList>> completableFuture = | ||
langServer.getTextDocumentService().completion(params); | ||
Either<List<CompletionItem>, CompletionList> completions = completableFuture.join(); | ||
projectCacheManager.deleteCache(); | ||
return completions; | ||
} catch (Throwable e) { | ||
return Either.forLeft(List.of()); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.