entlicher commented on a change in pull request #3025: URL: https://github.com/apache/netbeans/pull/3025#discussion_r662584205
########## File path: java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/ProjectConfigurationCompletion.java ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.netbeans.modules.java.lsp.server.protocol; + +import com.google.gson.stream.JsonWriter; +import java.io.IOException; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +import org.eclipse.lsp4j.CompletionItem; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.ProjectConfiguration; +import org.netbeans.spi.project.ProjectConfigurationProvider; +import org.openide.util.Exceptions; +import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; + +/** + * Completion of project configurations in launch.json. + * + * @author Martin Entlicher + */ +@ServiceProvider(service = LaunchConfigurationCompletion.class, position = 100) +public class ProjectConfigurationCompletion implements LaunchConfigurationCompletion { + + private static final String CONFIG_TYPE = "java8+"; // NOI18N + + @Override + public CompletableFuture<List<CompletionItem>> configurations(Supplier<CompletableFuture<Project>> projectSupplier) { + return projectSupplier.get().thenApply(p -> createConfigurationsCompletion(p)); + } + + @Override + public CompletableFuture<List<CompletionItem>> attributes(Supplier<CompletableFuture<Project>> projectSupplier, Map<String, Object> currentAttributes) { + return CompletableFuture.completedFuture(Collections.emptyList()); + } + + @Override + public CompletableFuture<List<CompletionItem>> attributeValues(Supplier<CompletableFuture<Project>> projectSupplier, Map<String, Object> currentAttributes, String attribute) { + if ("launchConfiguration".equals(attribute)) { // NOI18N + return projectSupplier.get().thenApply(p -> createLaunchConfigCompletion(p)); + } else { + return CompletableFuture.completedFuture(Collections.emptyList()); + } + } + + @NbBundle.Messages({"# {0} - Configuration name", "LBL_LaunchJavaConfig=Launch Java: {0}", + "# {0} - Configuration name", "LBL_LaunchJavaConfig_desc=Launch a Java 8+ application using {0}."}) + private static List<CompletionItem> createConfigurationsCompletion(Project p) { + ProjectConfigurationProvider<ProjectConfiguration> provider = p.getLookup().lookup(ProjectConfigurationProvider.class); + Collection<ProjectConfiguration> configurations = provider.getConfigurations(); + List<CompletionItem> completionItems = new ArrayList<>(configurations.size() - 1); + boolean skipFirst = true; + for (ProjectConfiguration c : configurations) { + if (skipFirst) { + skipFirst = false; + continue; + } + String configDisplayName = c.getDisplayName(); + String launchName = Bundle.LBL_LaunchJavaConfig(configDisplayName); + CompletionItem ci = new CompletionItem("Java 8+: " + launchName); // NOI18N Review comment: We do not localize "Java 8+" anywhere AFAIK. It's the identification name of our integration. I have seen that name of other configurations always start with the same name. Like "Chrome: ...", "Edge: ...", "Node.js: ..." And for us it's "Java 8+: ..." It makes no sense to me to localize the prefix. But, maybe we should address the right-to-left orientation in some languages. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
