jlahoda commented on a change in pull request #2587:
URL: https://github.com/apache/netbeans/pull/2587#discussion_r543092116



##########
File path: 
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/CodeGenerator.java
##########
@@ -0,0 +1,312 @@
+/*
+ * 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.sun.source.tree.LineMap;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.UncheckedIOException;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Objects;
+import java.util.Properties;
+import java.util.Set;
+import java.util.concurrent.CompletableFuture;
+import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
+import javax.lang.model.element.ExecutableElement;
+import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.TypeParameterElement;
+import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.ArrayType;
+import javax.lang.model.type.TypeKind;
+import javax.lang.model.type.TypeMirror;
+import org.eclipse.lsp4j.CodeAction;
+import org.eclipse.lsp4j.CodeActionParams;
+import org.eclipse.lsp4j.Command;
+import org.eclipse.lsp4j.Position;
+import org.eclipse.xtext.xbase.lib.Pure;
+import org.netbeans.api.java.source.CompilationInfo;
+import org.netbeans.api.java.source.ElementHandle;
+import org.netbeans.modules.editor.java.Utilities;
+import org.netbeans.modules.java.source.ElementHandleAccessor;
+import org.openide.filesystems.FileObject;
+import org.openide.filesystems.FileUtil;
+import org.openide.filesystems.URLMapper;
+import org.openide.modules.Places;
+import org.openide.util.Exceptions;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+public abstract class CodeGenerator {
+
+    public static final String CODE_GENERATOR_KIND = "source.generate";
+    protected static final String ERROR = "<error>"; //NOI18N
+
+    public abstract List<CodeAction> getCodeActions(CompilationInfo info, 
CodeActionParams params);
+
+    public abstract Set<String> getCommands();
+
+    public abstract CompletableFuture<Object> 
processCommand(NbCodeLanguageClient client, String command, List<Object> 
arguments);
+
+    protected static int getOffset(CompilationInfo info, Position pos) {
+        LineMap lm = info.getCompilationUnit().getLineMap();
+        return (int) lm.getPosition(pos.getLine() + 1, pos.getCharacter() + 1);
+    }
+
+    protected static CodeAction createCodeAction(String name, String kind, 
String command, Object... args) {
+        CodeAction action = new CodeAction(name);
+        action.setKind(kind);
+        action.setCommand(new Command(name, command, Arrays.asList(args)));
+        return action;
+    }
+
+    protected static String toUri(FileObject file) {
+        if (FileUtil.isArchiveArtifact(file)) {
+            //VS code cannot open jar:file: URLs, workaround:

Review comment:
       I think it is a little misleading to say the code was introduced in 
#2530 - the code is there for years, see:
   
https://github.com/apache/netbeans/pull/926/commits/64521088b6cc95a5a1951883ad9106e4839e06b8
   
   Anyway, to the merit: I assume you mean `URLMapper.NETWORK`, not `EXTERNAL`. 
As far as I can tall, `EXTERNAL` is still jar:file:. Anyway, I just tried with 
NETWORK (again), and VS Code still seems to reject it, at least in my setup. 
firefox started next to VS Code can access the URL just fine. It might be just 
an issue with rejecting http (and preferring https), although I am not sure of 
that. From the protocol, it is also not clear to me what types of URLs LSP 
clients are obliged to accept.
   
   Regarding this particular code - wouldn't it be better to use Utils.toUri? 
That would keep this code on one place, so that when Jaroslav fixes it, it will 
be automatically fixed on all places?
   




----------------------------------------------------------------
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.

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

Reply via email to