PT #165432307: Properly set insertion format for document edits
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Pivotal, Inc.
|
||||
* Copyright (c) 2015, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -322,6 +322,7 @@ public class DocumentEdits implements ProposalApplier {
|
||||
|
||||
private List<Edit> edits = new ArrayList<Edit>();
|
||||
private IDocument doc;
|
||||
final private boolean hasSnippets;
|
||||
|
||||
/**
|
||||
* When this is true, the cursor is moved after each edit, to be positioned right after the
|
||||
@@ -332,8 +333,9 @@ public class DocumentEdits implements ProposalApplier {
|
||||
*/
|
||||
private boolean grabCursor = true;
|
||||
|
||||
public DocumentEdits(IDocument doc) {
|
||||
public DocumentEdits(IDocument doc, boolean hasSnippets) {
|
||||
this.doc = doc;
|
||||
this.hasSnippets = hasSnippets;
|
||||
}
|
||||
|
||||
public void delete(int start, int end) {
|
||||
@@ -493,4 +495,9 @@ public class DocumentEdits implements ProposalApplier {
|
||||
public boolean hasRelativeIndents() {
|
||||
return true;
|
||||
}
|
||||
|
||||
final public boolean hasSnippets() {
|
||||
return hasSnippets;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ package org.springframework.ide.vscode.commons.languageserver.completion;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItemKind;
|
||||
import org.eclipse.lsp4j.InsertTextFormat;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
|
||||
/**
|
||||
@@ -38,8 +37,6 @@ public interface ICompletionProposal {
|
||||
*/
|
||||
default ICompletionProposal deemphasize(double howmuch) { return this; }
|
||||
|
||||
default InsertTextFormat getInsertTextFormat() { return InsertTextFormat.Snippet; }
|
||||
|
||||
default boolean isDeprecated() { return false; }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -77,7 +77,7 @@ public class SimpleCompletionFactory {
|
||||
}
|
||||
|
||||
public static SimpleProposal simpleProposal(IDocument doc, int offset, String query, CompletionItemKind kind, String value, String detail, Renderable info) {
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(offset-query.length(), offset, value);
|
||||
return new SimpleProposal(edits, kind, info, detail, value);
|
||||
}
|
||||
|
||||
@@ -17,10 +17,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItem;
|
||||
import org.eclipse.lsp4j.CompletionList;
|
||||
import org.eclipse.lsp4j.InsertTextFormat;
|
||||
import org.eclipse.lsp4j.MarkupContent;
|
||||
import org.eclipse.lsp4j.MarkupKind;
|
||||
import org.eclipse.lsp4j.Position;
|
||||
@@ -29,8 +31,6 @@ import org.eclipse.lsp4j.TextEdit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits.TextReplace;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LspClient;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.LspClient.Client;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SortKeys;
|
||||
@@ -217,16 +217,21 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
}
|
||||
|
||||
private void resolveEdits(TextDocument doc, ICompletionProposal completion, CompletionItem item) {
|
||||
Optional<TextEdit> mainEdit = adaptEdits(doc, completion.getTextEdit());
|
||||
AtomicBoolean usedSnippets = new AtomicBoolean();
|
||||
Optional<TextEdit> mainEdit = adaptEdits(doc, completion.getTextEdit(), usedSnippets);
|
||||
if (mainEdit.isPresent()) {
|
||||
item.setTextEdit(mainEdit.get());
|
||||
item.setInsertTextFormat(completion.getInsertTextFormat());
|
||||
if (server.hasCompletionSnippetSupport()) {
|
||||
item.setInsertTextFormat(usedSnippets.get() ? InsertTextFormat.Snippet : InsertTextFormat.PlainText);
|
||||
} else {
|
||||
item.setInsertTextFormat(InsertTextFormat.PlainText);
|
||||
}
|
||||
} else {
|
||||
item.setInsertText("");
|
||||
}
|
||||
|
||||
completion.getAdditionalEdit().ifPresent(edit -> {
|
||||
adaptEdits(doc, edit).ifPresent(extraEdit -> {
|
||||
adaptEdits(doc, edit, null).ifPresent(extraEdit -> {
|
||||
item.setAdditionalTextEdits(ImmutableList.of(extraEdit));
|
||||
});
|
||||
});
|
||||
@@ -239,9 +244,12 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
return null;
|
||||
}
|
||||
|
||||
private Optional<TextEdit> adaptEdits(TextDocument doc, DocumentEdits edits) {
|
||||
private Optional<TextEdit> adaptEdits(TextDocument doc, DocumentEdits edits, AtomicBoolean usedSnippets) {
|
||||
try {
|
||||
TextReplace replaceEdit = edits.asReplacement(doc);
|
||||
if (usedSnippets != null) {
|
||||
usedSnippets.set(edits.hasSnippets());
|
||||
}
|
||||
if (replaceEdit==null) {
|
||||
//The original edit does nothing.
|
||||
return Optional.empty();
|
||||
@@ -252,25 +260,23 @@ public class VscodeCompletionEngineAdapter implements VscodeCompletionEngine {
|
||||
vscodeEdit.setRange(doc.toRange(replaceEdit.start, replaceEdit.end-replaceEdit.start));
|
||||
String newText = replaceEdit.newText;
|
||||
IRegion selection = edits.getSelection();
|
||||
if (selection!=null) {
|
||||
if (selection!=null && usedSnippets != null) {
|
||||
//Special handling for the case where cursor is *not* just at the end of the newText
|
||||
int cursor = selection.getOffset() + selection.getLength();
|
||||
cursor = cursor - replaceEdit.start;
|
||||
if (cursor<newText.length()) {
|
||||
if (cursor < newText.length() && !edits.hasSnippets()) {
|
||||
newText = server.createSnippetBuilder()
|
||||
.text(newText.substring(0, cursor))
|
||||
.finalTabStop()
|
||||
.text(newText.substring(cursor))
|
||||
.build()
|
||||
.toString();
|
||||
usedSnippets.set(true);
|
||||
}
|
||||
}
|
||||
if (isMagicIndentingClient()) {
|
||||
newText = vscodeIndentFix(doc, vscodeEdit.getRange().getStart(), replaceEdit.newText);
|
||||
}
|
||||
if (LspClient.currentClient() == Client.THEIA || LspClient.currentClient() == Client.VSCODE) {
|
||||
newText = newText.replace("$", "\\$");
|
||||
}
|
||||
vscodeEdit.setNewText(newText);
|
||||
return Optional.of(vscodeEdit);
|
||||
}
|
||||
|
||||
@@ -713,4 +713,9 @@ public final class SimpleLanguageServer implements Sts4LanguageServer, LanguageC
|
||||
public boolean hasHierarchicalDocumentSymbolSupport() {
|
||||
return hasHierarchicalDocumentSymbolSupport;
|
||||
}
|
||||
|
||||
final public boolean hasCompletionSnippetSupport() {
|
||||
return hasCompletionSnippetSupport;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -156,7 +156,7 @@ public class DefaultCompletionFactory implements CompletionFactory {
|
||||
|
||||
@Override
|
||||
public DocumentEdits getTextEdit() {
|
||||
return new DocumentEdits(null);
|
||||
return new DocumentEdits(null, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2016 Pivotal, Inc.
|
||||
* Copyright (c) 2016, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -125,7 +125,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
|
||||
private DocumentEdits createEditFromSnippet(YamlDocument doc, SNode node, int offset, String query, YamlIndentUtil indenter,
|
||||
Snippet _snippet) throws Exception {
|
||||
DocumentEdits edits = new DocumentEdits(doc.getDocument());
|
||||
DocumentEdits edits = new DocumentEdits(doc.getDocument(), true);
|
||||
int start = offset - query.length();
|
||||
edits.delete(start, query);
|
||||
int referenceIndent = doc.getColumn(start);
|
||||
@@ -170,7 +170,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
edits = createEditFromSnippet(doc, node, offset, query, indenter, snippet);
|
||||
} else {
|
||||
//Generate edits the old-fashioned way
|
||||
edits = new DocumentEdits(doc.getDocument());
|
||||
edits = new DocumentEdits(doc.getDocument(), false);
|
||||
YType YType = p.getType();
|
||||
edits.delete(queryOffset, query);
|
||||
int referenceIndent = doc.getColumn(queryOffset);
|
||||
@@ -273,7 +273,7 @@ public class YTypeAssistContext extends AbstractYamlAssistContext {
|
||||
double score = FuzzyMatcher.matchScore(query, value.getValue());
|
||||
if (score!=0 && value!=null && !query.equals(value.getValue())) {
|
||||
int queryStart = offset-query.length();
|
||||
DocumentEdits edits = new DocumentEdits(doc.getDocument());
|
||||
DocumentEdits edits = new DocumentEdits(doc.getDocument(), false);
|
||||
edits.delete(queryStart, offset);
|
||||
if (!Character.isWhitespace(doc.getChar(queryStart-1))) {
|
||||
edits.insert(offset, " ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Pivotal, Inc.
|
||||
* Copyright (c) 2015, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -36,7 +36,7 @@ public class YamlPathEdits extends DocumentEdits {
|
||||
private YamlIndentUtil indentUtil;
|
||||
|
||||
public YamlPathEdits(YamlDocument doc) {
|
||||
super(doc.getDocument());
|
||||
super(doc.getDocument(), false);
|
||||
this.doc = doc;
|
||||
this.indentUtil = new YamlIndentUtil(doc);
|
||||
}
|
||||
|
||||
@@ -774,7 +774,7 @@ public class LanguageServerHarness {
|
||||
|
||||
TextDocument workingDocument = new TextDocument(uri, document.getLanguageId());
|
||||
workingDocument.setText(document.getText());
|
||||
DocumentEdits edits = new DocumentEdits(workingDocument);
|
||||
DocumentEdits edits = new DocumentEdits(workingDocument, false);
|
||||
for (TextEdit edit : entry.getValue()) {
|
||||
Range range = edit.getRange();
|
||||
edits.replace(document.toOffset(range.getStart()), document.toOffset(range.getEnd()), edit.getNewText());
|
||||
@@ -797,7 +797,7 @@ public class LanguageServerHarness {
|
||||
Path path = Paths.get(URI.create(uri));
|
||||
String content = docInfo == null ? IOUtil.toString(Files.newInputStream(path)) : docInfo.getText();
|
||||
TextDocument workingDocument = new TextDocument(uri, docInfo == null ? (LanguageId) null : docInfo.getLanguageId(), 0, content);
|
||||
DocumentEdits edits = new DocumentEdits(workingDocument);
|
||||
DocumentEdits edits = new DocumentEdits(workingDocument, false);
|
||||
for (TextEdit textEdit : docEdit.getEdits()) {
|
||||
Range range = textEdit.getRange();
|
||||
edits.replace(workingDocument.toOffset(range.getStart()), workingDocument.toOffset(range.getEnd()), textEdit.getNewText());
|
||||
|
||||
@@ -52,7 +52,7 @@ public class DocumentEditsTest {
|
||||
|
||||
public void reset() throws Exception {
|
||||
this.editor = harness.newEditor(orgText);
|
||||
this.edits = new DocumentEdits(getFreshDocument(editor));
|
||||
this.edits = new DocumentEdits(getFreshDocument(editor), false);
|
||||
}
|
||||
|
||||
private IDocument getFreshDocument(Editor editor) throws Exception {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -102,7 +102,7 @@ public class RouteContentAssistant implements ISubCompletionEngine {
|
||||
}
|
||||
|
||||
private ICompletionProposal createProposal(CompletionFactory f, DocumentRegion region, int offset, String query, double score, YValueHint domain) {
|
||||
DocumentEdits edits = new DocumentEdits(region.getDocument());
|
||||
DocumentEdits edits = new DocumentEdits(region.getDocument(), false);
|
||||
region = region.subSequence(offset - query.length());
|
||||
boolean needSpace = region.textBefore(1).charAt(0)==':'; //Add extra space after ':' if needed!
|
||||
edits.replace(region.getStart(), region.getEnd(), needSpace ? " "+domain.getValue() : domain.getValue());
|
||||
|
||||
@@ -17,7 +17,6 @@ import org.eclipse.jdt.core.dom.ASTNode;
|
||||
import org.eclipse.jdt.core.dom.Annotation;
|
||||
import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.TypeDeclaration;
|
||||
import org.eclipse.jdt.internal.core.util.ASTNodeFinder;
|
||||
import org.eclipse.lsp4j.CompletionItemKind;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.CompletionProvider;
|
||||
import org.springframework.ide.vscode.boot.java.utils.ASTUtils;
|
||||
@@ -72,7 +71,7 @@ public class DataRepositoryCompletionProcessor implements CompletionProvider {
|
||||
label.append(StringUtils.uncapitalize(domainProperty.getName()));
|
||||
label.append(");");
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(null);
|
||||
DocumentEdits edits = new DocumentEdits(null, false);
|
||||
|
||||
StringBuilder completion = new StringBuilder();
|
||||
completion.append("List<");
|
||||
@@ -97,7 +96,7 @@ public class DataRepositoryCompletionProcessor implements CompletionProvider {
|
||||
edits.insert(offset, completion.toString());
|
||||
}
|
||||
|
||||
DocumentEdits additionalEdits = new DocumentEdits(null);
|
||||
DocumentEdits additionalEdits = new DocumentEdits(null, false);
|
||||
return new FindByCompletionProposal(label.toString(), CompletionItemKind.Method, edits, null, null, Optional.of(additionalEdits), filter);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2018, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -13,11 +13,9 @@ package org.springframework.ide.vscode.boot.java.data;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItemKind;
|
||||
import org.eclipse.lsp4j.InsertTextFormat;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.text.IDocument;
|
||||
|
||||
public class FindByCompletionProposal implements ICompletionProposal {
|
||||
|
||||
@@ -71,11 +69,6 @@ public class FindByCompletionProposal implements ICompletionProposal {
|
||||
return additionalEdits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertTextFormat getInsertTextFormat() {
|
||||
return InsertTextFormat.Snippet;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFilterText() {
|
||||
return filter;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
/*******************************************************************************
|
||||
* Derived from:
|
||||
* org.eclipse.jdt.core.dom.rewrite.ImportRewrite
|
||||
*
|
||||
*
|
||||
* for use in STS4, where IProject and ICompilationUnit are not available when parsing a Java source.
|
||||
*
|
||||
*
|
||||
* Original license:
|
||||
*
|
||||
* Copyright (c) 2000, 2016 IBM Corporation and others.
|
||||
@@ -542,7 +542,7 @@ public final class ImportRewrite {
|
||||
|
||||
String[] createdImprts = getAddedImports();
|
||||
if (createdImprts != null && createdImprts.length >0) {
|
||||
edits =new DocumentEdits(doc);
|
||||
edits =new DocumentEdits(doc, false);
|
||||
buffer.append('\n');
|
||||
for (String imp : createdImprts) {
|
||||
buffer.append("import ");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -57,7 +57,7 @@ public class ScopeNameCompletionProposal implements ICompletionProposal {
|
||||
|
||||
@Override
|
||||
public DocumentEdits getTextEdit() {
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(startOffset + prefix.length(), endOffset, completion.getValue().substring(prefix.length()));
|
||||
return edits;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -40,7 +40,7 @@ public class JavaSnippetBuilder{
|
||||
IDocument doc = query.getDocument();
|
||||
IndentUtil indentUtil = new IndentUtil(doc);
|
||||
|
||||
DocumentEdits edit = new DocumentEdits(doc);
|
||||
DocumentEdits edit = new DocumentEdits(doc, true);
|
||||
|
||||
// PT 162103145 - Avoid creating a snippet with double `@` if the query is invoked after a `@` AND the template
|
||||
// also starts with a `@`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -24,7 +24,6 @@ import org.eclipse.jdt.core.dom.ITypeBinding;
|
||||
import org.eclipse.jdt.core.dom.MemberValuePair;
|
||||
import org.eclipse.jdt.core.dom.SimpleName;
|
||||
import org.eclipse.jdt.core.dom.StringLiteral;
|
||||
import org.eclipse.lsp4j.InsertTextFormat;
|
||||
import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.CompletionProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.ProjectBasedPropertyIndexProvider;
|
||||
@@ -65,13 +64,13 @@ public class ValueCompletionProcessor implements CompletionProvider {
|
||||
|
||||
for (Match<PropertyInfo> match : matches) {
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(offset, offset, "\"${" + match.data.getId() + "}\"");
|
||||
|
||||
// PT-160455522: create a proposal with `PlainText` format type, because for vscode (but not Eclipse), if you send it as a snippet
|
||||
// and it is "place holder" as such `"${debug}"`, vscode may treat it as a snippet place holder, and insert an empty string
|
||||
// if it cannot resolve it. If sending this as plain text, then insertion happens correctly
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match, InsertTextFormat.PlainText);
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match);
|
||||
|
||||
completions.add(proposal);
|
||||
}
|
||||
@@ -122,10 +121,10 @@ public class ValueCompletionProcessor implements CompletionProvider {
|
||||
|
||||
for (Match<PropertyInfo> match : matches) {
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(startOffset, endOffset, proposalPrefix + "${" + match.data.getId() + "}" + proposalPostfix);
|
||||
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match, InsertTextFormat.PlainText);
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match);
|
||||
|
||||
completions.add(proposal);
|
||||
}
|
||||
@@ -158,13 +157,13 @@ public class ValueCompletionProcessor implements CompletionProvider {
|
||||
|
||||
for (Match<PropertyInfo> match : matches) {
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(startOffset, endOffset, preCompletion + match.data.getId() + postCompletion);
|
||||
|
||||
// PT 160455522: create a proposal with `PlainText` format type, because for vscode (but not Eclipse), if you send it as a snippet
|
||||
// and the proposal value is "place holder" as such `"${debug}"`, vscode may treat it as a snippet place holder, and insert an empty string
|
||||
// if it cannot resolve it. If sending this as plain text, then insertion happens correctly
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match, InsertTextFormat.PlainText);
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match);
|
||||
|
||||
completions.add(proposal);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017, 2018 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2019 Pivotal, Inc.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
@@ -11,7 +11,6 @@
|
||||
package org.springframework.ide.vscode.boot.java.value;
|
||||
|
||||
import org.eclipse.lsp4j.CompletionItemKind;
|
||||
import org.eclipse.lsp4j.InsertTextFormat;
|
||||
import org.springframework.ide.vscode.boot.common.InformationTemplates;
|
||||
import org.springframework.ide.vscode.boot.metadata.PropertyInfo;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.DocumentEdits;
|
||||
@@ -29,19 +28,17 @@ public class ValuePropertyKeyProposal extends ScoreableProposal {
|
||||
private String detail;
|
||||
private Renderable documentation;
|
||||
private double score;
|
||||
private InsertTextFormat textFormat;
|
||||
|
||||
private ValuePropertyKeyProposal(DocumentEdits edits, String label, String detail, double score, Renderable documentation, InsertTextFormat textFormat) {
|
||||
private ValuePropertyKeyProposal(DocumentEdits edits, String label, String detail, double score, Renderable documentation) {
|
||||
this.edits = edits;
|
||||
this.label = label;
|
||||
this.detail = detail;
|
||||
this.documentation = documentation;
|
||||
this.score = score;
|
||||
this.textFormat = textFormat;
|
||||
}
|
||||
|
||||
public ValuePropertyKeyProposal(DocumentEdits edits, Match<PropertyInfo> match, InsertTextFormat textFormat) {
|
||||
this(edits, match.data.getId(), match.data.getType(), match.score, InformationTemplates.createCompletionDocumentation(match.data), textFormat);
|
||||
public ValuePropertyKeyProposal(DocumentEdits edits, Match<PropertyInfo> match) {
|
||||
this(edits, match.data.getId(), match.data.getType(), match.score, InformationTemplates.createCompletionDocumentation(match.data));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,10 +70,5 @@ public class ValuePropertyKeyProposal extends ScoreableProposal {
|
||||
public double getBaseScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertTextFormat getInsertTextFormat() {
|
||||
return this.textFormat;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ public class PropertiesCompletionProposalsCalculator {
|
||||
if (score!=0) {
|
||||
Type valueType = prop.getType();
|
||||
String postFix = propertyCompletionPostfix(typeUtil, valueType);
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.delete(navOffset+1, offset);
|
||||
edits.insert(offset, prop.getName()+postFix);
|
||||
proposals.add(
|
||||
@@ -290,7 +290,7 @@ public class PropertiesCompletionProposalsCalculator {
|
||||
String valueCandidate = hint.getValue();
|
||||
double score = FuzzyMatcher.matchScore(query, valueCandidate);
|
||||
if (score != 0) {
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.delete(startOfValue, offset);
|
||||
edits.insert(offset, valueCandidate);
|
||||
String valueTypeName = typeUtil.niceTypeName(getValueType(index, typeUtil, propertyName));
|
||||
@@ -343,13 +343,13 @@ public class PropertiesCompletionProposalsCalculator {
|
||||
docEdits = LazyProposalApplier.from(() -> {
|
||||
try {
|
||||
Type type = TypeParser.parse(match.data.getType());
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.delete(offset-prefix.length(), offset);
|
||||
edits.insert(offset, match.data.getId() + propertyCompletionPostfix(typeUtil, type));
|
||||
return edits;
|
||||
} catch (Throwable t) {
|
||||
log.error("{}", t);
|
||||
return new DocumentEdits(doc);
|
||||
return new DocumentEdits(doc, false);
|
||||
}
|
||||
});
|
||||
synchronized (proposals) {
|
||||
|
||||
@@ -32,8 +32,6 @@ import org.springframework.ide.vscode.commons.util.FuzzyMatcher;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.TupleExtensionsKt;
|
||||
import reactor.util.function.Tuples;
|
||||
|
||||
/**
|
||||
@@ -86,9 +84,8 @@ public class BeanRefCompletionProposalProvider implements XMLCompletionProvider
|
||||
private ICompletionProposal createProposal(String beanID, TextDocument doc, int offset, String prefix, Double score) {
|
||||
CompletionItemKind kind = CompletionItemKind.Reference;
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
edits.delete(offset - prefix.length(), offset);
|
||||
edits.insert(offset, beanID);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(offset - prefix.length(), offset, beanID);
|
||||
|
||||
Renderable renderable = null;
|
||||
|
||||
|
||||
@@ -89,7 +89,7 @@ public class PropertyNameCompletionProposalProvider implements XMLCompletionProv
|
||||
String label = getPropertyName(method);
|
||||
CompletionItemKind kind = CompletionItemKind.Method;
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
|
||||
String replaceString = "\"" + label + "\"";
|
||||
int replaceStart = tokenStart;
|
||||
|
||||
@@ -99,9 +99,8 @@ public class TypeCompletionProposalProvider implements XMLCompletionProvider {
|
||||
kind = CompletionItemKind.Property;
|
||||
}
|
||||
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
edits.delete(offset - prefix.length(), offset);
|
||||
edits.insert(offset, type.getFullyQualifiedName());
|
||||
DocumentEdits edits = new DocumentEdits(doc, false);
|
||||
edits.replace(offset - prefix.length(), offset, type.getFullyQualifiedName());
|
||||
|
||||
Renderable renderable = null;
|
||||
|
||||
|
||||
@@ -267,7 +267,7 @@ public abstract class ApplicationYamlAssistContext extends AbstractYamlAssistCon
|
||||
String value = hint.getValue();
|
||||
double score = FuzzyMatcher.matchScore(query, value);
|
||||
if (score!=0 && !value.equals(query)) {
|
||||
DocumentEdits edits = new DocumentEdits(doc.getDocument());
|
||||
DocumentEdits edits = new DocumentEdits(doc.getDocument(), false);
|
||||
int valueStart = offset-query.length();
|
||||
edits.delete(valueStart, offset);
|
||||
if (doc.getChar(valueStart-1)==':') {
|
||||
|
||||
Reference in New Issue
Block a user