mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-08 00:35:49 +02:00
Fix for Bug 172865 - [Content Assist] Parameter hint popup should disappear outside parentheses
This commit is contained in:
parent
cc7e0a31f7
commit
6b90a610a5
3 changed files with 41 additions and 18 deletions
|
@ -85,7 +85,7 @@ public class CParameterListValidator implements IContextInformationValidator, IC
|
||||||
|
|
||||||
Assert.isTrue((increment != 0 || decrement != 0) && increment != decrement);
|
Assert.isTrue((increment != 0 || decrement != 0) && increment != decrement);
|
||||||
|
|
||||||
int nestingLevel = -1; // Set to -1 to take into account first ( for function call
|
int nestingLevel = 0;
|
||||||
int charCount = 0;
|
int charCount = 0;
|
||||||
while (start < end) {
|
while (start < end) {
|
||||||
char curr = document.getChar(start++);
|
char curr = document.getChar(start++);
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
private ASTCompletionNode fCN= null;
|
private ASTCompletionNode fCN= null;
|
||||||
private boolean fCNComputed= false;
|
private boolean fCNComputed= false;
|
||||||
private IIndex fIndex = null;
|
private IIndex fIndex = null;
|
||||||
|
private int fContextInfoPosition;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new context.
|
* Creates a new context.
|
||||||
|
@ -109,6 +110,9 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
|
|
||||||
fCNComputed = true;
|
fCNComputed = true;
|
||||||
|
|
||||||
|
int offset = getParseOffset();
|
||||||
|
if (offset < 0) return null;
|
||||||
|
|
||||||
ICProject proj= getProject();
|
ICProject proj= getProject();
|
||||||
if (proj == null) return null;
|
if (proj == null) return null;
|
||||||
|
|
||||||
|
@ -129,7 +133,7 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
flags = 0;
|
flags = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fCN = fTU.getCompletionNode(fIndex, flags, getParseOffset());
|
fCN = fTU.getCompletionNode(fIndex, flags, offset);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,19 +143,35 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
public int getParseOffset() {
|
public int getParseOffset() {
|
||||||
if (!fParseOffsetComputed) {
|
if (!fParseOffsetComputed) {
|
||||||
fParseOffsetComputed= true;
|
fParseOffsetComputed= true;
|
||||||
|
fContextInfoPosition= guessContextInformationPosition();
|
||||||
if (fIsCompletion) {
|
if (fIsCompletion) {
|
||||||
fParseOffset = guessCompletionPosition();
|
fParseOffset = guessCompletionPosition(getInvocationOffset());
|
||||||
|
} else if (fContextInfoPosition > 0) {
|
||||||
|
fParseOffset = guessCompletionPosition(fContextInfoPosition);
|
||||||
} else {
|
} else {
|
||||||
fParseOffset = guessContextInformationPosition();
|
fParseOffset = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return fParseOffset;
|
return fParseOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int guessCompletionPosition() {
|
/**
|
||||||
final int contextPosition= getInvocationOffset();
|
* @return the offset where context information (parameter hints) starts.
|
||||||
|
*/
|
||||||
|
public int getContextInformationOffset() {
|
||||||
|
getParseOffset();
|
||||||
|
return fContextInfoPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to find a sensible completion position backwards in case the given offset
|
||||||
|
* is inside a function call argument list.
|
||||||
|
*
|
||||||
|
* @param contextPosition the starting position
|
||||||
|
* @return a sensible completion offset
|
||||||
|
*/
|
||||||
|
protected int guessCompletionPosition(int contextPosition) {
|
||||||
CHeuristicScanner scanner= new CHeuristicScanner(getDocument());
|
CHeuristicScanner scanner= new CHeuristicScanner(getDocument());
|
||||||
int bound= Math.max(-1, contextPosition - 200);
|
int bound= Math.max(-1, contextPosition - 200);
|
||||||
|
|
||||||
|
@ -181,6 +201,13 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
return contextPosition;
|
return contextPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try to find the smallest offset inside the opening parenthesis of a function call
|
||||||
|
* argument list.
|
||||||
|
*
|
||||||
|
* @return the offset of the function call parenthesis plus 1 or -1 if the invocation
|
||||||
|
* offset is not inside a function call (or similar)
|
||||||
|
*/
|
||||||
protected int guessContextInformationPosition() {
|
protected int guessContextInformationPosition() {
|
||||||
final int contextPosition= getInvocationOffset();
|
final int contextPosition= getInvocationOffset();
|
||||||
|
|
||||||
|
@ -193,20 +220,16 @@ public class CContentAssistInvocationContext extends ContentAssistInvocationCont
|
||||||
int paren= scanner.findOpeningPeer(pos, bound, '(', ')');
|
int paren= scanner.findOpeningPeer(pos, bound, '(', ')');
|
||||||
if (paren == CHeuristicScanner.NOT_FOUND)
|
if (paren == CHeuristicScanner.NOT_FOUND)
|
||||||
break;
|
break;
|
||||||
paren= scanner.findNonWhitespaceBackward(paren - 1, bound);
|
int token= scanner.previousToken(paren - 1, bound);
|
||||||
if (paren == CHeuristicScanner.NOT_FOUND) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
int token= scanner.previousToken(paren, bound);
|
|
||||||
// next token must be a method name (identifier) or the closing angle of a
|
// next token must be a method name (identifier) or the closing angle of a
|
||||||
// constructor call of a template type.
|
// constructor call of a template type.
|
||||||
if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN) {
|
if (token == Symbols.TokenIDENT || token == Symbols.TokenGREATERTHAN) {
|
||||||
return paren + 1;
|
return paren + 1;
|
||||||
}
|
}
|
||||||
pos= paren;
|
pos= paren - 1;
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
return contextPosition;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -195,7 +195,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
if (argString.length() > 0) {
|
if (argString.length() > 0) {
|
||||||
CProposalContextInformation info = new CProposalContextInformation(image, descString, argString);
|
CProposalContextInformation info = new CProposalContextInformation(image, descString, argString);
|
||||||
info.setContextInformationPosition(context.getParseOffset());
|
info.setContextInformationPosition(context.getContextInformationOffset());
|
||||||
proposal.setContextInformation(info);
|
proposal.setContextInformation(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -307,7 +307,7 @@ public class DOMCompletionProposalComputer extends ParsingBasedProposalComputer
|
||||||
|
|
||||||
if (dispargString.length() > 0) {
|
if (dispargString.length() > 0) {
|
||||||
CProposalContextInformation info = new CProposalContextInformation(image, dispString, dispargString);
|
CProposalContextInformation info = new CProposalContextInformation(image, dispString, dispargString);
|
||||||
info.setContextInformationPosition(context.getParseOffset());
|
info.setContextInformationPosition(context.getContextInformationOffset());
|
||||||
proposal.setContextInformation(info);
|
proposal.setContextInformation(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue