use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class TypeBasedYamlSymbolHandler method createSymbol.
protected SymbolInformation createSymbol(TextDocument doc, Node node, YType type) throws BadLocationException {
DocumentRegion region = NodeUtil.region(doc, node);
Location location = new Location(doc.getUri(), doc.toRange(region.getStart(), region.getLength()));
SymbolInformation symbol = new SymbolInformation();
symbol.setName(region.toString());
symbol.setKind(symbolKind(type));
symbol.setLocation(location);
symbol.setContainerName(containerName(type));
return symbol;
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class GithubRepoContentAssistant method getOwnerOrRepoCompletions.
private List<ICompletionProposal> getOwnerOrRepoCompletions(CompletionFactory f, DocumentRegion ownerAndRepoRegion) {
try {
int slash = ownerAndRepoRegion.indexOf('/');
if (slash >= 0) {
DocumentRegion owner = ownerAndRepoRegion.subSequence(0, slash);
return getRepoCompletions(f, owner, ownerAndRepoRegion.subSequence(slash + 1));
} else {
Collection<String> owners = github.getOwners();
DocumentRegion query = ownerAndRepoRegion;
if (!owners.isEmpty()) {
List<ICompletionProposal> proposals = new ArrayList<>(owners.size());
for (String owner : owners) {
if (FuzzyMatcher.matchScore(query, owner) != 0.0) {
proposals.add(SimpleCompletionFactory.simpleProposal(query, CompletionItemKind.Text, owner + "/", null, null));
}
}
return proposals;
} else {
return ImmutableList.of();
}
}
} catch (Exception e) {
return ImmutableList.of(f.errorMessage(ownerAndRepoRegion.toString(), ExceptionUtil.getMessageNoAppendedInformation(e)));
}
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class GithubValueParsers method uri.
public static ValueParser uri(GithubInfoProvider github) {
return new ValueParser() {
@Override
public GithubRepoReference parse(String _str) throws Exception {
TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
doc.setText(_str);
DocumentRegion str = new DocumentRegion(doc);
GithubRepoReference repo = parseFormat(str);
if (repo != null) {
Collection<String> knownRepos;
try {
knownRepos = github.getReposForOwner(repo.owner.toString());
} catch (Exception e) {
// Couldn't read info from github. Ignore this in reconciler context.
return repo;
}
if (knownRepos == null) {
throw unknownEntity("User or Organization not found: '" + repo.owner + "'", repo.owner);
} else {
if (!knownRepos.contains(repo.name.toString())) {
throw unknownEntity("Repo not found: '" + repo.name + "'", repo.name);
}
}
}
return repo;
}
private GithubRepoReference parseFormat(DocumentRegion str) throws Exception {
String prefix = checkPrefix(str);
if (prefix != null) {
DocumentRegion ownerAndName = str.subSequence(prefix.length());
// Should end with '.git'
if (ownerAndName.endsWith(".git")) {
ownerAndName = ownerAndName.subSequence(0, ownerAndName.length() - 4);
} else {
DocumentRegion highlight = ownerAndName.textAtEnd(1);
throw new ValueParseException("GitHub repo uri should end with '.git'", highlight.getStart(), highlight.getEnd());
}
int slash = ownerAndName.indexOf('/');
if (slash >= 0) {
return new GithubRepoReference(ownerAndName.subSequence(0, slash), ownerAndName.subSequence(slash + 1));
} else {
throw new ValueParseException("Expecting something of the form '${owner}/${repo}'.", ownerAndName.getStart(), ownerAndName.getEnd());
}
}
return null;
}
private String checkPrefix(DocumentRegion str) throws ValueParseException {
for (String expectedPrefix : GithubRepoContentAssistant.URI_PREFIXES) {
int lastChar = expectedPrefix.length() - 1;
if (str.startsWith(expectedPrefix.substring(0, lastChar))) {
if (str.charAt(lastChar) == expectedPrefix.charAt(lastChar)) {
return expectedPrefix;
}
throw new ValueParseException("Expecting a '" + expectedPrefix.charAt(lastChar) + "'", lastChar, lastChar + 1);
}
}
return null;
}
};
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class RouteContentAssistant method getQueries.
private String[] getQueries(DocumentRegion region) {
// Example of what this should do
// region = "foo.bar.com"
// We have to make a guess which part of this is the host-name and which part is domain-name
// The split could be either at the very start, or at any one of the '.' chars.
// So the possible queries are as follows:
// - "foo.bar.com"
// - "bar.com"
// - "com"
region = region.trimStart();
DocumentRegion[] pieces = region.split('.');
String[] queries = new String[pieces.length];
for (int i = pieces.length - 1; i >= 0; i--) {
if (i == pieces.length - 1) {
queries[i] = pieces[i].toString();
} else {
queries[i] = pieces[i] + "." + queries[i + 1];
}
}
return queries;
}
use of org.springframework.ide.vscode.commons.util.text.DocumentRegion in project sts4 by spring-projects.
the class CommonLanguageTools method getValueType.
/**
* Determine the value type for a give propertyName.
*/
public static Type getValueType(FuzzyMap<PropertyInfo> index, TypeUtil typeUtil, String propertyName) {
try {
PropertyInfo prop = index.get(propertyName);
if (prop != null) {
return TypeParser.parse(prop.getType());
} else {
prop = CommonLanguageTools.findLongestValidProperty(index, propertyName);
if (prop != null) {
TextDocument doc = new TextDocument(null, LanguageId.PLAINTEXT);
doc.setText(propertyName);
PropertyNavigator navigator = new PropertyNavigator(doc, null, typeUtil, new DocumentRegion(doc, 0, doc.getLength()));
return navigator.navigate(prop.getId().length(), TypeParser.parse(prop.getType()));
}
}
} catch (Exception e) {
Log.log(e);
}
return null;
}
Aggregations