PT-160455522: Fix for empty string insertion for ad hoc props
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2018 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,6 +24,7 @@ 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.springframework.ide.vscode.boot.java.handlers.CompletionProvider;
|
||||
import org.springframework.ide.vscode.boot.metadata.PropertyInfo;
|
||||
import org.springframework.ide.vscode.boot.metadata.SpringPropertyIndexProvider;
|
||||
@@ -63,7 +64,11 @@ public class ValueCompletionProcessor implements CompletionProvider {
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
edits.replace(offset, offset, "\"${" + match.data.getId() + "}\"");
|
||||
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match);
|
||||
// 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);
|
||||
|
||||
result.add(proposal);
|
||||
}
|
||||
}
|
||||
@@ -114,7 +119,8 @@ public class ValueCompletionProcessor implements CompletionProvider {
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
edits.replace(startOffset, endOffset, proposalPrefix + "${" + match.data.getId() + "}" + proposalPostfix);
|
||||
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match);
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match, InsertTextFormat.PlainText);
|
||||
|
||||
completions.add(proposal);
|
||||
}
|
||||
}
|
||||
@@ -149,7 +155,11 @@ public class ValueCompletionProcessor implements CompletionProvider {
|
||||
DocumentEdits edits = new DocumentEdits(doc);
|
||||
edits.replace(startOffset, endOffset, preCompletion + match.data.getId() + postCompletion);
|
||||
|
||||
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match);
|
||||
// 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);
|
||||
|
||||
completions.add(proposal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2017 Pivotal, Inc.
|
||||
* Copyright (c) 2017, 2018 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,14 +11,13 @@
|
||||
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;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ICompletionProposal;
|
||||
import org.springframework.ide.vscode.commons.languageserver.completion.ScoreableProposal;
|
||||
import org.springframework.ide.vscode.commons.util.FuzzyMap.Match;
|
||||
import org.springframework.ide.vscode.commons.util.Renderable;
|
||||
import org.springframework.ide.vscode.commons.util.Renderables;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -30,17 +29,19 @@ 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) {
|
||||
private ValuePropertyKeyProposal(DocumentEdits edits, String label, String detail, double score, Renderable documentation, InsertTextFormat textFormat) {
|
||||
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) {
|
||||
this(edits, match.data.getId(), match.data.getType(), match.score, InformationTemplates.createCompletionDocumentation(match.data));
|
||||
public ValuePropertyKeyProposal(DocumentEdits edits, Match<PropertyInfo> match, InsertTextFormat textFormat) {
|
||||
this(edits, match.data.getId(), match.data.getType(), match.score, InformationTemplates.createCompletionDocumentation(match.data), textFormat);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,5 +73,10 @@ public class ValuePropertyKeyProposal extends ScoreableProposal {
|
||||
public double getBaseScore() {
|
||||
return score;
|
||||
}
|
||||
|
||||
@Override
|
||||
public InsertTextFormat getInsertTextFormat() {
|
||||
return this.textFormat;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user