Skip to content

Commit

Permalink
iReverting "Prefixing all code names of commands with 'nbls'.", as mo…
Browse files Browse the repository at this point in the history
…re time will be needed to discuss, validate the patch and adjust to it.
  • Loading branch information
lahodaj committed Jun 22, 2023
1 parent 20a867a commit 9c28cf6
Show file tree
Hide file tree
Showing 27 changed files with 200 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
Expand All @@ -55,7 +53,6 @@
import org.netbeans.api.java.source.CompilationInfo;
import org.netbeans.api.lsp.StructureElement;
import org.netbeans.modules.editor.java.Utilities;
import org.netbeans.modules.java.lsp.server.protocol.NbCodeClientCapabilities;
import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport;
import org.netbeans.spi.jumpto.type.SearchType;
import org.openide.cookies.EditorCookie;
Expand All @@ -70,8 +67,6 @@
*/
public class Utils {

public static final String DEFAULT_COMMAND_PREFIX = "nbls";

public static SymbolKind structureElementKind2SymbolKind (StructureElement.Kind kind) {
switch (kind) {
case Array : return SymbolKind.Array;
Expand Down Expand Up @@ -449,38 +444,4 @@ public static String html2plain(String s) {
return sb.toString();
}

public static String encodeCommand(String cmd, NbCodeClientCapabilities capa) {
String prefix = capa != null ? capa.getCommandPrefix()
: DEFAULT_COMMAND_PREFIX;

if (cmd.startsWith(DEFAULT_COMMAND_PREFIX) &&
!DEFAULT_COMMAND_PREFIX.equals(prefix)) {
return prefix + cmd.substring(DEFAULT_COMMAND_PREFIX.length());
} else {
return cmd;
}
}

public static String decodeCommand(String cmd, NbCodeClientCapabilities capa) {
String prefix = capa != null ? capa.getCommandPrefix()
: DEFAULT_COMMAND_PREFIX;

if (cmd.startsWith(prefix) &&
!DEFAULT_COMMAND_PREFIX.equals(prefix)) {
return DEFAULT_COMMAND_PREFIX + cmd.substring(prefix.length());
} else {
return cmd;
}
}

public static void ensureCommandsPrefixed(Collection<String> commands) {
Set<String> wrongCommands = commands.stream()
.filter(cmd -> !cmd.startsWith(DEFAULT_COMMAND_PREFIX))
.filter(cmd -> !cmd.startsWith("test."))
.collect(Collectors.toSet());

if (!wrongCommands.isEmpty()) {
throw new IllegalStateException("Some commands are not properly prefixed: " + wrongCommands);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
})
@ServiceProvider(service = CodeActionsProvider.class)
public class DBAddConnection extends CodeActionsProvider {
public static final String DB_ADD_CONNECTION = "nbls.db.add.connection"; // NOI18N
public static final String DB_ADD_CONNECTION = "db.add.connection"; // NOI18N
public static final String USER_ID = "userId"; // NOI18N
public static final String PASSWORD = "password"; // NOI18N
public static final String DRIVER = "driver"; // NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
*/
@ServiceProvider(service = CodeActionsProvider.class)
public class DBCommandProvider extends CodeActionsProvider {
private static final String COMMAND_GET_PREFERRED_CONNECTION = "nbls.db.preferred.connection";
private static final String COMMAND_GET_PREFERRED_CONNECTION = "java.db.preferred.connection";

private static final Set<String> COMMANDS = new HashSet<>(Arrays.asList(
COMMAND_GET_PREFERRED_CONNECTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
@ServiceProvider(service = CodeActionsProvider.class)
public class DBConnectionProvider extends CodeActionsProvider{
private static final String GET_DB_CONNECTION = "nbls.db.connection"; //NOI18N
private static final String GET_DB_CONNECTION = "java.db.connection"; //NOI18N

private static final Set<String> COMMANDS = new HashSet<>(Arrays.asList(
GET_DB_CONNECTION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ private static Level findLevel(int priority) {
public static final class Server extends CodeActionsProvider {

private static final Map<String, WebView.Command> SESSIONS = new HashMap<>();
private static final String PROCESS_COMMAND = "nbls.htmlui.process.command"; // NOI18N
private static final String PROCESS_COMMAND = "nb.htmlui.process.command"; // NOI18N
private static final String ID = "id"; // NOI18N
private final Gson gson = new Gson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@ServiceProvider(service = CodeActionsProvider.class, position = 200)
public final class ImplementAllAbstractMethodsAction extends CodeActionsProvider {

private static final String IMPLEMENT_ALL_ABSTRACT_METHODS = "nbls.java.implement.all.abstract.methods"; //NOI18N
private static final String IMPLEMENT_ALL_ABSTRACT_METHODS = "java.implement.all.abstract.methods"; //NOI18N
private final Gson gson = new Gson();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import com.google.gson.JsonElement;
import org.eclipse.lsp4j.ClientCapabilities;
import org.eclipse.lsp4j.InitializeParams;
import org.netbeans.modules.java.lsp.server.Utils;

/**
* Encapsulates all nbcode-specific client capabilities. Need to be passed in
Expand Down Expand Up @@ -76,16 +75,6 @@ public final class NbCodeClientCapabilities {
*/
private Boolean wantsGroovySupport = Boolean.TRUE;

/**
* Common prefix for all commands.
*/
private String commandPrefix = Utils.DEFAULT_COMMAND_PREFIX;

/**
* Common prefix for all configuration.
*/
private String configurationPrefix = "netbeans.";

public ClientCapabilities getClientCapabilities() {
return clientCaps;
}
Expand Down Expand Up @@ -150,22 +139,6 @@ public boolean wantsGroovySupport() {
return wantsGroovySupport.booleanValue();
}

public String getCommandPrefix() {
return commandPrefix;
}

public void setCommandPrefix(String commandPrefix) {
this.commandPrefix = commandPrefix;
}

public String getConfigurationPrefix() {
return configurationPrefix;
}

public void setConfigurationPrefix(String configurationPrefix) {
this.configurationPrefix = configurationPrefix;
}

private NbCodeClientCapabilities withCapabilities(ClientCapabilities caps) {
if (caps == null) {
caps = new ClientCapabilities();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
@ServiceProvider(service = CodeActionsProvider.class)
public class QuickOpen extends CodeActionsProvider {

public static final String QUICK_OPEN = "nbls.quick.open"; // NOI18N
public static final String QUICK_OPEN = "java.quick.open"; // NOI18N
public static final String DEFAULT_PKG = "<default package>"; // NOI18N
private final Gson gson = new Gson();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import java.util.prefs.Preferences;
import java.util.LinkedHashSet;
import java.util.concurrent.CompletionException;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.CallHierarchyRegistrationOptions;
import org.eclipse.lsp4j.CodeActionKind;
import org.eclipse.lsp4j.CodeActionOptions;
Expand Down Expand Up @@ -349,8 +348,8 @@ public Project next() {

public static class LanguageServerImpl implements LanguageServer, LanguageClientAware, LspServerState, NbLanguageServer {

private static final String NETBEANS_FORMAT = "format";
private static final String NETBEANS_JAVA_IMPORTS = "java.imports";
private static final String NETBEANS_FORMAT = "netbeans.format";
private static final String NETBEANS_JAVA_IMPORTS = "netbeans.java.imports";

// change to a greater throughput if the initialization waits on more processes than just (serialized) project open.
private static final RequestProcessor SERVER_INIT_RP = new RequestProcessor(LanguageServerImpl.class.getName());
Expand Down Expand Up @@ -755,7 +754,7 @@ private void showStatusBarMessage(final MessageType type, final String msg, int
}
}

private InitializeResult constructInitResponse(InitializeParams init, JavaSource src, NbCodeClientCapabilities capa) {
private InitializeResult constructInitResponse(InitializeParams init, JavaSource src) {
ServerCapabilities capabilities = new ServerCapabilities();
if (src != null) {
TextDocumentSyncOptions textDocumentSyncOptions = new TextDocumentSyncOptions();
Expand Down Expand Up @@ -783,33 +782,31 @@ private InitializeResult constructInitResponse(InitializeParams init, JavaSource
CallHierarchyRegistrationOptions chOpts = new CallHierarchyRegistrationOptions();
chOpts.setWorkDoneProgress(true);
capabilities.setCallHierarchyProvider(chOpts);
Set<String> commands = new LinkedHashSet<>(Arrays.asList(NBLS_GRAALVM_PAUSE_SCRIPT,
Set<String> commands = new LinkedHashSet<>(Arrays.asList(GRAALVM_PAUSE_SCRIPT,
NBLS_BUILD_WORKSPACE,
NBLS_CLEAN_WORKSPACE,
NBLS_RUN_PROJECT_ACTION,
JAVA_RUN_PROJECT_ACTION,
JAVA_FIND_DEBUG_ATTACH_CONFIGURATIONS,
JAVA_FIND_DEBUG_PROCESS_TO_ATTACH,
NBLS_FIND_PROJECT_CONFIGURATIONS,
JAVA_FIND_PROJECT_CONFIGURATIONS,
JAVA_GET_PROJECT_CLASSPATH,
JAVA_GET_PROJECT_PACKAGES,
JAVA_GET_PROJECT_SOURCE_ROOTS,
NBLS_LOAD_WORKSPACE_TESTS,
NBLS_RESOLVE_STACKTRACE_LOCATION,
NBLS_NEW_FROM_TEMPLATE,
NBLS_NEW_PROJECT,
NBLS_PROJECT_CONFIGURATION_COMPLETION,
NBLS_PROJECT_RESOLVE_PROJECT_PROBLEMS,
JAVA_LOAD_WORKSPACE_TESTS,
JAVA_RESOLVE_STACKTRACE_LOCATION,
JAVA_NEW_FROM_TEMPLATE,
JAVA_NEW_PROJECT,
JAVA_PROJECT_CONFIGURATION_COMPLETION,
JAVA_PROJECT_RESOLVE_PROJECT_PROBLEMS,
JAVA_SUPER_IMPLEMENTATION,
NBLS_CLEAR_PROJECT_CACHES,
JAVA_CLEAR_PROJECT_CACHES,
NATIVE_IMAGE_FIND_DEBUG_PROCESS_TO_ATTACH,
NBLS_PROJECT_INFO,
JAVA_PROJECT_INFO,
JAVA_ENABLE_PREVIEW
));
for (CodeActionsProvider codeActionsProvider : Lookup.getDefault().lookupAll(CodeActionsProvider.class)) {
commands.addAll(codeActionsProvider.getCommands());
}
Utils.ensureCommandsPrefixed(commands);
commands = commands.stream().map(cmd -> Utils.encodeCommand(cmd, capa)).collect(Collectors.toSet());
capabilities.setExecuteCommandProvider(new ExecuteCommandOptions(new ArrayList<>(commands)));
WorkspaceSymbolOptions wsOpts = new WorkspaceSymbolOptions();
wsOpts.setResolveProvider(true);
Expand Down Expand Up @@ -874,7 +871,7 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams init) {
// but complete the InitializationRequest independently of the project initialization.
return CompletableFuture.completedFuture(
finishInitialization(
constructInitResponse(init, checkJavaSupport(), capa)
constructInitResponse(init, checkJavaSupport())
)
);
}
Expand All @@ -885,13 +882,13 @@ private void initializeOptions() {
ConfigurationItem item = new ConfigurationItem();
FileObject fo = projects[0].getProjectDirectory();
item.setScopeUri(Utils.toUri(fo));
item.setSection(client.getNbCodeCapabilities().getConfigurationPrefix() + NETBEANS_FORMAT);
item.setSection(NETBEANS_FORMAT);
client.configuration(new ConfigurationParams(Collections.singletonList(item))).thenAccept(c -> {
if (c != null && !c.isEmpty() && c.get(0) instanceof JsonObject) {
workspaceService.updateJavaFormatPreferences(fo, (JsonObject) c.get(0));
}
});
item.setSection(client.getNbCodeCapabilities().getConfigurationPrefix() + NETBEANS_JAVA_IMPORTS);
item.setSection(NETBEANS_JAVA_IMPORTS);
client.configuration(new ConfigurationParams(Collections.singletonList(item))).thenAccept(c -> {
if (c != null && !c.isEmpty() && c.get(0) instanceof JsonObject) {
workspaceService.updateJavaImportPreferences(fo, (JsonObject) c.get(0));
Expand Down Expand Up @@ -975,59 +972,59 @@ public void setTrace(SetTraceParams params) {

public static final String NBLS_BUILD_WORKSPACE = "nbls.build.workspace";
public static final String NBLS_CLEAN_WORKSPACE = "nbls.clean.workspace";
public static final String NBLS_NEW_FROM_TEMPLATE = "nbls.new.from.template";
public static final String NBLS_NEW_PROJECT = "nbls.new.project";
public static final String JAVA_GET_PROJECT_SOURCE_ROOTS = "nbls.java.get.project.source.roots";
public static final String JAVA_GET_PROJECT_CLASSPATH = "nbls.java.get.project.classpath";
public static final String JAVA_GET_PROJECT_PACKAGES = "nbls.java.get.project.packages";
public static final String NBLS_LOAD_WORKSPACE_TESTS = "nbls.load.workspace.tests";
public static final String NBLS_RESOLVE_STACKTRACE_LOCATION = "nbls.resolve.stacktrace.location";
public static final String JAVA_SUPER_IMPLEMENTATION = "nbls.java.super.implementation";
public static final String NBLS_GRAALVM_PAUSE_SCRIPT = "nbls.graalvm.pause.script";
public static final String NBLS_RUN_PROJECT_ACTION = "nbls.project.run.action";
public static final String JAVA_NEW_FROM_TEMPLATE = "java.new.from.template";
public static final String JAVA_NEW_PROJECT = "java.new.project";
public static final String JAVA_GET_PROJECT_SOURCE_ROOTS = "java.get.project.source.roots";
public static final String JAVA_GET_PROJECT_CLASSPATH = "java.get.project.classpath";
public static final String JAVA_GET_PROJECT_PACKAGES = "java.get.project.packages";
public static final String JAVA_LOAD_WORKSPACE_TESTS = "java.load.workspace.tests";
public static final String JAVA_RESOLVE_STACKTRACE_LOCATION = "java.resolve.stacktrace.location";
public static final String JAVA_SUPER_IMPLEMENTATION = "java.super.implementation";
public static final String GRAALVM_PAUSE_SCRIPT = "graalvm.pause.script";
public static final String JAVA_RUN_PROJECT_ACTION = "java.project.run.action";

/**
* Enumerates project configurations.
*/
public static final String NBLS_FIND_PROJECT_CONFIGURATIONS = "nbls.project.configurations";
public static final String JAVA_FIND_PROJECT_CONFIGURATIONS = "java.project.configurations";
/**
* Enumerates attach debugger configurations.
*/
public static final String JAVA_FIND_DEBUG_ATTACH_CONFIGURATIONS = "nbls.java.attachDebugger.configurations";
public static final String JAVA_FIND_DEBUG_ATTACH_CONFIGURATIONS = "java.attachDebugger.configurations";
/**
* Enumerates JVM processes eligible for debugger attach.
*/
public static final String JAVA_FIND_DEBUG_PROCESS_TO_ATTACH = "nbls.java.attachDebugger.pickProcess";
public static final String JAVA_FIND_DEBUG_PROCESS_TO_ATTACH = "java.attachDebugger.pickProcess";
/**
* Enumerates native processes eligible for debugger attach.
*/
public static final String NATIVE_IMAGE_FIND_DEBUG_PROCESS_TO_ATTACH = "nbls.nativeImage.attachDebugger.pickProcess";
public static final String NATIVE_IMAGE_FIND_DEBUG_PROCESS_TO_ATTACH = "nativeImage.attachDebugger.pickProcess";
/**
* Provides code-completion of configurations.
*/
public static final String NBLS_PROJECT_CONFIGURATION_COMPLETION = "nbls.project.configuration.completion";
public static final String JAVA_PROJECT_CONFIGURATION_COMPLETION = "java.project.configuration.completion";
/**
* Provides resolution of project problems.
*/
public static final String NBLS_PROJECT_RESOLVE_PROJECT_PROBLEMS = "nbls.project.resolveProjectProblems";
public static final String JAVA_PROJECT_RESOLVE_PROJECT_PROBLEMS = "java.project.resolveProjectProblems";


/**
* Diagnostic / test command: clears NBLS internal project caches. Useful between testcases and after
* new project files were generated into workspace subtree.
*/
public static final String NBLS_CLEAR_PROJECT_CACHES = "nbls.clear.project.caches";
public static final String JAVA_CLEAR_PROJECT_CACHES = "java.clear.project.caches";

/**
* For a project directory, returns basic project information and structure.
* Syntax: nbls.project.info(locations : String | String[], options? : { projectStructure? : boolean; actions? : boolean; recursive? : boolean }) : LspProjectInfo
*/
public static final String NBLS_PROJECT_INFO = "nbls.project.info";
public static final String JAVA_PROJECT_INFO = "nbls.project.info";

/**
* Provides enable preview for given project
*/
public static final String JAVA_ENABLE_PREVIEW = "nbls.java.project.enable.preview";
public static final String JAVA_ENABLE_PREVIEW = "java.project.enable.preview";

static final String INDEXING_COMPLETED = "Indexing completed.";
static final String NO_JAVA_SUPPORT = "Cannot initialize Java support on JDK ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
public final class SurroundWithHint extends CodeActionsProvider {

private static final String COMMAND_INSERT_SNIPPET = "editor.action.insertSnippet";
private static final String COMMAND_SURROUND_WITH = "surround.with";
private static final String COMMAND_SURROUND_WITH = "java.surround.with";
private static final String DOTS = "...";
private static final String SNIPPET = "snippet";
private static final String SELECTION_VAR = "${selection}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
@ServiceProvider(service = CodeActionsProvider.class, position = 100)
public final class TestClassGenerator extends CodeActionsProvider {

private static final String GENERATE_TEST_CLASS_COMMAND = "nbls.java.generate.testClass";
private static final String GENERATE_TEST_CLASS_COMMAND = "java.generate.testClass";

private final Set<String> commands = Collections.singleton(GENERATE_TEST_CLASS_COMMAND);

Expand Down
Loading

0 comments on commit 9c28cf6

Please sign in to comment.