use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class ValueCompletionProcessor method computeProposalsForStringLiteral.
private void computeProposalsForStringLiteral(ASTNode node, List<ICompletionProposal> completions, int offset, IDocument doc, FuzzyMap<PropertyInfo> index) throws BadLocationException {
String prefix = identifyPropertyPrefix(doc.get(node.getStartPosition() + 1, offset - (node.getStartPosition() + 1)), offset - (node.getStartPosition() + 1));
int startOffset = offset - prefix.length();
int endOffset = offset;
String prePrefix = doc.get(node.getStartPosition() + 1, offset - prefix.length() - node.getStartPosition() - 1);
String preCompletion;
if (prePrefix.endsWith("${")) {
preCompletion = "";
} else if (prePrefix.endsWith("$")) {
preCompletion = "{";
} else {
preCompletion = "${";
}
String fullNodeContent = doc.get(node.getStartPosition(), node.getLength());
String postCompletion = isClosingBracketMissing(fullNodeContent + preCompletion) ? "}" : "";
List<Match<PropertyInfo>> matches = findMatches(prefix, index);
for (Match<PropertyInfo> match : matches) {
DocumentEdits edits = new DocumentEdits(doc);
edits.replace(startOffset, endOffset, preCompletion + match.data.getId() + postCompletion);
ValuePropertyKeyProposal proposal = new ValuePropertyKeyProposal(edits, match.data.getId(), match.data.getName(), null);
completions.add(proposal);
}
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class PropertiesCompletionProposalsCalculator method getNavigationProposals.
private Collection<ICompletionProposal> getNavigationProposals() {
String navPrefix = navigationPrefixFinder.getPrefix(doc, offset);
try {
if (navPrefix != null) {
// offset of 'nav' operator char (i.e. '.' or ']').
int navOffset = offset - navPrefix.length() - 1;
navPrefix = fuzzySearchPrefix.getPrefix(doc, navOffset);
if (navPrefix != null && !navPrefix.isEmpty()) {
PropertyInfo prop = findLongestValidProperty(index, navPrefix);
if (prop != null) {
int regionStart = navOffset - navPrefix.length();
Collection<ICompletionProposal> hintProposals = getKeyHintProposals(prop, navOffset);
if (CollectionUtil.hasElements(hintProposals)) {
return hintProposals;
}
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, regionStart, navOffset));
Type type = navigator.navigate(regionStart + prop.getId().length(), TypeParser.parse(prop.getType()));
if (type != null) {
return getNavigationProposals(type, navOffset);
}
}
}
}
} catch (Exception e) {
Log.log(e);
}
return Collections.emptyList();
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class PropertiesHoverCalculator method getPropertyHover.
private Tuple2<Renderable, IRegion> getPropertyHover(Key property) {
PropertyInfo best = findBestHoverMatch(property.decode());
if (best == null) {
return null;
} else {
Renderable renderable = InformationTemplates.createHover(best);
DocumentRegion region = createRegion(doc, property);
return Tuples.of(renderable, region.asRegion());
}
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class CommonLanguageTools method getValueHints.
public static Collection<StsValueHint> getValueHints(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String query, String propertyName, EnumCaseMode caseMode) {
Type type = getValueType(index, typeUtil, propertyName);
if (TypeUtil.isSequencable(type)) {
// It is useful to provide content assist for the values in the list when entering a list
type = TypeUtil.getDomainType(type);
}
List<StsValueHint> allHints = new ArrayList<>();
{
Collection<StsValueHint> hints = typeUtil.getHintValues(type, query, caseMode);
if (CollectionUtil.hasElements(hints)) {
allHints.addAll(hints);
}
}
{
PropertyInfo prop = index.findLongestCommonPrefixEntry(propertyName);
if (prop != null) {
HintProvider hintProvider = prop.getHints(typeUtil, false);
if (!HintProviders.isNull(hintProvider)) {
allHints.addAll(hintProvider.getValueHints(query));
}
}
}
return allHints;
}
use of org.springframework.ide.vscode.boot.metadata.PropertyInfo in project sts4 by spring-projects.
the class ApplicationYamlEditorTest method testBootBug5905.
@Test
public void testBootBug5905() throws Exception {
useProject(createPredefinedMavenProject("boot-1.3.3-app-with-resource-prop"));
// Check the metadata reflects the 'handle-as':
PropertyInfo metadata = getIndexProvider().getIndex(null).get("my.welcome.path");
assertEquals("org.springframework.core.io.Resource", metadata.getType());
// Check the content assist based on it works too:
assertCompletionsDisplayString("my:\n" + " welcome:\n" + " path: <*>", // =>
"classpath:", "classpath*:", "file:", "http://", "https://");
}
Aggregations