use of org.jkiss.dbeaver.model.sql.completion.SQLCompletionRequest in project dbeaver by serge-rider.
the class SQLCompletionProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
IDocument document = editor.getDocument();
if (document == null) {
return new ICompletionProposal[0];
}
final SQLCompletionRequest request = new SQLCompletionRequest(editor.getCompletionContext(), document, documentOffset, editor.extractQueryAtPos(documentOffset), simpleMode);
SQLWordPartDetector wordDetector = request.getWordDetector();
try {
// Check that word start position is in default partition (#5994)
String contentType = TextUtilities.getContentType(document, SQLParserPartitions.SQL_PARTITIONING, wordDetector.getStartOffset(), true);
if (contentType == null || (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) && !SQLParserPartitions.CONTENT_TYPE_SQL_QUOTED.equals(contentType))) {
return new ICompletionProposal[0];
}
} catch (BadLocationException e) {
log.debug(e);
return new ICompletionProposal[0];
}
if (lookupTemplates) {
return makeTemplateProposals(viewer, request);
}
try {
String commandPrefix = editor.getSyntaxManager().getControlCommandPrefix();
if (wordDetector.getStartOffset() >= commandPrefix.length() && viewer.getDocument().get(wordDetector.getStartOffset() - commandPrefix.length(), commandPrefix.length()).equals(commandPrefix)) {
return makeCommandProposals(request, request.getWordPart());
}
} catch (BadLocationException e) {
log.debug(e);
}
SQLCompletionAnalyzer analyzer = new SQLCompletionAnalyzer(request);
DBPDataSource dataSource = editor.getDataSource();
if (request.getWordPart() != null) {
if (dataSource != null) {
ProposalSearchJob searchJob = new ProposalSearchJob(analyzer);
searchJob.schedule();
// Wait until job finished
UIUtils.waitJobCompletion(searchJob);
}
}
List<SQLCompletionProposalBase> proposals = analyzer.getProposals();
List<ICompletionProposal> result = new ArrayList<>();
for (SQLCompletionProposalBase cp : proposals) {
if (cp instanceof ICompletionProposal) {
result.add((ICompletionProposal) cp);
}
}
return ArrayUtils.toArray(ICompletionProposal.class, result);
}
use of org.jkiss.dbeaver.model.sql.completion.SQLCompletionRequest in project dbeaver by dbeaver.
the class SQLCompletionProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
IDocument document = editor.getDocument();
if (document == null) {
return new ICompletionProposal[0];
}
final SQLCompletionRequest request = new SQLCompletionRequest(editor.getCompletionContext(), document, documentOffset, editor.extractQueryAtPos(documentOffset), simpleMode);
SQLWordPartDetector wordDetector = request.getWordDetector();
try {
// Check that word start position is in default partition (#5994)
String contentType = TextUtilities.getContentType(document, SQLParserPartitions.SQL_PARTITIONING, wordDetector.getStartOffset(), true);
if (contentType == null || (!IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) && !SQLParserPartitions.CONTENT_TYPE_SQL_QUOTED.equals(contentType))) {
return new ICompletionProposal[0];
}
} catch (BadLocationException e) {
log.debug(e);
return new ICompletionProposal[0];
}
if (lookupTemplates) {
return makeTemplateProposals(viewer, request);
}
try {
String commandPrefix = editor.getSyntaxManager().getControlCommandPrefix();
if (wordDetector.getStartOffset() >= commandPrefix.length() && viewer.getDocument().get(wordDetector.getStartOffset() - commandPrefix.length(), commandPrefix.length()).equals(commandPrefix)) {
return makeCommandProposals(request, request.getWordPart());
}
} catch (BadLocationException e) {
log.debug(e);
}
SQLCompletionAnalyzer analyzer = new SQLCompletionAnalyzer(request);
DBPDataSource dataSource = editor.getDataSource();
if (request.getWordPart() != null) {
if (dataSource != null) {
ProposalSearchJob searchJob = new ProposalSearchJob(analyzer);
searchJob.schedule();
// Wait until job finished
UIUtils.waitJobCompletion(searchJob);
}
}
List<SQLCompletionProposalBase> proposals = analyzer.getProposals();
List<ICompletionProposal> result = new ArrayList<>();
for (SQLCompletionProposalBase cp : proposals) {
if (cp instanceof ICompletionProposal) {
result.add((ICompletionProposal) cp);
}
}
return ArrayUtils.toArray(ICompletionProposal.class, result);
}
Aggregations