Changeset 1147

Show
Ignore:
Timestamp:
05/01/08 12:11:31 (4 months ago)
Author:
asterite
Message:

More autocompletion improvements! Now requesting it in between a name allows you to see all matching symbols starting from that name, allowing you to insert the new proposal or overwrite the old one.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/descent.core/src/descent/internal/codeassist/CompletionEngine.java

    r1145 r1147  
    264264    boolean isCompletingThisCall = false; 
    265265    boolean isCompletingSuperCall = false; 
     266    boolean isBetweenMethodName = false; 
    266267     
    267268    Scope rootScope; 
     
    660661        CompletionContext context = new CompletionContext(); 
    661662        context.setOffset(this.offset); 
     663        if (parser.completionToken != null) { 
     664            context.setTokenKind(CompletionContext.TOKEN_KIND_NAME); 
     665            context.setToken(parser.completionToken); 
     666            context.setTokenRange(parser.completionTokenStart, parser.completionTokenEnd); 
     667        } 
    662668        return context; 
    663669    } 
     
    14561462    } 
    14571463    private void completeExpression(Expression e1, IdentifierExp ident) throws JavaModelException { 
     1464        isBetweenMethodName = ident != null && ident.resolvedSymbol != null; 
     1465         
    14581466        if (e1 instanceof VarExp) { 
    14591467            VarExp var = (VarExp) e1; 
     
    16591667            proposal.setCompletion(CharOperation.NO_CHAR); 
    16601668        } else { 
    1661             proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
     1669            if (!isBetweenMethodName && parser.completionTokenEnd == this.actualCompletionPosition) { 
     1670                proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
     1671            } else { 
     1672                proposal.setCompletion(currentName); 
     1673            } 
    16621674        } 
    16631675         
     
    22932305                            handleContextInfo(func, funcNameIsOpCall, proposal); 
    22942306                        } else { 
    2295                             proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
     2307                            if (!isBetweenMethodName && parser.completionTokenEnd == this.actualCompletionPosition) { 
     2308                                proposal.setCompletion(CharOperation.concat(currentName, "()".toCharArray())); 
     2309                            } else { 
     2310                                proposal.setCompletion(currentName); 
     2311                            } 
    22962312                        } 
    22972313                    } else { 
     
    23002316                            handleContextInfo(func, funcNameIsOpCall, proposal); 
    23012317                        } else { 
    2302                             proposal.setCompletion(CharOperation.concat(ident, "()".toCharArray())); 
     2318                            if (!isBetweenMethodName && parser.completionTokenEnd == this.actualCompletionPosition) { 
     2319                                proposal.setCompletion(CharOperation.concat(ident, "()".toCharArray())); 
     2320                            } else { 
     2321                                proposal.setCompletion(ident); 
     2322                            } 
    23032323                        } 
    23042324                    } 
     
    27072727    private char[] computePrefixAndSourceRange(IdentifierExp ident) { 
    27082728        char[] prefix; 
    2709         if (ident == null || ident.ident == null || CharOperation.equals(ident.ident, CharOperation.NO_CHAR)) { 
     2729         
     2730        if (parser.completionToken != null) { 
     2731            this.startPosition = parser.completionTokenStart; 
     2732            this.endPosition = parser.completionTokenEnd; 
     2733            prefix = parser.completionToken; 
     2734        } else if (ident == null || ident.ident == null || CharOperation.equals(ident.ident, CharOperation.NO_CHAR)) { 
    27102735            this.startPosition = this.actualCompletionPosition; 
    27112736            this.endPosition = this.actualCompletionPosition; 
     
    27162741            prefix = ident.ident; 
    27172742        } 
     2743         
    27182744        return prefix; 
    27192745    } 
  • trunk/descent.core/src/descent/internal/codeassist/complete/CompletionParser.java

    r1141 r1147  
    8585    public boolean inNewExp; 
    8686    public boolean isInExp; 
     87     
     88    public char[] completionToken; 
     89    public int completionTokenStart; 
     90    public int completionTokenEnd; 
    8791 
    8892    public CompletionParser(int apiLevel, char[] source, char[] filename) { 
     
    242246    @Override 
    243247    protected IdentifierExp newIdentifierExp() { 
    244         if (token.ptr + token.sourceLen == cursorLocation && !wantNames) { 
     248        if (token.ptr <= cursorLocation && cursorLocation <= token.ptr + token.sourceLen && !wantNames) { 
     249            completionTokenStart = token.ptr; 
     250            completionTokenEnd = token.ptr + token.sourceLen; 
     251            completionToken = CharOperation.subarray(input, completionTokenStart, cursorLocation); 
     252             
    245253            assistNode = new CompletionOnIdentifierExp(loc, token); 
    246254            return (IdentifierExp) assistNode; 
     
    261269    @Override 
    262270    protected TypeQualified newTypeIdentifier(Loc loc, IdentifierExp id) { 
    263         if (id.start + id.length == cursorLocation) { 
     271        if (id.start <= cursorLocation && cursorLocation <= id.start + id.length) { 
    264272            assistNode = new CompletionOnTypeIdentifier(loc, id); 
    265273            return (TypeQualified) assistNode; 
     
    435443    @Override 
    436444    protected DotIdExp newDotIdExp(Loc loc, Expression e, IdentifierExp id) { 
    437         if (prevToken.ptr + prevToken.sourceLen == cursorLocation || token.ptr + token.sourceLen == cursorLocation) { 
     445        if (prevToken.ptr <= cursorLocation && cursorLocation <= prevToken.ptr + prevToken.sourceLen) { 
    438446            if (cursorLocation <= id.start) { 
    439447                assistNode = new CompletionOnDotIdExp(loc, e, new IdentifierExp(CharOperation.NO_CHAR)); 
    440448                return (DotIdExp) assistNode; 
    441449            } else { 
     450                completionTokenStart = prevToken.ptr; 
     451                completionTokenEnd = prevToken.ptr + prevToken.sourceLen; 
     452                completionToken = CharOperation.subarray(input, completionTokenStart, cursorLocation); 
     453                 
    442454                assistNode = new CompletionOnDotIdExp(loc, e, id); 
    443455                return (DotIdExp) assistNode; 
  • trunk/descent.ui/src/descent/internal/ui/text/java/LazyJavaMethodCompletionProposal.java

    r1136 r1147  
    117117        if (!hasParameters() || !hasArgumentList()) { 
    118118            setCursorPosition(replacement.length() + (getVariadic() != IMethod.VARARGS_NO ? 1 : 2)); 
    119           if (replacement.length() > 0) { 
    120               return replacement + "()"; //$NON-NLS-1$ 
    121           } else { 
     119//            if (replacement.length() > 0) { 
     120//                return replacement + "()"; //$NON-NLS-1$ 
     121//            } else { 
    122122                return replacement; 
    123           } 
     123//            } 
    124124        } 
    125125