dbalek commented on a change in pull request #2812: URL: https://github.com/apache/netbeans/pull/2812#discussion_r601731305
########## File path: ide/api.lsp/src/org/netbeans/api/lsp/Completion.java ########## @@ -0,0 +1,405 @@ +/* + * 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.api.lsp; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +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; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.lib.editor.util.swing.DocumentUtilities; +import org.netbeans.modules.lsp.CompletionAccessor; +import org.netbeans.spi.lsp.CompletionCollector; + +/** + * Represents a completion proposal. + * + * @author Dusan Balek + */ +public final class Completion { + + static { + CompletionAccessor.setDefault(new CompletionAccessor() { + @Override + public Completion createCompletion(String label, Kind kind, List<Tag> tags, CompletableFuture<String> detail, CompletableFuture<String> documentation, + boolean preselect, String sortText, String filterText, String insertText, TextFormat insertTextFormat, TextEdit textEdit, CompletableFuture<List<TextEdit>> additionalTextEdits, + List<Character> commitCharacters, Command command) { + return new Completion(label, kind, tags, detail, documentation, preselect, sortText, filterText, insertText, insertTextFormat, textEdit, additionalTextEdits, commitCharacters, command); + } + }); + } + + private final String label; + private final Kind kind; + private final List<Tag> tags; + private final CompletableFuture<String> detail; + private final CompletableFuture<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 CompletableFuture<List<TextEdit>> additionalTextEdits; + private final List<Character> commitCharacters; + private final Command command; + + private Completion(String label, Kind kind, List<Tag> tags, CompletableFuture<String> detail, CompletableFuture<String> documentation, + boolean preselect, String sortText, String filterText, String insertText, TextFormat insertTextFormat, + TextEdit textEdit, CompletableFuture<List<TextEdit>> additionalTextEdits, List<Character> commitCharacters, Command command) { + 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; + } + + /** + * 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 != null ? Collections.unmodifiableList(tags) : null; + } + + /** + * A human-readable string with additional information + * about this completion, like type or symbol information. + */ + @CheckForNull + public CompletableFuture<String> getDetail() { + return detail; + } + + /** + * A human-readable string that represents a doc-comment. An HTML format is + * supported. + */ + @CheckForNull + public CompletableFuture<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() { + return textEdit; + } + + /** + * A list of additional text edits that are applied when selecting this + * completion. Edits must not overlap (including the same insert position) + * with the main edit nor with themselves. + * Additional text edits should be used to change text unrelated to the + * current cursor position (for example adding an import statement at the + * top of the file if the completion item will insert an unqualified type). + */ + @CheckForNull + public CompletableFuture<List<TextEdit>> getAdditionalTextEdits() { Review comment: Its by LSP specification. Only `documentation`, `detail` and `additionalTextEdits` can be computed lazy on completion resolve request. ########## File path: ide/api.lsp/src/org/netbeans/api/lsp/Completion.java ########## @@ -0,0 +1,405 @@ +/* + * 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.api.lsp; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.CompletableFuture; +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; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; +import org.netbeans.lib.editor.util.swing.DocumentUtilities; +import org.netbeans.modules.lsp.CompletionAccessor; +import org.netbeans.spi.lsp.CompletionCollector; + +/** + * Represents a completion proposal. + * + * @author Dusan Balek + */ +public final class Completion { + + static { + CompletionAccessor.setDefault(new CompletionAccessor() { + @Override + public Completion createCompletion(String label, Kind kind, List<Tag> tags, CompletableFuture<String> detail, CompletableFuture<String> documentation, + boolean preselect, String sortText, String filterText, String insertText, TextFormat insertTextFormat, TextEdit textEdit, CompletableFuture<List<TextEdit>> additionalTextEdits, + List<Character> commitCharacters, Command command) { + return new Completion(label, kind, tags, detail, documentation, preselect, sortText, filterText, insertText, insertTextFormat, textEdit, additionalTextEdits, commitCharacters, command); + } + }); + } + + private final String label; + private final Kind kind; + private final List<Tag> tags; + private final CompletableFuture<String> detail; + private final CompletableFuture<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 CompletableFuture<List<TextEdit>> additionalTextEdits; + private final List<Character> commitCharacters; + private final Command command; + + private Completion(String label, Kind kind, List<Tag> tags, CompletableFuture<String> detail, CompletableFuture<String> documentation, + boolean preselect, String sortText, String filterText, String insertText, TextFormat insertTextFormat, + TextEdit textEdit, CompletableFuture<List<TextEdit>> additionalTextEdits, List<Character> commitCharacters, Command command) { + 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; + } + + /** + * 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 != null ? Collections.unmodifiableList(tags) : null; + } + + /** + * A human-readable string with additional information + * about this completion, like type or symbol information. + */ + @CheckForNull + public CompletableFuture<String> getDetail() { + return detail; + } + + /** + * A human-readable string that represents a doc-comment. An HTML format is + * supported. + */ + @CheckForNull + public CompletableFuture<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() { + return textEdit; + } + + /** + * A list of additional text edits that are applied when selecting this + * completion. Edits must not overlap (including the same insert position) + * with the main edit nor with themselves. + * Additional text edits should be used to change text unrelated to the + * current cursor position (for example adding an import statement at the + * top of the file if the completion item will insert an unqualified type). + */ + @CheckForNull + public CompletableFuture<List<TextEdit>> getAdditionalTextEdits() { Review comment: It is by LSP specification. Only `documentation`, `detail` and `additionalTextEdits` can be computed lazy on completion resolve request. -- 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
