Lines 354-367
Link Here
|
354 |
if (enterThreadLocalAntiloop(AntiloopClient.query_type, expression)) { |
354 |
if (enterThreadLocalAntiloop(AntiloopClient.query_type, expression)) { |
355 |
try { |
355 |
try { |
356 |
CsmCacheManager.enter(); |
356 |
CsmCacheManager.enter(); |
|
|
357 |
|
358 |
// Note that baseDocument can be null |
357 |
baseDocument = (BaseDocument) CsmUtilities.getDocument(expression.getContainingFile()); |
359 |
baseDocument = (BaseDocument) CsmUtilities.getDocument(expression.getContainingFile()); |
358 |
if (baseDocument == null) { |
360 |
assert getBaseDocument() != null || getCsmFile() != null : "Either document or CsmFile must be provided!"; // NOI18N |
359 |
CloneableEditorSupport support = CsmUtilities.findCloneableEditorSupport(expression.getContainingFile()); |
|
|
360 |
if (support == null) { |
361 |
return false; |
362 |
} |
363 |
baseDocument = (BaseDocument) support.openDocument(); |
364 |
} |
365 |
|
361 |
|
366 |
final int startOffset = expression.getStartOffset(); |
362 |
final int startOffset = expression.getStartOffset(); |
367 |
final int endOffset = expression.getEndOffset(); |
363 |
final int endOffset = expression.getEndOffset(); |
Lines 370-377
Link Here
|
370 |
// return false; |
366 |
// return false; |
371 |
// } |
367 |
// } |
372 |
|
368 |
|
373 |
long docVersion = DocumentUtilities.getDocumentVersion(baseDocument); |
|
|
374 |
|
375 |
// TokenProcessorCache property = (TokenProcessorCache) baseDocument.getProperty(TOKEN_PROCESSOR_CACHE_KEY); |
369 |
// TokenProcessorCache property = (TokenProcessorCache) baseDocument.getProperty(TOKEN_PROCESSOR_CACHE_KEY); |
376 |
// CsmCompletionTokenProcessor tp = null; |
370 |
// CsmCompletionTokenProcessor tp = null; |
377 |
// if (property != null) { |
371 |
// if (property != null) { |
Lines 385-398
Link Here
|
385 |
} |
379 |
} |
386 |
|
380 |
|
387 |
CsmCompletionTokenProcessor tp; |
381 |
CsmCompletionTokenProcessor tp; |
388 |
|
|
|
389 |
CsmScope passedScope = null; |
382 |
CsmScope passedScope = null; |
390 |
|
383 |
|
391 |
if (CsmKindUtilities.isExpression(expression)) { |
384 |
if (CsmKindUtilities.isExpression(expression)) { |
392 |
passedScope = ((CsmExpression) expression).getScope(); |
385 |
passedScope = ((CsmExpression) expression).getScope(); |
393 |
tp = processTokensInExpression((CsmExpression) expression, task.isFindTypeTask()); |
386 |
tp = processTokensInExpression((CsmExpression) expression, task.isFindTypeTask()); |
394 |
} else { |
387 |
} else { |
395 |
tp = processTokensInFile(csmFile, startOffset, endOffset, baseDocument, docVersion); |
388 |
tp = processTokensInFile(csmFile, startOffset, endOffset, baseDocument); |
396 |
} |
389 |
} |
397 |
|
390 |
|
398 |
if (!checkErrorTokenState(tp)) { |
391 |
if (!checkErrorTokenState(tp)) { |
Lines 429-436
Link Here
|
429 |
} else if (TRACE_COMPLETION) { |
422 |
} else if (TRACE_COMPLETION) { |
430 |
System.err.println("Error expression " + tp.getResultExp()); |
423 |
System.err.println("Error expression " + tp.getResultExp()); |
431 |
} |
424 |
} |
432 |
} catch (IOException ex) { |
|
|
433 |
ex.printStackTrace(System.err); |
434 |
} finally { |
425 |
} finally { |
435 |
exitThreadLocalAntiloop(AntiloopClient.query_type, expression); |
426 |
exitThreadLocalAntiloop(AntiloopClient.query_type, expression); |
436 |
CsmCacheManager.leave(); |
427 |
CsmCacheManager.leave(); |
Lines 561-567
Link Here
|
561 |
if (tp == null) { |
552 |
if (tp == null) { |
562 |
// find last separator position |
553 |
// find last separator position |
563 |
final int lastSepOffset = sup.getLastCommandSeparator(csmFile, offset, getFileReferencesContext()); |
554 |
final int lastSepOffset = sup.getLastCommandSeparator(csmFile, offset, getFileReferencesContext()); |
564 |
tp = processTokensInFile(csmFile, lastSepOffset, offset, doc, docVersion); |
555 |
tp = processTokensInFile(csmFile, lastSepOffset, offset, doc); |
565 |
baseDocument.putProperty(TOKEN_PROCESSOR_CACHE_KEY, new TokenProcessorCache(offset, docVersion, tp)); |
556 |
baseDocument.putProperty(TOKEN_PROCESSOR_CACHE_KEY, new TokenProcessorCache(offset, docVersion, tp)); |
566 |
} else { |
557 |
} else { |
567 |
// hit |
558 |
// hit |
Lines 719-725
Link Here
|
719 |
return errState; |
710 |
return errState; |
720 |
} |
711 |
} |
721 |
|
712 |
|
722 |
private CsmCompletionTokenProcessor processTokensInFile(CsmFile csmFile, final int startOffset, final int endOffset, final BaseDocument doc, final long docVersion) { |
713 |
private CsmCompletionTokenProcessor processTokensInFile(CsmFile csmFile, final int startOffset, final int endOffset, final BaseDocument doc) { |
723 |
CsmCompletionTokenProcessor tp = new CsmCompletionTokenProcessor(endOffset, startOffset); |
714 |
CsmCompletionTokenProcessor tp = new CsmCompletionTokenProcessor(endOffset, startOffset); |
724 |
final CndTokenProcessor<Token<TokenId>> etp = CsmExpandedTokenProcessor.create(csmFile, doc, tp, endOffset); |
715 |
final CndTokenProcessor<Token<TokenId>> etp = CsmExpandedTokenProcessor.create(csmFile, doc, tp, endOffset); |
725 |
if(etp instanceof CsmExpandedTokenProcessor) { |
716 |
if(etp instanceof CsmExpandedTokenProcessor) { |
Lines 727-738
Link Here
|
727 |
} |
718 |
} |
728 |
tp.enableLambdaSupport(areLambdasEnabled(csmFile)); |
719 |
tp.enableLambdaSupport(areLambdasEnabled(csmFile)); |
729 |
tp.enableTemplateSupport(areTemplatesEnabled(csmFile)); |
720 |
tp.enableTemplateSupport(areTemplatesEnabled(csmFile)); |
730 |
doc.render(new Runnable() { |
721 |
if (doc != null) { |
731 |
@Override |
722 |
doc.render(new Runnable() { |
732 |
public void run() { |
723 |
@Override |
733 |
CndTokenUtilities.processTokens(etp, doc, startOffset, endOffset); |
724 |
public void run() { |
|
|
725 |
CndTokenUtilities.processTokens(etp, doc, startOffset, endOffset); |
726 |
} |
727 |
}); |
728 |
} else { |
729 |
TokenSequence<TokenId> cppTokenSequence = CsmFileInfoQuery.getDefault().getCppTokenSequence(csmFile, startOffset, false, endOffset < startOffset); |
730 |
if (cppTokenSequence != null) { |
731 |
CndTokenUtilities.processTokens(etp, cppTokenSequence, startOffset, endOffset); |
734 |
} |
732 |
} |
735 |
}); |
733 |
} |
736 |
return tp; |
734 |
return tp; |
737 |
} |
735 |
} |
738 |
|
736 |
|
Lines 748-759
Link Here
|
748 |
int exprEndOffset = exprStartOffset + expressionText.length(); |
746 |
int exprEndOffset = exprStartOffset + expressionText.length(); |
749 |
|
747 |
|
750 |
final CsmCompletionTokenProcessor tp = new CsmCompletionTokenProcessor(exprEndOffset, exprStartOffset); |
748 |
final CsmCompletionTokenProcessor tp = new CsmCompletionTokenProcessor(exprEndOffset, exprStartOffset); |
751 |
TokenHierarchy<String> hi = TokenHierarchy.create( |
749 |
|
752 |
expressionText, |
750 |
final Language<CppTokenId> language = getBaseDocument() != null ? |
753 |
false, |
751 |
CndLexerUtilities.getLanguage(getBaseDocument()) |
754 |
CndLexerUtilities.getLanguage(getBaseDocument()), |
752 |
: CsmFileInfoQuery.getDefault().getFileLexerLanguage(getCsmFile()); |
|
|
753 |
|
754 |
final InputAttributes attributes = getBaseDocument() != null ? |
755 |
(InputAttributes) getBaseDocument().getProperty(InputAttributes.class) |
756 |
: null; |
757 |
|
758 |
TokenHierarchy<String> hi = TokenHierarchy.create(expressionText, |
759 |
false, |
760 |
language, |
755 |
null, |
761 |
null, |
756 |
(InputAttributes) getBaseDocument().getProperty(InputAttributes.class) |
762 |
attributes |
757 |
); |
763 |
); |
758 |
List<TokenSequence<?>> tsList = hi.embeddedTokenSequences(exprEndOffset - exprStartOffset, true); |
764 |
List<TokenSequence<?>> tsList = hi.embeddedTokenSequences(exprEndOffset - exprStartOffset, true); |
759 |
// Go from inner to outer TSes |
765 |
// Go from inner to outer TSes |
Lines 777-782
Link Here
|
777 |
|
783 |
|
778 |
return tp; |
784 |
return tp; |
779 |
} |
785 |
} |
|
|
786 |
|
787 |
private CsmCompletionExpression getResultExpression(CsmCompletionTokenProcessor tp, boolean processedAsExpression, boolean keepWholeAst) { |
788 |
if (processedAsExpression && keepWholeAst) { |
789 |
// See implementation of processTokensInExpression |
790 |
CsmCompletionExpression resultExp = tp.getResultExp(); |
791 |
if (resultExp != null && resultExp.getParameterCount() == 1 && resultExp.getExpID() == CsmCompletionExpression.PARENTHESIS) { |
792 |
return resultExp.getParameter(0); |
793 |
} |
794 |
} |
795 |
return tp.getResultExp(); |
796 |
} |
780 |
|
797 |
|
781 |
abstract protected boolean isProjectBeeingParsed(boolean openingSource); |
798 |
abstract protected boolean isProjectBeeingParsed(boolean openingSource); |
782 |
|
799 |
|
Lines 812-818
Link Here
|
812 |
); |
829 |
); |
813 |
} |
830 |
} |
814 |
} |
831 |
} |
815 |
CompletionSupport sup = CompletionSupport.get(doc); |
832 |
CompletionSupport sup = CompletionSupport.get(doc, getCsmFile()); |
816 |
CsmOffsetableDeclaration context = sup.getDefinition(contextScope); |
833 |
CsmOffsetableDeclaration context = sup.getDefinition(contextScope); |
817 |
if (context == null) { |
834 |
if (context == null) { |
818 |
context = sup.getDefinition(getCsmFile(), offset, getFileReferencesContext()); |
835 |
context = sup.getDefinition(getCsmFile(), offset, getFileReferencesContext()); |
Lines 1457-1464
Link Here
|
1457 |
if (CsmKindUtilities.isExpression(expression)) { |
1474 |
if (CsmKindUtilities.isExpression(expression)) { |
1458 |
tp = processTokensInExpression((CsmExpression) expression, true); |
1475 |
tp = processTokensInExpression((CsmExpression) expression, true); |
1459 |
} else { |
1476 |
} else { |
1460 |
long docVersion = DocumentUtilities.getDocumentVersion(getBaseDocument()); |
1477 |
tp = processTokensInFile(expression.getContainingFile(), expression.getStartOffset(), expression.getEndOffset(), getBaseDocument()); |
1461 |
tp = processTokensInFile(expression.getContainingFile(), expression.getStartOffset(), expression.getEndOffset(), getBaseDocument(), docVersion); |
|
|
1462 |
} |
1478 |
} |
1463 |
|
1479 |
|
1464 |
if (!checkErrorTokenState(tp)) { |
1480 |
if (!checkErrorTokenState(tp)) { |