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

Provide a Ballerina command to display the API specifications of all active LS APIs #43641

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -53,6 +53,7 @@ public final class Constants {
public static final String UPDATE_COMMAND = "update";
public static final String PROFILE_COMMAND = "profile";
public static final String START_LANG_SERVER_COMMAND = "start-language-server";
public static final String LANG_SERVER_SPEC = "language-server-spec";
public static final String START_DEBUG_ADAPTER_COMMAND = "start-debugger-adapter";
public static final String HELP_COMMAND = "help";
public static final String HOME_COMMAND = "home";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import static io.ballerina.cli.cmd.Constants.HELP_SHORT_OPTION;
import static io.ballerina.cli.cmd.Constants.HOME_COMMAND;
import static io.ballerina.cli.cmd.Constants.INIT_COMMAND;
import static io.ballerina.cli.cmd.Constants.LANG_SERVER_SPEC;
import static io.ballerina.cli.cmd.Constants.NEW_COMMAND;
import static io.ballerina.cli.cmd.Constants.OPENAPI_COMMAND;
import static io.ballerina.cli.cmd.Constants.PACK_COMMAND;
Expand Down Expand Up @@ -111,8 +112,8 @@ public final class BalToolsUtil {
SHELL_COMMAND, VERSION_COMMAND, OPENAPI_COMMAND, GRAPHQL_COMMAND, ASYNCAPI_COMMAND, GRPC_COMMAND,
PERSIST_COMMAND, PROFILE_COMMAND);
private static final List<String> hiddenCommands = Arrays.asList(INIT_COMMAND, TOOL_COMMAND, DIST_COMMAND,
UPDATE_COMMAND, START_LANG_SERVER_COMMAND, START_DEBUG_ADAPTER_COMMAND, HELP_COMMAND, HOME_COMMAND,
GENCACHE_COMMAND);
UPDATE_COMMAND, START_LANG_SERVER_COMMAND, LANG_SERVER_SPEC, START_DEBUG_ADAPTER_COMMAND, HELP_COMMAND,
HOME_COMMAND, GENCACHE_COMMAND);
// if a command is a built-in tool command, add it to this list
private static final List<String> builtInToolCommands = List.of();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
requires io.ballerina.cli;
requires info.picocli;
requires io.ballerina.language.server.stdio.launcher;
}
requires com.google.gson;
}
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");
}
}

Check warning on line 67 in language-server/modules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.java

View check run for this annotation

Codecov / codecov/patch

language-server/modules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.java#L59-L67

Added lines #L59 - L67 were not covered by tests

@Override
public String getName() {
return CMD_NAME;
}

@Override
public void printLongDesc(StringBuilder out) {

}

Check warning on line 77 in language-server/modules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.java

View check run for this annotation

Codecov / codecov/patch

language-server/modules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.java#L77

Added line #L77 was not covered by tests

@Override
public void printUsage(StringBuilder out) {

}

Check warning on line 82 in language-server/modules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.java

View check run for this annotation

Codecov / codecov/patch

language-server/modules/langserver-cli/src/main/java/org/ballerinalang/langserver/cmd/LangServerSpecCmd.java#L82

Added line #L82 was not covered by tests

