-
Notifications
You must be signed in to change notification settings - Fork 758
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43641 from nipunayf/dump-ls-apis
Provide a Ballerina command to display the API specifications of all active LS APIs
- Loading branch information
Showing
25 changed files
with
2,462 additions
and
48 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
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
88 changes: 88 additions & 0 deletions
88
...ules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.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,88 @@ | ||
/* | ||
* 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 org.ballerinalang.langserver.cmd; | ||
|
||
import com.google.gson.JsonObject; | ||
import io.ballerina.cli.BLauncherCmd; | ||
import io.ballerina.cli.launcher.LauncherUtils; | ||
import org.ballerinalang.langserver.launchers.stdio.Main; | ||
import picocli.CommandLine; | ||
|
||
import java.io.PrintStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
/** | ||
* Command to generate API specifications for the active LS APIs. | ||
* | ||
* @since 2201.12.0 | ||
*/ | ||
@CommandLine.Command(name = "language-server-spec", description = "Generate specifications for the LS APIs") | ||
public class LangServerSpecCmd implements BLauncherCmd { | ||
|
||
private static final String CMD_NAME = "language-server-spec"; | ||
private static final String FILE_NAME = "language-server-spec.json"; | ||
private static final String BALLERINA_HOME; | ||
private final PrintStream outputStream; | ||
|
||
static { | ||
BALLERINA_HOME = System.getProperty("ballerina.home"); | ||
} | ||
|
||
public LangServerSpecCmd() { | ||
outputStream = System.out; | ||
} | ||
|
||
@CommandLine.Option(names = {"-h", "--help"}, hidden = true) | ||
private boolean helpFlag; | ||
|
||
@Override | ||
public void execute() { | ||
try { | ||
System.setProperty("ballerina.home", BALLERINA_HOME); | ||
List<JsonObject> output = Main.generateApiDoc(); | ||
String jsonString = output.toString(); | ||
Files.writeString(Paths.get(FILE_NAME), jsonString); | ||
outputStream.println("LS API specifications are successfully dumped to " + FILE_NAME); | ||
} catch (Throwable e) { | ||
throw LauncherUtils.createLauncherException("Could not generate LS API specifications"); | ||
} | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return CMD_NAME; | ||
} | ||
|
||
@Override | ||
public void printLongDesc(StringBuilder out) { | ||
|
||
} | ||
|
||
@Override | ||
public void printUsage(StringBuilder out) { | ||
|
||
} | ||
|
||
@Override | ||
public void setParentCmdParser(CommandLine parentCmdParser) { | ||
|
||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...modules/langserver-cli/src/main/resources/META-INF/services/io.ballerina.cli.BLauncherCmd
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
org.ballerinalang.langserver.cmd.LangServerStartCmd | ||
org.ballerinalang.langserver.cmd.LangServerSpecCmd |
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
Oops, something went wrong.