use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class GithubRepoContentAssistant method getCompletions.
@Override
public List<ICompletionProposal> getCompletions(CompletionFactory f, DocumentRegion region, int offset) {
DocumentRegion query = region.subSequence(0, offset);
// If uri prefix is already there, we provide CA for owner / repo
for (String uriPrefix : URI_PREFIXES) {
if (query.startsWith(uriPrefix)) {
return getOwnerOrRepoCompletions(f, query.subSequence(uriPrefix.length()));
}
}
// If uri prefix is not yet there, maybe we can suggest it (if it matches the query)
List<ICompletionProposal> proposals = new ArrayList<>(URI_PREFIXES.length);
for (String uriPrefix : URI_PREFIXES) {
if (FuzzyMatcher.matchScore(query, uriPrefix) != 0.0) {
proposals.add(SimpleCompletionFactory.simpleProposal(query, CompletionItemKind.Text, uriPrefix, null, null));
}
}
return proposals;
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class PropertiesHoverCalculator method getValueHover.
private Tuple2<Renderable, IRegion> getValueHover(Value value) {
DocumentRegion valueRegion = createRegion(doc, value).trimStart(SPACES).trimEnd(SPACES);
if (valueRegion.getStart() <= offset && offset < valueRegion.getEnd()) {
String valueString = valueRegion.toString();
String propertyName = value.getParent().getKey().decode();
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);
}
if (TypeUtil.isClass(type)) {
// Special case. We want to provide hoverinfos more liberally than what's suggested for completions (i.e. even class names
// that are not suggested by the hints because they do not meet subtyping constraints should be hoverable and linkable!
StsValueHint hint = StsValueHint.className(valueString, typeUtil);
if (hint != null) {
return Tuples.of(createRenderable(hint), valueRegion.asRegion());
}
}
// Hack: pretend to invoke content-assist at the end of the value text. This should provide hints applicable to that value
// then show hoverinfo based on that. That way we can avoid duplication a lot of similar logic to compute hoverinfos and hyperlinks.
Collection<StsValueHint> hints = getValueHints(index, typeUtil, valueString, propertyName, EnumCaseMode.ALIASED);
if (hints != null) {
Optional<StsValueHint> hint = hints.stream().filter(h -> valueString.equals(h.getValue())).findFirst();
if (hint.isPresent()) {
return Tuples.of(createRenderable(hint.get()), valueRegion.asRegion());
}
}
}
return null;
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class SpringPropertiesReconcileEngine method reconcile.
@Override
public void reconcile(IDocument doc, IProblemCollector problemCollector) {
FuzzyMap<PropertyInfo> index = fIndexProvider.getIndex(doc);
problemCollector.beginCollecting();
try {
ParseResults results = parser.parse(doc.get());
DuplicateNameChecker duplicateNameChecker = new DuplicateNameChecker(problemCollector);
results.syntaxErrors.forEach(syntaxError -> {
problemCollector.accept(problem(PROP_SYNTAX_ERROR, syntaxError.getMessage(), syntaxError.getOffset(), syntaxError.getLength()));
});
if (index == null || index.isEmpty()) {
// some problem putting information about properties into the index.
return;
}
results.ast.getNodes(KeyValuePair.class).forEach(pair -> {
try {
DocumentRegion propertyNameRegion = createRegion(doc, pair.getKey());
String keyName = PropertiesFileEscapes.unescape(propertyNameRegion.toString());
duplicateNameChecker.check(propertyNameRegion);
PropertyInfo validProperty = SpringPropertyIndex.findLongestValidProperty(index, keyName);
if (validProperty != null) {
// in PropertyNavigator (probably these changes are also for the better making it simpler as well)
if (validProperty.isDeprecated()) {
problemCollector.accept(problemDeprecated(propertyNameRegion, validProperty));
}
int offset = validProperty.getId().length() + propertyNameRegion.getStart();
PropertyNavigator navigator = new PropertyNavigator(doc, problemCollector, typeUtilProvider.getTypeUtil(doc), propertyNameRegion);
Type valueType = navigator.navigate(offset, TypeParser.parse(validProperty.getType()));
if (valueType != null) {
reconcileType(doc, valueType, pair.getValue(), problemCollector);
}
} else {
// validProperty==null
// The name is invalid, with no 'prefix' of the name being a valid property name.
PropertyInfo similarEntry = index.findLongestCommonPrefixEntry(propertyNameRegion.toString());
CharSequence validPrefix = commonPrefix(similarEntry.getId(), keyName);
problemCollector.accept(problemUnkownProperty(propertyNameRegion, similarEntry, validPrefix));
}
// end: validProperty==null
} catch (Exception e) {
Log.log(e);
}
});
} catch (Throwable e2) {
Log.log(e2);
} finally {
problemCollector.endCollecting();
}
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class ApplicationYamlASTReconciler method valueParseError.
private void valueParseError(YamlFileAST root, ScalarNode scalar, ValueParseException e) {
IDocument doc = root.getDocument();
DocumentRegion containingRegion = new DocumentRegion(doc, scalar.getStartMark().getIndex(), scalar.getEndMark().getIndex());
problems.accept(problem(ApplicationYamlProblemType.YAML_VALUE_TYPE_MISMATCH, e.getHighlightRegion(containingRegion), ExceptionUtil.getMessage(e)));
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class JavaSnippetManager method getCompletions.
public Collection<ICompletionProposal> getCompletions(IDocument doc, int offset, ASTNode node, CompilationUnit cu) {
Collection<ICompletionProposal> completions = new ArrayList<>();
DocumentRegion query = PREFIX_FINDER.getPrefixRegion(doc, offset);
for (JavaSnippet javaSnippet : snippets) {
if (FuzzyMatcher.matchScore(query.toString(), javaSnippet.getName()) != 0) {
javaSnippet.generateCompletion(snippetBuilderFactory, query, node, cu).ifPresent((completion) -> completions.add(completion));
}
}
return completions;
}
Aggregations