@Override
public void setParentCmdParser(CommandLine parentCmdParser) {

}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
org.ballerinalang.langserver.cmd.LangServerStartCmd
org.ballerinalang.langserver.cmd.LangServerSpecCmd
106 changes: 61 additions & 45 deletions language-server/modules/langserver-core/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
-->
<FindBugsFilter>
<Match>
<Package name="org.ballerinalang.langserver.workspace.repository" />
<Package name="org.ballerinalang.langserver.workspace.repository"/>
</Match>
<Match>
<Package name="org.ballerinalang.langserver.common.utils" />
<Package name="org.ballerinalang.langserver.common.utils"/>
<OR>
<Bug pattern="DE_MIGHT_IGNORE"/>
</OR>
Expand All @@ -35,105 +35,105 @@
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.LSContextManager" />
<Class name="org.ballerinalang.langserver.LSContextManager"/>
<OR>
<Bug pattern="NP_NULL_PARAM_DEREF" />
<Bug pattern="NP_NULL_PARAM_DEREF"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.BallerinaTextDocumentService" />
<Class name="org.ballerinalang.langserver.BallerinaTextDocumentService"/>
<OR>
<Bug pattern="REC_CATCH_EXCEPTION" />
<Bug pattern="REC_CATCH_EXCEPTION"/>
</OR>
</Match>
<Match>
<Package name="org.ballerinalang.langserver.completions.resolvers" />
<Package name="org.ballerinalang.langserver.completions.resolvers"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Package name="org.ballerinalang.langserver.completions.providers.context" />
<Package name="org.ballerinalang.langserver.completions.providers.context"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.util.SortingUtil" />
<Class name="org.ballerinalang.langserver.completions.util.SortingUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.util.QNameRefCompletionUtil" />
<Class name="org.ballerinalang.langserver.completions.util.QNameRefCompletionUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.signature.SignatureHelpUtil" />
<Class name="org.ballerinalang.langserver.signature.SignatureHelpUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.command.docs.DocumentationGenerator" />
<Class name="org.ballerinalang.langserver.command.docs.DocumentationGenerator"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.builder.FunctionCompletionItemBuilder" />
<Class name="org.ballerinalang.langserver.completions.builder.FunctionCompletionItemBuilder"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.codeaction.providers.CreateFunctionCodeAction" />
<Class name="org.ballerinalang.langserver.codeaction.providers.CreateFunctionCodeAction"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.command.executors.PullModuleExecutor" />
<Class name="org.ballerinalang.langserver.command.executors.PullModuleExecutor"/>
<OR>
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE" />
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.extensions.ballerina.connector.BallerinaConnectorService" />
<Class name="org.ballerinalang.langserver.extensions.ballerina.connector.BallerinaConnectorService"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.extensions.ballerina.document.BallerinaTreeModifyUtil" />
<Class name="org.ballerinalang.langserver.extensions.ballerina.document.BallerinaTreeModifyUtil"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.extensions.ballerina.document.BallerinaTriggerModifyUtil" />
<Class name="org.ballerinalang.langserver.extensions.ballerina.document.BallerinaTriggerModifyUtil"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.extensions.ballerina.document.BallerinaServiceListResponse" />
<Class name="org.ballerinalang.langserver.extensions.ballerina.document.BallerinaServiceListResponse"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.hover.HoverUtil" />
<Class name="org.ballerinalang.langserver.hover.HoverUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.definition.DefinitionUtil" />
<Class name="org.ballerinalang.langserver.definition.DefinitionUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.codeaction.CodeActionUtil" />
<Class name="org.ballerinalang.langserver.codeaction.CodeActionUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.providers.context.util.ClassDefinitionNodeContextUtil" />
<Class name="org.ballerinalang.langserver.completions.providers.context.util.ClassDefinitionNodeContextUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
Expand All @@ -158,36 +158,52 @@
<Class name="org.ballerinalang.langserver.workspace.BallerinaWorkspaceManager"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.util.Snippet" />
<Class name="org.ballerinalang.langserver.completions.util.Snippet"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.documentsymbol.DocumentSymbolUtil" />
<Class name="org.ballerinalang.langserver.documentsymbol.DocumentSymbolUtil"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.builder.XMLNSCompletionItemBuilder"/>
<OR>
<Bug pattern="DM_CONVERT_CASE" />
<Bug pattern="DM_CONVERT_CASE"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.util.TestUtil" />
<Class name="org.ballerinalang.langserver.util.TestUtil"/>
<OR>
<Bug pattern="DM_DEFAULT_ENCODING" />
<Bug pattern="DM_DEFAULT_ENCODING"/>
</OR>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.completions.providers.context.util.RegexpCompletionProvider" />
<Class name="org.ballerinalang.langserver.completions.providers.context.util.RegexpCompletionProvider"/>
<OR>
<Bug pattern="BC_UNCONFIRMED_CAST" />
<Bug pattern="BC_UNCONFIRMED_CAST"/>
</OR>
</Match>
<Match>
<Bug pattern="EI_EXPOSE_REP,EI_EXPOSE_REP2,MC_OVERRIDABLE_METHOD_CALL_IN_CONSTRUCTOR,CT_CONSTRUCTOR_THROW"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.apispec.TypeSchema"/>
<Bug pattern="URF_UNREAD_FIELD"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.apispec.TypeSchema$CollectionTypeSchema"/>
<Bug pattern="URF_UNREAD_FIELD"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.apispec.TypeSchema$EnumTypeSchema"/>
<Bug pattern="URF_UNREAD_FIELD"/>
</Match>
<Match>
<Class name="org.ballerinalang.langserver.apispec.TypeSchema$ObjectTypeSchema"/>
<Bug pattern="URF_UNREAD_FIELD"/>
</Match>
</FindBugsFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
exports org.ballerinalang.langserver.telemetry;
exports org.ballerinalang.langserver.util;
exports org.ballerinalang.langserver.codeaction to io.ballerina.datamapper;
exports org.ballerinalang.langserver.apispec;
requires io.ballerina.diagram.util;
requires io.ballerina.formatter.core;
requires org.eclipse.lsp4j;
Expand Down
Loading
Loading