Skip to content

Commit 9bcba4e

Browse files
committed
Add runtime services support when remote debugging
1 parent 6f7c609 commit 9bcba4e

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/SynapseLanguageService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.gson.JsonElement;
1818
import com.google.gson.JsonObject;
19+
import org.apache.commons.lang3.StringUtils;
1920
import org.eclipse.lemminx.customservice.ISynapseLanguageService;
2021
import org.eclipse.lemminx.customservice.SynapseLanguageClientAPI;
2122
import org.eclipse.lemminx.customservice.synapse.CodeDiagnosticRequest;
@@ -332,7 +333,8 @@ public CompletableFuture<ExtendedLocation> definition(
332333
@Override
333334
public CompletableFuture<ResourceResponse> availableResources(ResourceParam param) {
334335

335-
ResourceResponse response = resourceFinder.getAvailableResources(projectUri, param.resourceType);
336+
ResourceResponse response = resourceFinder.getAvailableResources(
337+
StringUtils.isNotBlank(param.projectPath) ? param.projectPath : projectUri, param.resourceType);
336338
return CompletableFuture.supplyAsync(() -> response);
337339
}
338340

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/api/generator/OpenAPIProcessor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ public OpenAPIProcessor(final API api) {
8080
* @param isJSON response data type JSON / YAML.
8181
* @return OpenAPI definition as string.
8282
*/
83-
public String getOpenAPISpecification(final boolean isJSON, final int port) {
83+
public String getOpenAPISpecification(final boolean isJSON, final String hostname, final int port) {
8484

8585
final OpenAPI openAPI = new OpenAPI();
8686
addInfoSection(openAPI);
87-
addServersSection(openAPI, port, StringUtils.EMPTY);
87+
addServersSection(openAPI, hostname, port, StringUtils.EMPTY);
8888
// Re-use the previous implementation to get resource details of the API.
8989
final Map<String, Object> dataMap = GenericApiObjectDefinition.getPathMap(api);
9090
Paths paths = new Paths();
@@ -195,7 +195,7 @@ private void updateServersSection(OpenAPI openAPI) {
195195
}
196196
}
197197
} else {
198-
addServersSection(openAPI, SwaggerConstants.DEFAULT_HTTP_PORT, StringUtils.EMPTY);
198+
addServersSection(openAPI, SwaggerConstants.DEFAULT_HOST, SwaggerConstants.DEFAULT_HTTP_PORT, StringUtils.EMPTY);
199199
}
200200
}
201201

@@ -204,7 +204,7 @@ private void updateServersSection(OpenAPI openAPI) {
204204
*
205205
* @param openAPI OpenApi object.
206206
*/
207-
private void addServersSection(OpenAPI openAPI, int port, String projectPath) {
207+
private void addServersSection(OpenAPI openAPI, String hostname, int port, String projectPath) {
208208

209209
String serverVersionPath = api.getContext().startsWith("/") ? "" : "/";
210210
if (StringUtils.isNotBlank(projectPath)){
@@ -227,6 +227,9 @@ private void addServersSection(OpenAPI openAPI, int port, String projectPath) {
227227
if (StringUtils.isNotBlank(api.getHostname()) && !"-1".equals(api.getPort())) {
228228
httpHost = api.getHostname() + ":" + port;
229229
httpsHost = api.getHostname() + ":" + (SwaggerConstants.DEFAULT_HTTPS_PORT + offset);
230+
} else if (StringUtils.isNotBlank(hostname)) {
231+
httpHost = hostname + ":" + port;
232+
httpsHost = hostname + ":" + (SwaggerConstants.DEFAULT_HTTPS_PORT + offset);
230233
} else {
231234
httpHost = SwaggerConstants.DEFAULT_HOST + ":" + port;
232235
httpsHost = SwaggerConstants.DEFAULT_HOST + ":" + (SwaggerConstants.DEFAULT_HTTPS_PORT + offset);
@@ -354,7 +357,8 @@ private void addDefaultRequestBody(Operation operation, Map.Entry methodEntry) {
354357
* @param isJSONOut output swagger data type JSON / YAML.
355358
* @return updated swagger definition as string.
356359
*/
357-
public String getUpdatedSwaggerFromApi(String existingSwagger, boolean isJSONIn, boolean isJSONOut, int port, String projectPath)
360+
public String getUpdatedSwaggerFromApi(String existingSwagger, boolean isJSONIn, boolean isJSONOut,
361+
String hostname, int port, String projectPath)
358362
throws APIGenException {
359363

360364
if (api == null) {
@@ -506,7 +510,7 @@ public String getUpdatedSwaggerFromApi(String existingSwagger, boolean isJSONIn,
506510
// Adding the new path map
507511
openAPI.setPaths(newPaths);
508512
updateInfoSection(openAPI);
509-
addServersSection(openAPI, port, projectPath);
513+
addServersSection(openAPI, hostname, port, projectPath);
510514

511515
try {
512516
if (isJSONOut) {

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/api/generator/RestApiAdmin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,10 @@ public GenerateSwaggerResponse generateSwaggerFromAPI(GenerateSwaggerParam param
352352
File existingSwaggerFile = new File(param.swaggerPath);
353353
if (existingSwaggerFile.exists()) {
354354
return generateUpdatedSwaggerFromAPI(existingSwaggerFile, param.isJsonIn, param.isJsonOut,
355-
param.apiPath, param.port, param.projectPath);
355+
param.apiPath, param.hostname, param.port, param.projectPath);
356356
}
357357
}
358-
return generateSwaggerFromSynapseAPIByFormat(param.apiPath, param.isJsonOut, param.port);
358+
return generateSwaggerFromSynapseAPIByFormat(param.apiPath, param.isJsonOut, param.hostname, param.port);
359359
}
360360

361361
/**
@@ -386,15 +386,15 @@ public Boolean isEqualSwaggers(IsEqualSwaggersParam param) {
386386
* @param apiPath API file path
387387
* @return generated API
388388
*/
389-
public GenerateSwaggerResponse generateSwaggerFromSynapseAPIByFormat(String apiPath, boolean isJSON, int port) {
389+
public GenerateSwaggerResponse generateSwaggerFromSynapseAPIByFormat(String apiPath, boolean isJSON, String hostname, int port) {
390390

391391
GenerateSwaggerResponse response = new GenerateSwaggerResponse();
392392
try {
393393
File apiFile = new File(apiPath);
394394
DOMDocument domDocument = Utils.getDOMDocument(apiFile);
395395
APIFactory factory = new APIFactory();
396396
API api = (API) factory.create(domDocument.getDocumentElement());
397-
String generatedSwagger = generateSwaggerFromSynapseAPIByFormat(api, isJSON, port);
397+
String generatedSwagger = generateSwaggerFromSynapseAPIByFormat(api, isJSON, hostname, port);
398398
response.setSwagger(generatedSwagger);
399399
} catch (IOException e) {
400400
LOGGER.log(Level.SEVERE, "Error occurred while reading the existing API file.", e);
@@ -410,14 +410,14 @@ public GenerateSwaggerResponse generateSwaggerFromSynapseAPIByFormat(String apiP
410410
* @param isJSON generate Swagger in YAML / JSON format.
411411
* @return generated swagger.
412412
*/
413-
public String generateSwaggerFromSynapseAPIByFormat(API api, boolean isJSON, int port) {
413+
public String generateSwaggerFromSynapseAPIByFormat(API api, boolean isJSON, String hostname, int port) {
414414

415-
return new OpenAPIProcessor(api).getOpenAPISpecification(isJSON, port);
415+
return new OpenAPIProcessor(api).getOpenAPISpecification(isJSON, hostname, port);
416416
}
417417

418418
private GenerateSwaggerResponse generateUpdatedSwaggerFromAPI(File existingSwaggerFile, boolean isJSONIn,
419-
boolean isJSONOut, String apiPath, int port,
420-
String projectPath) {
419+
boolean isJSONOut, String apiPath, String hostname,
420+
int port, String projectPath) {
421421

422422
GenerateSwaggerResponse response = new GenerateSwaggerResponse();
423423
API api;
@@ -434,7 +434,7 @@ private GenerateSwaggerResponse generateUpdatedSwaggerFromAPI(File existingSwagg
434434
try {
435435
String swaggerContent = Utils.readFile(existingSwaggerFile);
436436
String generatedSwagger = generateUpdatedSwaggerFromAPI(swaggerContent, isJSONIn, isJSONOut, api,
437-
port, projectPath);
437+
hostname, port, projectPath);
438438
response.setSwagger(generatedSwagger);
439439
} catch (IOException e) {
440440
LOGGER.log(Level.SEVERE, "Error occurred while reading the existing Swagger file.", e);
@@ -457,10 +457,10 @@ private GenerateSwaggerResponse generateUpdatedSwaggerFromAPI(File existingSwagg
457457
* @throws APIGenException Error occurred while generating the updated definition.
458458
*/
459459
public String generateUpdatedSwaggerFromAPI(String existingSwagger, boolean isJSONIn, boolean isJSONOut, API api,
460-
int port, String projectPath)
460+
String hostname, int port, String projectPath)
461461
throws APIGenException {
462462

463463
OpenAPIProcessor openAPIProcessor = new OpenAPIProcessor(api);
464-
return openAPIProcessor.getUpdatedSwaggerFromApi(existingSwagger, isJSONIn, isJSONOut, port, projectPath);
464+
return openAPIProcessor.getUpdatedSwaggerFromApi(existingSwagger, isJSONIn, isJSONOut, hostname, port, projectPath);
465465
}
466466
}

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/api/generator/pojo/GenerateSwaggerParam.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class GenerateSwaggerParam {
2222
public String swaggerPath;
2323
public boolean isJsonIn;
2424
public boolean isJsonOut;
25+
public String hostname = SwaggerConstants.DEFAULT_HOST;
2526
public int port = SwaggerConstants.DEFAULT_HTTP_PORT;
2627
public String projectPath;
2728
}

org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/customservice/synapse/resourceFinder/pojo/ResourceParam.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414

1515
package org.eclipse.lemminx.customservice.synapse.resourceFinder.pojo;
1616

17+
import org.apache.commons.lang3.StringUtils;
1718
import org.eclipse.lsp4j.jsonrpc.messages.Either;
1819

1920
import java.util.List;
2021

2122
public class ResourceParam {
2223

2324
public Either<String, List<RequestedResource>> resourceType;
25+
public String projectPath = StringUtils.EMPTY;
2426
}

0 commit comments

Comments
 (0)