mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 16:28:56 +00:00
[lsp] introduced Contentassistentry#documentation, pad sortText.
This commit is contained in:
parent
7c51af4e58
commit
9f39754cba
6 changed files with 52 additions and 6 deletions
|
@ -43,6 +43,12 @@ class ContentAssistEntry {
|
|||
*/
|
||||
String description
|
||||
|
||||
/**
|
||||
* Documentation for the proposal proposals.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
String documentation
|
||||
|
||||
/**
|
||||
* The absolute cursor position to apply after the proposal has been inserted.
|
||||
* If omitted, the cursor it set to the end of the inserted proposal.
|
||||
|
|
|
@ -78,6 +78,7 @@ import org.eclipse.xtext.resource.IResourceServiceProvider
|
|||
import org.eclipse.xtext.service.OperationCanceledManager
|
||||
import org.eclipse.xtext.util.CancelIndicator
|
||||
import org.eclipse.xtext.validation.Issue
|
||||
import com.google.common.base.Strings
|
||||
|
||||
/**
|
||||
* @author Sven Efftinge - Initial contribution and API
|
||||
|
@ -303,7 +304,7 @@ import org.eclipse.xtext.validation.Issue
|
|||
val completionItems = newArrayList
|
||||
acceptor.getEntries().forEach[it, idx|
|
||||
val item = toCompletionItem(caretOffset, caretPosition, document)
|
||||
item.sortText = ''+idx
|
||||
item.sortText = Strings.padStart(''+idx, 5, "0")
|
||||
completionItems += item
|
||||
]
|
||||
return completionItems
|
||||
|
@ -316,6 +317,7 @@ import org.eclipse.xtext.validation.Issue
|
|||
val completionItem = new CompletionItemImpl
|
||||
completionItem.label = entry.label ?: entry.proposal
|
||||
completionItem.detail = entry.description
|
||||
completionItem.documentation = entry.documentation
|
||||
val prefixOffset = caretOffset - (entry.prefix?:'').length
|
||||
val prefixPosition = document.getPosition(prefixOffset)
|
||||
completionItem.textEdit = new TextEditImpl(new RangeImpl(prefixPosition, caretPosition), entry.proposal)
|
||||
|
|
|
@ -45,6 +45,12 @@ public class ContentAssistEntry {
|
|||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* Documentation for the proposal proposals.
|
||||
* <p>This property may not be supported by all editor frameworks.</p>
|
||||
*/
|
||||
private String documentation;
|
||||
|
||||
/**
|
||||
* The absolute cursor position to apply after the proposal has been inserted.
|
||||
* If omitted, the cursor it set to the end of the inserted proposal.
|
||||
|
@ -152,6 +158,15 @@ public class ContentAssistEntry {
|
|||
this.description = description;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public String getDocumentation() {
|
||||
return this.documentation;
|
||||
}
|
||||
|
||||
public void setDocumentation(final String documentation) {
|
||||
this.documentation = documentation;
|
||||
}
|
||||
|
||||
@Pure
|
||||
public Integer getEscapePosition() {
|
||||
return this.escapePosition;
|
||||
|
@ -198,6 +213,7 @@ public class ContentAssistEntry {
|
|||
b.add("proposal", this.proposal);
|
||||
b.add("label", this.label);
|
||||
b.add("description", this.description);
|
||||
b.add("documentation", this.documentation);
|
||||
b.add("escapePosition", this.escapePosition);
|
||||
b.add("textReplacements", this.textReplacements);
|
||||
b.add("editPositions", this.editPositions);
|
||||
|
@ -235,6 +251,11 @@ public class ContentAssistEntry {
|
|||
return false;
|
||||
} else if (!this.description.equals(other.description))
|
||||
return false;
|
||||
if (this.documentation == null) {
|
||||
if (other.documentation != null)
|
||||
return false;
|
||||
} else if (!this.documentation.equals(other.documentation))
|
||||
return false;
|
||||
if (this.escapePosition == null) {
|
||||
if (other.escapePosition != null)
|
||||
return false;
|
||||
|
@ -267,6 +288,7 @@ public class ContentAssistEntry {
|
|||
result = prime * result + ((this.proposal== null) ? 0 : this.proposal.hashCode());
|
||||
result = prime * result + ((this.label== null) ? 0 : this.label.hashCode());
|
||||
result = prime * result + ((this.description== null) ? 0 : this.description.hashCode());
|
||||
result = prime * result + ((this.documentation== null) ? 0 : this.documentation.hashCode());
|
||||
result = prime * result + ((this.escapePosition== null) ? 0 : this.escapePosition.hashCode());
|
||||
result = prime * result + ((this.textReplacements== null) ? 0 : this.textReplacements.hashCode());
|
||||
result = prime * result + ((this.editPositions== null) ? 0 : this.editPositions.hashCode());
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
*/
|
||||
package org.eclipse.xtext.ide.server;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
|
@ -482,7 +483,8 @@ public class LanguageServerImpl implements LanguageServer, WorkspaceService, Win
|
|||
Iterable<ContentAssistEntry> _entries = acceptor.getEntries();
|
||||
final Procedure2<ContentAssistEntry, Integer> _function_2 = (ContentAssistEntry it, Integer idx) -> {
|
||||
final CompletionItemImpl item = this.toCompletionItem(it, caretOffset, caretPosition, document);
|
||||
item.setSortText(("" + idx));
|
||||
String _padStart = Strings.padStart(("" + idx), 5, '0');
|
||||
item.setSortText(_padStart);
|
||||
completionItems.add(item);
|
||||
};
|
||||
IterableExtensions.<ContentAssistEntry>forEach(_entries, _function_2);
|
||||
|
@ -511,6 +513,8 @@ public class LanguageServerImpl implements LanguageServer, WorkspaceService, Win
|
|||
completionItem.setLabel(_elvis);
|
||||
String _description = entry.getDescription();
|
||||
completionItem.setDetail(_description);
|
||||
String _documentation = entry.getDocumentation();
|
||||
completionItem.setDocumentation(_documentation);
|
||||
String _elvis_1 = null;
|
||||
String _prefix = entry.getPrefix();
|
||||
if (_prefix != null) {
|
||||
|
|
|
@ -261,8 +261,12 @@ abstract class AbstractLanguageServerTest implements Consumer<PublishDiagnostics
|
|||
textDocument(filePath)
|
||||
position(line, column)
|
||||
].build)
|
||||
|
||||
// assert ordered by sortText
|
||||
val list = completionItems.get
|
||||
Assert.assertEquals(list.items, list.items.sortBy[sortText].toList)
|
||||
|
||||
val actualCompletionItems = completionItems.get.items.toExpectation
|
||||
val actualCompletionItems = list.items.toExpectation
|
||||
assertEquals(expectedCompletionItems, actualCompletionItems)
|
||||
}
|
||||
|
||||
|
|
|
@ -533,9 +533,17 @@ public abstract class AbstractLanguageServerTest implements Consumer<PublishDiag
|
|||
TextDocumentPositionParamsBuilder _textDocumentPositionParamsBuilder = new TextDocumentPositionParamsBuilder(_function);
|
||||
TextDocumentPositionParams _build = _textDocumentPositionParamsBuilder.build();
|
||||
final CompletableFuture<CompletionList> completionItems = this.languageServer.completion(_build);
|
||||
CompletionList _get = completionItems.get();
|
||||
List<? extends CompletionItem> _items = _get.getItems();
|
||||
final String actualCompletionItems = this.toExpectation(_items);
|
||||
final CompletionList list = completionItems.get();
|
||||
List<? extends CompletionItem> _items = list.getItems();
|
||||
List<? extends CompletionItem> _items_1 = list.getItems();
|
||||
final Function1<CompletionItem, String> _function_1 = (CompletionItem it) -> {
|
||||
return it.getSortText();
|
||||
};
|
||||
List<? extends CompletionItem> _sortBy = IterableExtensions.sortBy(_items_1, _function_1);
|
||||
List<? extends CompletionItem> _list = IterableExtensions.toList(_sortBy);
|
||||
Assert.assertEquals(_items, _list);
|
||||
List<? extends CompletionItem> _items_2 = list.getItems();
|
||||
final String actualCompletionItems = this.toExpectation(_items_2);
|
||||
String _expectedCompletionItems = configuration.getExpectedCompletionItems();
|
||||
this.assertEquals(_expectedCompletionItems, actualCompletionItems);
|
||||
} catch (Throwable _e) {
|
||||
|
|
Loading…
Reference in a new issue