[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited AbstractASTManag
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2006-09-23 21:22:53
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28896/src/org/python/pydev/editor/codecompletion/revisited Modified Files: AbstractASTManager.java Log Message: Completion for parameters (only based on the local context) Index: AbstractASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited/AbstractASTManager.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** AbstractASTManager.java 18 Sep 2006 00:50:32 -0000 1.32 --- AbstractASTManager.java 23 Sep 2006 21:22:50 -0000 1.33 *************** *** 19,22 **** --- 19,23 ---- import org.python.pydev.core.ICompletionRequest; import org.python.pydev.core.ICompletionState; + import org.python.pydev.core.ILocalScope; import org.python.pydev.core.IModule; import org.python.pydev.core.IModulesManager; *************** *** 35,38 **** --- 36,40 ---- import org.python.pydev.editor.codecompletion.revisited.modules.SourceToken; import org.python.pydev.editor.codecompletion.revisited.visitors.Definition; + import org.python.pydev.editor.codecompletion.revisited.visitors.LocalScope; import org.python.pydev.parser.PyParser; import org.python.pydev.parser.jython.SimpleNode; *************** *** 288,292 **** public IToken[] getCompletionsForToken(File file, IDocument doc, ICompletionState state) { IModule module = createModule(file, doc, state, this); ! return getCompletionsForModule(module, state); } --- 290,294 ---- public IToken[] getCompletionsForToken(File file, IDocument doc, ICompletionState state) { IModule module = createModule(file, doc, state, this); ! return getCompletionsForModule(module, state, true, true); } *************** *** 301,305 **** IModule module = AbstractModule.createModule(n); ! completionsForModule = getCompletionsForModule(module, state); } catch (CompletionRecursionException e) { --- 303,307 ---- IModule module = AbstractModule.createModule(n); ! completionsForModule = getCompletionsForModule(module, state, true, true); } catch (CompletionRecursionException e) { *************** *** 366,378 **** */ public IToken[] getCompletionsForModule(IModule module, ICompletionState state, boolean searchSameLevelMods) { if(PyCodeCompletion.DEBUG_CODE_COMPLETION){ Log.toLogFile(this, "getCompletionsForModule"); } ArrayList<IToken> importedModules = new ArrayList<IToken>(); if(state.getLocalImportsGotten() == false){ //in the first analyzed module, we have to get the local imports too. state.setLocalImportsGotten (true); if(module != null){ ! importedModules.addAll(module.getLocalImportedModules(state.getLine(), state.getCol())); } } --- 368,391 ---- */ public IToken[] getCompletionsForModule(IModule module, ICompletionState state, boolean searchSameLevelMods) { + return getCompletionsForModule(module, state, true, false); + } + + /** + * @see org.python.pydev.editor.codecompletion.revisited.ICodeCompletionASTManage#getCompletionsForModule(org.python.pydev.editor.codecompletion.revisited.modules.AbstractModule, org.python.pydev.editor.codecompletion.revisited.CompletionState, boolean, boolean) + */ + public IToken[] getCompletionsForModule(IModule module, ICompletionState state, boolean searchSameLevelMods, boolean lookForArgumentCompletion) { if(PyCodeCompletion.DEBUG_CODE_COMPLETION){ Log.toLogFile(this, "getCompletionsForModule"); } ArrayList<IToken> importedModules = new ArrayList<IToken>(); + ILocalScope localScope = null; if(state.getLocalImportsGotten() == false){ //in the first analyzed module, we have to get the local imports too. state.setLocalImportsGotten (true); if(module != null){ ! localScope = module.getLocalScope(state.getLine(), state.getCol()); ! if(localScope != null){ ! importedModules.addAll(localScope.getLocalImportedModules(state.getLine(), state.getCol(), module.getName())); ! } } } *************** *** 386,390 **** int parI = act.indexOf('('); if(parI != -1){ ! state.setActivationToken(act.substring(0, parI)); state.setLookingForInstance(true); } --- 399,404 ---- int parI = act.indexOf('('); if(parI != -1){ ! act = act.substring(0, parI); ! state.setActivationToken(act); state.setLookingForInstance(true); } *************** *** 432,445 **** //first check if the token is a module... if it is, get the completions for that module. ! IToken[] t = findTokensOnImportedMods(importedModules.toArray(new IToken[0]), state, module); ! if(t != null && t.length > 0){ ! return t; } //if it is an __init__, modules on the same level are treated as local tokens if(searchSameLevelMods){ ! t = searchOnSameLevelMods(initial, state); ! if(t != null && t.length > 0){ ! return t; } } --- 446,459 ---- //first check if the token is a module... if it is, get the completions for that module. ! IToken[] tokens = findTokensOnImportedMods(importedModules.toArray(new IToken[0]), state, module); ! if(tokens != null && tokens.length > 0){ ! return tokens; } //if it is an __init__, modules on the same level are treated as local tokens if(searchSameLevelMods){ ! tokens = searchOnSameLevelMods(initial, state); ! if(tokens != null && tokens.length > 0){ ! return tokens; } } *************** *** 466,470 **** //it was not a module (would have returned already), so, try to get the completions for a global token defined. - IToken[] tokens = null; tokens = module.getGlobalTokens(state, this); if (tokens.length > 0){ --- 480,483 ---- *************** *** 482,485 **** --- 495,505 ---- } } + + if(lookForArgumentCompletion){ + tokens = getArgsCompletion(state, localScope); + if(tokens != null && tokens.length > 0){ + return tokens; + } + } return getAssignCompletions( module, state); *************** *** 494,497 **** --- 514,541 ---- } + + + + /** + * Get the completions based on the arguments received + * + * @param state this is the state used for the completion + * @param localScope this is the scope we're currently on (may be null) + */ + private IToken[] getArgsCompletion(ICompletionState state, ILocalScope localScope) { + if (localScope != null){ + LocalScope s = (LocalScope) localScope; + IToken[] args = localScope.getLocalTokens(-1,-1,true); //only to get the args + String activationToken = state.getActivationToken(); + String firstPart = FullRepIterable.getFirstPart(activationToken); + for (IToken token : args) { + if(token.getRepresentation().equals(firstPart)){ + return s.getInterfaceForLocal(firstPart, state.getActivationToken()); + } + } + } + return null; + } + /** * Attempt to search on modules on the same level as this one (this will only happen if we are in an __init__ |