dbalek commented on a change in pull request #2812:
URL: https://github.com/apache/netbeans/pull/2812#discussion_r601361764



##########
File path: 
ide/editor.completion/src/org/netbeans/spi/editor/completion/CompletionCollector.java
##########
@@ -0,0 +1,565 @@
+/*
+ * 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.spi.editor.completion;
+
+import java.util.List;
+import java.util.function.Consumer;
+import javax.swing.text.Document;
+import org.netbeans.api.annotations.common.CheckForNull;
+import org.netbeans.api.annotations.common.NonNull;
+import org.netbeans.api.annotations.common.NullAllowed;
+
+/**
+ * Interface for computing and collecting completions. Clients can use this 
interface
+ * to collect completions and send them for presentation outside of NetBeans,
+ * e.g. using the Language Server Protocol. Implementations of the interface
+ * should be registered in MimeLookup.
+ *
+ * @author Dusan Balek
+ * @since 1.57
+ */
+public interface CompletionCollector {
+
+    /**
+     * Computes and collects completions for a document at a given offset.
+     * This method is called outside of AWT to collect completions and e.g.
+     * send them via the Language Server Protocol to client for display.
+     *
+     * @param doc a text document
+     * @param offset an offset inside the text document
+     * @param consumer an operation accepting collected completions
+     *
+     * @return true if the list of collected completion is complete
+     */
+    public boolean collectCompletions(Document doc, int offset, 
Consumer<Completion> consumer);
+
+    public final static class Completion {
+
+        /**
+         * Creates a new completion builder.
+         *
+         * @param label the completion label. By default also the text that is
+         *              inserted when selecting the completion created by this 
builder.
+         */
+        @NonNull
+        public static Builder newBuilder(@NonNull String label) {
+            return new Builder(label);
+        }
+
+        private final String label;
+        private final Kind kind;
+        private final List<Tag> tags;
+        private final String detail;
+        private final String documentation;
+        private final boolean preselect;
+        private final String sortText;
+        private final String filterText;
+        private final String insertText;
+        private final TextFormat insertTextFormat;
+        private final TextEdit textEdit;
+        private final List<TextEdit> additionalTextEdits;
+        private final List<String> commitCharacters;
+        private final Command command;
+        private final Object data;
+
+        private Completion(String label, Kind kind, List<Tag> tags, String 
detail, String documentation,
+                boolean preselect, String sortText, String filterText, String 
insertText, TextFormat insertTextFormat,
+                TextEdit textEdit, List<TextEdit> additionalTextEdits, 
List<String> commitCharacters, Command command, Object data) {
+            this.label = label;
+            this.kind = kind;
+            this.tags = tags;
+            this.detail = detail;
+            this.documentation = documentation;
+            this.preselect = preselect;
+            this.sortText = sortText;
+            this.filterText = filterText;
+            this.insertText = insertText;
+            this.insertTextFormat = insertTextFormat;
+            this.textEdit = textEdit;
+            this.additionalTextEdits = additionalTextEdits;
+            this.commitCharacters = commitCharacters;
+            this.command = command;
+            this.data = data;
+        }
+
+        /**
+        * The label of this completion. By default also the text that is 
inserted
+         * when selecting this completion.
+        */
+        @NonNull
+        public String getLabel() {
+            return label;
+        }
+
+        /**
+        * The kind of this completion.
+        */
+        @CheckForNull
+        public Kind getKind() {
+            return kind;
+        }
+
+        /**
+         * Tags for this completion.
+         */
+        @CheckForNull
+        public List<Tag> getTags() {
+            return tags;
+        }
+
+        /**
+        * A human-readable string with additional information
+        * about this completion, like type or symbol information.
+        */
+        @CheckForNull
+        public String getDetail() {
+            return detail;
+        }
+
+        /**
+        * A human-readable string that represents a doc-comment.
+        */
+        @CheckForNull
+        public String getDocumentation() {
+            return documentation;
+        }
+
+        /**
+        * Select this completion when showing.
+        */
+        public boolean isPreselect() {
+            return preselect;
+        }
+
+        /**
+        * A string that should be used when comparing this completion with 
other
+         * completions. When {@code null} the label is used as the sort text.
+        */
+        @CheckForNull
+        public String getSortText() {
+            return sortText;
+        }
+
+        /**
+        * A string that should be used when filtering a set of completions.
+         * When {@code null} the label is used as the filter.
+        */
+        @CheckForNull
+        public String getFilterText() {
+            return filterText;
+        }
+
+        /**
+        * A string that should be inserted into a document when selecting
+        * this completion. When {@code null} the label is used as the insert 
text.
+         */
+        @CheckForNull
+       public String getInsertText() {
+            return insertText;
+        }
+
+        /**
+        * The format of the insert text. The format applies to both the
+        * {@code insertText} property and the {@code newText} property of a 
provided
+        * {@code textEdit}. If omitted defaults to {@link 
TextFormat#PlainText}.
+        */
+        @CheckForNull
+        public TextFormat getInsertTextFormat() {
+            return insertTextFormat;
+        }
+
+        /**
+        * An edit which is applied to a document when selecting this 
completion.
+        * When an edit is provided the value of {@code insertText} is ignored.
+        * The range of the edit must be a single line range and it must
+        * contain the position at which completion has been requested.
+        */
+        @CheckForNull
+        public TextEdit getTextEdit() {

Review comment:
       These methods do not exit by mistake in LSP. Most completion items 
provide just a simple `insertText`, however some completion items may need a 
more complex handling - replace some existing text with something different 
(e.g. `OverrideMethodItem` in Java which needs to remove already written name 
prefix and replace it with the whole method declaration usually starting with 
modifiers and return type). Those items provide  `textEdit` instead of 
`insertText`.




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