JaroslavTulach commented on a change in pull request #2812:
URL: https://github.com/apache/netbeans/pull/2812#discussion_r596606155
##########
File path:
enterprise/micronaut/external/android-json-0.0.20131108.vaadin1-license.txt
##########
@@ -0,0 +1,209 @@
+Name: JSON library from Android SDK
Review comment:
I don't think we need yet another library for parsing JSON in NetBeans.
There already is `ide/modules/org-netbeans-libs-json_simple.jar`. There is also
`net.java.html.json` which we can use (I can make that work). Anyway, we should
be including proprietary internal JSON parser in `enterprise` cluster.
##########
File path:
enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigCompletionProvider.java
##########
@@ -0,0 +1,116 @@
+/*
+ * 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.micronaut;
+
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.document.EditorDocumentUtils;
+import org.netbeans.api.editor.mimelookup.MimeRegistration;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.spi.editor.completion.CompletionProvider;
+import org.netbeans.spi.editor.completion.CompletionResultSet;
+import org.netbeans.spi.editor.completion.CompletionTask;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionQuery;
+import org.netbeans.spi.editor.completion.support.AsyncCompletionTask;
+import org.openide.filesystems.FileObject;
+import
org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+@MimeRegistration(mimeType = "text/x-yaml", service = CompletionProvider.class)
+public class MicronautConfigCompletionProvider implements CompletionProvider {
Review comment:
Ideally this class wouldn't be needed. All its functionality would be
provided via `MicronautConfigCompletionCollector`.
##########
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;
Review comment:
All collections returned from this class shall not be modifiable.
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ /**
+ * A human-readable string with additional information
+ * about this completion, like type or symbol information.
+ */
+ @NonNull
+ public Builder detail(@NonNull String detail) {
+ this.detail = detail;
+ return this;
+ }
+
+ /**
+ * A human-readable string that represents a doc-comment.
+ */
+ @NonNull
+ public Builder documentation(@NonNull String documentation) {
+ this.documentation = documentation;
+ return this;
+ }
+
+ /**
+ * Select this completion when showing.
+ */
+ @NonNull
+ public Builder preselect(boolean preselect) {
+ this.preselect = preselect;
+ return this;
+ }
+
+ /**
+ * A string that should be used when comparing this completion
with other
+ * completions. When {@code null} the label is used as the sort
text.
+ */
+ @NonNull
+ public Builder sortText(@NonNull String sortText) {
+ this.sortText = sortText;
+ return this;
+ }
+
+ /**
+ * A string that should be used when filtering a set of
completions.
+ * When {@code null} the label is used as the filter.
+ */
+ @NonNull
+ public Builder filterText(@NonNull String filterText) {
+ this.filterText = filterText;
+ return this;
+ }
+
+ /**
+ * A string that should be inserted into a document when selecting
+ * this completion. When {@code null} the label is used as the
insert text.
+ */
+ @NonNull
+ public Builder insertText(@NonNull String insertText) {
+ this.insertText = insertText;
+ return this;
+ }
+
+ /**
+ * 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}.
+ */
+ @NonNull
+ public Builder insertTextFormat(@NonNull TextFormat
insertTextFormat) {
+ this.insertTextFormat = insertTextFormat;
+ return this;
+ }
+
+ /**
+ * 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.
+ */
+ @NonNull
+ public Builder textEdit(@NonNull TextEdit textEdit) {
+ this.textEdit = textEdit;
Review comment:
I'd suggest to remove or delegate to other existing concepts. For
example:
```
this.insertText = null;
this.insertTextFormat = null;
this.additonalTextEdits = Collections.singleton(textEdit);
```
at least under the assumption that such assignments provide similar behavior.
##########
File path:
java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/TextDocumentServiceImpl.java
##########
@@ -301,35 +309,88 @@ public void indexingComplete(Set<URL> indexedRoots) {
EditorCookie ec = file.getLookup().lookup(EditorCookie.class);
Document doc = ec.openDocument();
final int caret = Utils.getOffset(doc, params.getPosition());
- ParserManager.parse(Collections.singletonList(Source.create(doc)),
new UserTask() {
- @Override
- public void run(ResultIterator resultIterator) throws
Exception {
- TokenSequence<JavaTokenId> ts =
resultIterator.getSnapshot().getTokenHierarchy().tokenSequence(JavaTokenId.language());
- if (ts.move(caret) == 0 || !ts.moveNext()) {
- if (!ts.movePrevious()) {
- ts.moveNext();
+ String mimeType = file.getMIMEType();
+ if ("text/x-java".equals(mimeType)) {
+
ParserManager.parse(Collections.singletonList(Source.create(doc)), new
UserTask() {
Review comment:
Ideally this special `text/x-java` code could be moved to Java module
and exposed as `CompletionCollector`.
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ /**
+ * A human-readable string with additional information
+ * about this completion, like type or symbol information.
+ */
+ @NonNull
+ public Builder detail(@NonNull String detail) {
+ this.detail = detail;
+ return this;
+ }
+
+ /**
+ * A human-readable string that represents a doc-comment.
+ */
+ @NonNull
+ public Builder documentation(@NonNull String documentation) {
+ this.documentation = documentation;
+ return this;
+ }
+
+ /**
+ * Select this completion when showing.
+ */
+ @NonNull
+ public Builder preselect(boolean preselect) {
+ this.preselect = preselect;
+ return this;
+ }
+
+ /**
+ * A string that should be used when comparing this completion
with other
+ * completions. When {@code null} the label is used as the sort
text.
+ */
+ @NonNull
+ public Builder sortText(@NonNull String sortText) {
+ this.sortText = sortText;
+ return this;
+ }
+
+ /**
+ * A string that should be used when filtering a set of
completions.
+ * When {@code null} the label is used as the filter.
+ */
+ @NonNull
+ public Builder filterText(@NonNull String filterText) {
+ this.filterText = filterText;
+ return this;
+ }
+
+ /**
+ * A string that should be inserted into a document when selecting
+ * this completion. When {@code null} the label is used as the
insert text.
+ */
+ @NonNull
+ public Builder insertText(@NonNull String insertText) {
+ this.insertText = insertText;
+ return this;
+ }
+
+ /**
+ * 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}.
+ */
+ @NonNull
+ public Builder insertTextFormat(@NonNull TextFormat
insertTextFormat) {
+ this.insertTextFormat = insertTextFormat;
+ return this;
+ }
+
+ /**
+ * 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.
+ */
+ @NonNull
+ public Builder textEdit(@NonNull TextEdit textEdit) {
+ this.textEdit = textEdit;
+ return this;
+ }
+
+ /**
+ * 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).
+ */
+ @NonNull
+ public Builder additionalTextEdits(@NonNull List<TextEdit>
additionalTextEdits) {
+ this.additionalTextEdits = additionalTextEdits;
+ return this;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @NonNull
+ public Builder commitCharacters(@NonNull List<String>
commitCharacters) {
Review comment:
Consider making this cumulative and change to parameter like `char...`
or `char`.
##########
File path: java/maven/nbproject/project.xml
##########
@@ -621,6 +621,8 @@
<friend>org.netbeans.modules.maven.util</friend>
<!-- JShel support -->
<friend>org.netbeans.modules.jshell.support</friend>
+ <!-- Micronaut support -->
+ <friend>org.netbeans.modules.micronaut</friend>
Review comment:
Can this be avoided please? What functionality the micronaut module
needs from Maven? Can it be exposed via `java/api.maven/` module instead?
##########
File path:
enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigProperties.java
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.micronaut;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.netbeans.api.java.classpath.ClassPath;
+import org.netbeans.api.java.project.JavaProjectConstants;
+import org.netbeans.api.project.Project;
+import org.netbeans.api.project.ProjectUtils;
+import org.netbeans.api.project.SourceGroup;
+import org.netbeans.spi.project.ProjectServiceProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.Exceptions;
+import
org.springframework.boot.configurationmetadata.ConfigurationMetadataGroup;
+import
org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
+import
org.springframework.boot.configurationmetadata.ConfigurationMetadataRepository;
+import
org.springframework.boot.configurationmetadata.ConfigurationMetadataRepositoryJsonBuilder;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+@ProjectServiceProvider(
+ service = MicronautConfigProperties.class,
+ projectType = {
+ "org-netbeans-modules-maven",
+ "org-netbeans-modules-gradle"
+ }
+)
+public class MicronautConfigProperties {
Review comment:
Is this some form of caching per project instance?
##########
File path:
enterprise/micronaut/src/org/netbeans/modules/micronaut/MicronautConfigCompletionItem.java
##########
@@ -0,0 +1,302 @@
+/*
+ * 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.micronaut;
+
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.event.InputEvent;
+import java.awt.event.KeyEvent;
+import java.util.regex.Pattern;
+import javax.swing.ImageIcon;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.completion.Completion;
+import org.netbeans.api.editor.document.LineDocument;
+import org.netbeans.api.editor.document.LineDocumentUtils;
+import org.netbeans.lib.editor.codetemplates.api.CodeTemplateManager;
+import org.netbeans.lib.editor.util.ArrayUtilities;
+import org.netbeans.modules.editor.indent.api.IndentUtils;
+import org.netbeans.spi.editor.completion.CompletionItem;
+import org.netbeans.spi.editor.completion.CompletionTask;
+import org.netbeans.spi.editor.completion.support.CompletionUtilities;
+import org.netbeans.swing.plaf.LFCustoms;
+import org.openide.util.Exceptions;
+import org.openide.util.ImageUtilities;
+import org.openide.xml.XMLUtil;
+import
org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty;
+
+/**
+ *
+ * @author Dusan Balek
+ */
+public abstract class MicronautConfigCompletionItem implements CompletionItem {
Review comment:
Ideally it should be enough to provide just
`MicronautConfigCompletionCollector`. This source file could be deleted. The
appropriate `CompletionItem` would be constructed by the `editor.completion`
module itself based on the values provided via `Completion` from the collector.
Such simplification may wait for another PR, but it would be good to know it
is going to be possible.
##########
File path:
enterprise/micronaut/src/org/netbeans/modules/micronaut/newproject/BasePropertiesWizardPanel.java
##########
@@ -0,0 +1,108 @@
+/*
+ * 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.micronaut.newproject;
+
+import java.awt.Component;
+import javax.swing.event.ChangeListener;
+import org.openide.WizardDescriptor;
+import org.openide.WizardValidationException;
+import org.openide.util.ChangeSupport;
+import org.openide.util.HelpCtx;
+import org.openide.util.NbBundle;
+
+/**
+ * Wizard descriptor for Base Properties step in Micronaut project wizard.
+ *
+ * @author Dusan Balek
+ */
+public class BasePropertiesWizardPanel implements
WizardDescriptor.ValidatingPanel<WizardDescriptor>,
WizardDescriptor.FinishablePanel<WizardDescriptor> {
Review comment:
Ideally, we could generate the Swing wizard from some lower level
components reusable in VSNetBeans as well.
##########
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:
Can we live without `getTextEdit` and only use `getInsertText` and
`additionalTextEdits`? We don't have to carry the history of LSP and repeat
their mistakes one by one.
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
Review comment:
What this is good for? Can we live without it?
##########
File path:
ide/editor.lib/src/org/netbeans/lib/editor/hyperlink/spi/HyperlinkProviderExt.java
##########
@@ -125,5 +126,17 @@
* @since 1.18
*/
String getTooltipText(Document doc, int offset, HyperlinkType type);
-
+
+ /**
+ * Returns hyperlink target location.
+ *
+ * @param doc document on which to operate.
+ * @param offset >=0 offset to test (it generally should be offset <
doc.getLength(), but
+ * the implementations should not depend on it)
+ * @param type the hyperlink type
+ * @return 4.20
+ */
+ default CompletableFuture<HyperlinkLocation> getHyperlinkLocation(Document
doc, int offset, HyperlinkType type) {
Review comment:
Adding default method is an option, but we have added new
`CompletionCollector` interface. Shoudn't we rather add new interface
`HyperlinkLocation.Provider extends HyperlinkProviderExt` as well?
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ /**
+ * A human-readable string with additional information
+ * about this completion, like type or symbol information.
+ */
+ @NonNull
+ public Builder detail(@NonNull String detail) {
+ this.detail = detail;
+ return this;
+ }
+
+ /**
+ * A human-readable string that represents a doc-comment.
+ */
+ @NonNull
+ public Builder documentation(@NonNull String documentation) {
+ this.documentation = documentation;
+ return this;
+ }
+
+ /**
+ * Select this completion when showing.
+ */
+ @NonNull
+ public Builder preselect(boolean preselect) {
+ this.preselect = preselect;
+ return this;
+ }
+
+ /**
+ * A string that should be used when comparing this completion
with other
+ * completions. When {@code null} the label is used as the sort
text.
+ */
+ @NonNull
+ public Builder sortText(@NonNull String sortText) {
+ this.sortText = sortText;
+ return this;
+ }
+
+ /**
+ * A string that should be used when filtering a set of
completions.
+ * When {@code null} the label is used as the filter.
+ */
+ @NonNull
+ public Builder filterText(@NonNull String filterText) {
+ this.filterText = filterText;
+ return this;
+ }
+
+ /**
+ * A string that should be inserted into a document when selecting
+ * this completion. When {@code null} the label is used as the
insert text.
+ */
+ @NonNull
+ public Builder insertText(@NonNull String insertText) {
+ this.insertText = insertText;
+ return this;
+ }
+
+ /**
+ * 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}.
+ */
+ @NonNull
+ public Builder insertTextFormat(@NonNull TextFormat
insertTextFormat) {
+ this.insertTextFormat = insertTextFormat;
+ return this;
+ }
+
+ /**
+ * 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.
+ */
+ @NonNull
+ public Builder textEdit(@NonNull TextEdit textEdit) {
+ this.textEdit = textEdit;
+ return this;
+ }
+
+ /**
+ * 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).
+ */
+ @NonNull
+ public Builder additionalTextEdits(@NonNull List<TextEdit>
additionalTextEdits) {
Review comment:
Consider making this cumulative. something like `addTextEdit(TextEdit)`
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
Review comment:
`Set<Character>` is the proper type, I guess. The warnings can be
removed from the Javadoc.
##########
File path: ide/libs.bytelist/nbproject/project.xml
##########
@@ -24,7 +24,15 @@
<configuration>
<data xmlns="http://www.netbeans.org/ns/nb-module-project/2">
<code-name-base>org.netbeans.libs.bytelist</code-name-base>
- <module-dependencies/>
+ <module-dependencies>
+ <dependency>
+ <code-name-base>org.netbeans.libs.jcodings</code-name-base>
Review comment:
Extracting this library shared between two modules is a good move.
Please also remove a reference to it from
`nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ignored-overlaps`.
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ /**
+ * A human-readable string with additional information
+ * about this completion, like type or symbol information.
+ */
+ @NonNull
+ public Builder detail(@NonNull String detail) {
+ this.detail = detail;
+ return this;
+ }
+
+ /**
+ * A human-readable string that represents a doc-comment.
+ */
+ @NonNull
+ public Builder documentation(@NonNull String documentation) {
+ this.documentation = documentation;
+ return this;
+ }
+
+ /**
+ * Select this completion when showing.
+ */
+ @NonNull
+ public Builder preselect(boolean preselect) {
+ this.preselect = preselect;
+ return this;
+ }
+
+ /**
+ * A string that should be used when comparing this completion
with other
+ * completions. When {@code null} the label is used as the sort
text.
+ */
+ @NonNull
+ public Builder sortText(@NonNull String sortText) {
+ this.sortText = sortText;
+ return this;
+ }
+
+ /**
+ * A string that should be used when filtering a set of
completions.
+ * When {@code null} the label is used as the filter.
+ */
+ @NonNull
+ public Builder filterText(@NonNull String filterText) {
+ this.filterText = filterText;
+ return this;
+ }
+
+ /**
+ * A string that should be inserted into a document when selecting
+ * this completion. When {@code null} the label is used as the
insert text.
+ */
+ @NonNull
+ public Builder insertText(@NonNull String insertText) {
+ this.insertText = insertText;
+ return this;
+ }
+
+ /**
+ * 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}.
+ */
+ @NonNull
+ public Builder insertTextFormat(@NonNull TextFormat
insertTextFormat) {
+ this.insertTextFormat = insertTextFormat;
+ return this;
+ }
+
+ /**
+ * 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.
+ */
+ @NonNull
+ public Builder textEdit(@NonNull TextEdit textEdit) {
+ this.textEdit = textEdit;
+ return this;
+ }
+
+ /**
+ * 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).
+ */
+ @NonNull
+ public Builder additionalTextEdits(@NonNull List<TextEdit>
additionalTextEdits) {
+ this.additionalTextEdits = additionalTextEdits;
+ return this;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @NonNull
+ public Builder commitCharacters(@NonNull List<String>
commitCharacters) {
+ this.commitCharacters = commitCharacters;
+ return this;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @NonNull
+ public Builder command(@NonNull Command command) {
+ this.command = command;
+ return this;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @NonNull
+ public Builder data(@NonNull Object data) {
Review comment:
I'd like to see a use-case for this method. It is quite poorly typed
right now and I guess we can be better.
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
Review comment:
`tags(Tag... tags)` I'd say. Maybe even make cumullatible - e.g. calling
`tags` or `addTags` multiple times adds to previous tags. CCing @sdedic as
Sváťa recently designed such builder API in `extexecution` module.
##########
File path: nbbuild/antsrc/org/netbeans/nbbuild/extlibs/ignored-overlaps
##########
@@ -82,9 +82,6 @@ enterprise/javaee7.api/external/javax.annotation-api-1.2.jar
enterprise/websvc.r
enterprise/javaee7.api/external/jaxws-api-2.2.8.jar
java/websvc.jaxws21api/external/jaxws-2.2.6-api.zip
enterprise/javaee7.api/external/jsr181-api-1.0-MR1.jar
java/websvc.jaxws21api/external/jaxws-2.2.6-api.zip
-# the jcodings is used internally in two unrelated modules:
-ide/libs.bytelist/external/jcodings-1.0.18.jar
ide/textmate.lexer/external/jcodings-1.0.18.jar
-
Review comment:
Turning `jcodings` into its own module is great.
##########
File path:
java/java.sourceui/src/org/netbeans/api/java/source/ui/ElementOpen.java
##########
@@ -276,12 +281,85 @@ public void run(CompilationController cc) throws
Exception {
}
}
+ /**
+ * Gets location of the {@link Element} corresponding to the given {@link
ElementHandle}.
+ *
+ * @param cpInfo ClasspathInfo which should be used for the search
+ * @param el ElementHandle to search
+ * @param resourceName optional resource name to search
+ * @return location of the given element
+ *
+ * @since 1.58
+ */
+ public static CompletableFuture<HyperlinkLocation> getLocation(final
ClasspathInfo cpInfo, final ElementHandle<? extends Element> el, String
resourceName) {
Review comment:
Is there an `apichange.xml` entry?
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ /**
+ * A human-readable string with additional information
+ * about this completion, like type or symbol information.
+ */
+ @NonNull
+ public Builder detail(@NonNull String detail) {
+ this.detail = detail;
+ return this;
+ }
+
+ /**
+ * A human-readable string that represents a doc-comment.
+ */
+ @NonNull
+ public Builder documentation(@NonNull String documentation) {
+ this.documentation = documentation;
+ return this;
+ }
+
+ /**
+ * Select this completion when showing.
+ */
+ @NonNull
+ public Builder preselect(boolean preselect) {
+ this.preselect = preselect;
+ return this;
+ }
+
+ /**
+ * A string that should be used when comparing this completion
with other
+ * completions. When {@code null} the label is used as the sort
text.
+ */
+ @NonNull
+ public Builder sortText(@NonNull String sortText) {
+ this.sortText = sortText;
+ return this;
+ }
+
+ /**
+ * A string that should be used when filtering a set of
completions.
+ * When {@code null} the label is used as the filter.
+ */
+ @NonNull
+ public Builder filterText(@NonNull String filterText) {
+ this.filterText = filterText;
+ return this;
+ }
+
+ /**
+ * A string that should be inserted into a document when selecting
+ * this completion. When {@code null} the label is used as the
insert text.
+ */
+ @NonNull
+ public Builder insertText(@NonNull String insertText) {
+ this.insertText = insertText;
+ return this;
+ }
+
+ /**
+ * 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}.
+ */
+ @NonNull
+ public Builder insertTextFormat(@NonNull TextFormat
insertTextFormat) {
+ this.insertTextFormat = insertTextFormat;
+ return this;
+ }
+
+ /**
+ * 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.
+ */
+ @NonNull
+ public Builder textEdit(@NonNull TextEdit textEdit) {
+ this.textEdit = textEdit;
+ return this;
+ }
+
+ /**
+ * 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).
+ */
+ @NonNull
+ public Builder additionalTextEdits(@NonNull List<TextEdit>
additionalTextEdits) {
+ this.additionalTextEdits = additionalTextEdits;
+ return this;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @NonNull
+ public Builder commitCharacters(@NonNull List<String>
commitCharacters) {
+ this.commitCharacters = commitCharacters;
+ return this;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @NonNull
+ public Builder command(@NonNull Command command) {
+ this.command = command;
+ return this;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @NonNull
+ public Builder data(@NonNull Object data) {
+ this.data = data;
+ return this;
+ }
+
+ /**
+ * Builds completion.
+ */
+ @NonNull
+ public Completion build() {
+ return new Completion(label, kind, tags, detail,
documentation, preselect,
+ sortText, filterText, insertText, insertTextFormat,
textEdit,
+ additionalTextEdits, commitCharacters, command, data);
+ }
+ }
+ }
+
+ public static enum Kind {
+
+ Text(1),
+ Method(2),
+ Function(3),
+ Constructor(4),
+ Field(5),
+ Variable(6),
+ Class(7),
+ Interface(8),
+ Module(9),
+ Property(10),
+ Unit(11),
+ Value(12),
+ Enum(13),
+ Keyword(14),
+ Snippet(15),
+ Color(16),
+ File(17),
+ Reference(18),
+ Folder(19),
+ EnumMember(20),
+ Constant(21),
+ Struct(22),
+ Event(23),
+ Operator(24),
+ TypeParameter(25);
+
+ private final int value;
+
+ private Kind(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public static enum Tag {
+
+ Deprecated(1);
+
+ private final int value;
+
+ private Tag(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public static enum TextFormat {
+
+ /**
+ * The primary text to be inserted is treated as a plain string.
+ */
+ PlainText(1),
+
+ /**
+ * The primary text to be inserted is treated as a snippet.
+ */
+ Snippet(2);
+
+ private final int value;
+
+ private TextFormat(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public static final class TextEdit {
+
+ private final int start;
+ private final int end;
+ private final String newText;
+
+ public TextEdit(int start, int end, @NonNull String newText) {
+ this.start = start;
+ this.end = end;
+ this.newText = newText;
+ }
+
+ /**
+ * The start offset of the text document range to be manipulated. To
insert
+ * text into a document create edit where {@code startOffset ==
endOffset}.
+ */
+ public int getStartOffset() {
+ return start;
+ }
+
+ /**
+ * The end offset of the text document range to be manipulated. To
insert
+ * text into a document create edit where {@code startOffset ==
endOffset}.
+ */
+ public int getEndOffset() {
+ return end;
+ }
+
+ /**
+ * The string to be inserted. For delete operations use an empty
string.
+ */
+ @NonNull
+ public String getNewText() {
+ return newText;
+ }
+ }
+
+ public static final class Command {
+
+ private final String title;
+ private final String command;
+ private final List<Object> arguments;
+
+ public Command(@NonNull String title, @NonNull String command,
@NullAllowed List<Object> arguments) {
Review comment:
What can be the types of `arguments`? Any `Object`?
##########
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() {
+ 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 List<TextEdit> getAdditionalTextEdits() {
+ return additionalTextEdits;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @CheckForNull
+ public List<String> getCommitCharacters() {
+ return commitCharacters;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @CheckForNull
+ public Command getCommand() {
+ return command;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @CheckForNull
+ public Object getData() {
+ return data;
+ }
+
+ public static final class Builder {
+
+ private final String label;
+ private Kind kind;
+ private List<Tag> tags;
+ private String detail;
+ private String documentation;
+ private boolean preselect;
+ private String sortText;
+ private String filterText;
+ private String insertText;
+ private TextFormat insertTextFormat;
+ private TextEdit textEdit;
+ private List<TextEdit> additionalTextEdits;
+ private List<String> commitCharacters;
+ private Command command;
+ private Object data;
+
+ private Builder(@NonNull String label) {
+ this.label = label;
+ }
+
+ /**
+ * The kind of this completion.
+ */
+ @NonNull
+ public Builder kind(@NonNull Kind kind) {
+ this.kind = kind;
+ return this;
+ }
+
+ /**
+ * Tags for this completion.
+ */
+ @NonNull
+ public Builder tags(@NonNull List<Tag> tags) {
+ this.tags = tags;
+ return this;
+ }
+
+ /**
+ * A human-readable string with additional information
+ * about this completion, like type or symbol information.
+ */
+ @NonNull
+ public Builder detail(@NonNull String detail) {
+ this.detail = detail;
+ return this;
+ }
+
+ /**
+ * A human-readable string that represents a doc-comment.
+ */
+ @NonNull
+ public Builder documentation(@NonNull String documentation) {
+ this.documentation = documentation;
+ return this;
+ }
+
+ /**
+ * Select this completion when showing.
+ */
+ @NonNull
+ public Builder preselect(boolean preselect) {
+ this.preselect = preselect;
+ return this;
+ }
+
+ /**
+ * A string that should be used when comparing this completion
with other
+ * completions. When {@code null} the label is used as the sort
text.
+ */
+ @NonNull
+ public Builder sortText(@NonNull String sortText) {
+ this.sortText = sortText;
+ return this;
+ }
+
+ /**
+ * A string that should be used when filtering a set of
completions.
+ * When {@code null} the label is used as the filter.
+ */
+ @NonNull
+ public Builder filterText(@NonNull String filterText) {
+ this.filterText = filterText;
+ return this;
+ }
+
+ /**
+ * A string that should be inserted into a document when selecting
+ * this completion. When {@code null} the label is used as the
insert text.
+ */
+ @NonNull
+ public Builder insertText(@NonNull String insertText) {
+ this.insertText = insertText;
+ return this;
+ }
+
+ /**
+ * 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}.
+ */
+ @NonNull
+ public Builder insertTextFormat(@NonNull TextFormat
insertTextFormat) {
+ this.insertTextFormat = insertTextFormat;
+ return this;
+ }
+
+ /**
+ * 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.
+ */
+ @NonNull
+ public Builder textEdit(@NonNull TextEdit textEdit) {
+ this.textEdit = textEdit;
+ return this;
+ }
+
+ /**
+ * 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).
+ */
+ @NonNull
+ public Builder additionalTextEdits(@NonNull List<TextEdit>
additionalTextEdits) {
+ this.additionalTextEdits = additionalTextEdits;
+ return this;
+ }
+
+ /**
+ * A list of characters that when pressed while this completion is
+ * active will accept it first and then type that character. All
+ * commit characters should have length one and that superfluous
+ * characters will be ignored.
+ */
+ @NonNull
+ public Builder commitCharacters(@NonNull List<String>
commitCharacters) {
+ this.commitCharacters = commitCharacters;
+ return this;
+ }
+
+ /**
+ * A command that is executed after inserting this completion.
+ */
+ @NonNull
+ public Builder command(@NonNull Command command) {
+ this.command = command;
+ return this;
+ }
+
+ /**
+ * A data entry to identify this completion.
+ */
+ @NonNull
+ public Builder data(@NonNull Object data) {
+ this.data = data;
+ return this;
+ }
+
+ /**
+ * Builds completion.
+ */
+ @NonNull
+ public Completion build() {
+ return new Completion(label, kind, tags, detail,
documentation, preselect,
+ sortText, filterText, insertText, insertTextFormat,
textEdit,
+ additionalTextEdits, commitCharacters, command, data);
+ }
+ }
+ }
+
+ public static enum Kind {
+
+ Text(1),
+ Method(2),
+ Function(3),
+ Constructor(4),
+ Field(5),
+ Variable(6),
+ Class(7),
+ Interface(8),
+ Module(9),
+ Property(10),
+ Unit(11),
+ Value(12),
+ Enum(13),
+ Keyword(14),
+ Snippet(15),
+ Color(16),
+ File(17),
+ Reference(18),
+ Folder(19),
+ EnumMember(20),
+ Constant(21),
+ Struct(22),
+ Event(23),
+ Operator(24),
+ TypeParameter(25);
+
+ private final int value;
+
+ private Kind(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public static enum Tag {
+
+ Deprecated(1);
+
+ private final int value;
+
+ private Tag(int value) {
+ this.value = value;
+ }
+
+ public int getValue() {
+ return value;
+ }
+ }
+
+ public static enum TextFormat {
+
+ /**
+ * The primary text to be inserted is treated as a plain string.
+ */
+ PlainText(1),
+
+ /**
+ * The primary text to be inserted is treated as a snippet.
+ */
+ Snippet(2);
Review comment:
Can we only support Snippets in this API? One can simulate `PlainText`
via `Snippet` with no parameters, right?
----------------------------------------------------------------
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