[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited ASTManager.java,1.
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-02-16 16:49:30
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9724/src/org/python/pydev/editor/codecompletion/revisited Modified Files: ASTManager.java Log Message: Code completion improvement Index: ASTManager.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/revisited/ASTManager.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ASTManager.java 14 Feb 2005 11:51:24 -0000 1.20 --- ASTManager.java 16 Feb 2005 16:48:48 -0000 1.21 *************** *** 429,432 **** --- 429,468 ---- } + /** + * Identifies the token passed and if it maps to a builtin not 'easily recognizable', as + * a string or list, we return it. + * + * @param state + * @return + */ + private IToken[] getBuiltinsCompletions(CompletionState state){ + //check for the builtin types. + if(state.activationToken.endsWith("'") || state.activationToken.endsWith("\"")){ + //ok, we are getting code completion for a string. + AbstractModule m = getModule("__builtin__", state.nature); + return m.getGlobalTokens("str", this, state.line, state.col, state.nature); + } + + if(state.activationToken.endsWith("]")){ + //ok, we are getting code completion for a string. + AbstractModule m = getModule("__builtin__", state.nature); + return m.getGlobalTokens("list", this, state.line, state.col, state.nature); + } + + try { + Integer.parseInt(state.activationToken); + AbstractModule m = getModule("__builtin__", state.nature); + return m.getGlobalTokens("int", this, state.line, state.col, state.nature); + } catch (Exception e) { //ok, not parsed as int + } + + try { + Float.parseFloat(state.activationToken); + AbstractModule m = getModule("__builtin__", state.nature); + return m.getGlobalTokens("float", this, state.line, state.col, state.nature); + } catch (Exception e) { //ok, not parsed as int + } + return null; + } /** *************** *** 439,443 **** */ public IToken[] getCompletionsForModule(AbstractModule module, CompletionState state) { ! if (module != null) { --- 475,483 ---- */ public IToken[] getCompletionsForModule(AbstractModule module, CompletionState state) { ! IToken[] builtinsCompletions = getBuiltinsCompletions(state); ! if(builtinsCompletions != null){ ! return builtinsCompletions; ! } ! if (module != null) { *************** *** 450,453 **** --- 490,502 ---- List completions = getGlobalCompletions(globalTokens, importedModules, wildImportedModules, state); + + //now find the locals for the module + if (state.line >= 0){ + IToken[] localTokens = module.getLocalTokens(state.line, state.col); + for (int i = 0; i < localTokens.length; i++) { + completions.add(localTokens[i]); + } + } + return (IToken[]) completions.toArray(new IToken[0]); *************** *** 491,504 **** //If it was still not found, go to builtins. AbstractModule builtinsMod = getModule("__builtin__", state.nature); ! if(builtinsMod != null){ ! if(!state.recursing){ ! state.recursing = true; ! tokens = getCompletionsForModule( builtinsMod, state); ! if (tokens.length > 0){ ! if (tokens[0].getRepresentation().equals("ERROR:") == false){ ! return tokens; ! } ! } ! } } --- 540,550 ---- //If it was still not found, go to builtins. AbstractModule builtinsMod = getModule("__builtin__", state.nature); ! if(builtinsMod != null && builtinsMod != module){ ! tokens = getCompletionsForModule( builtinsMod, state); ! if (tokens.length > 0){ ! if (tokens[0].getRepresentation().equals("ERROR:") == false){ ! return tokens; ! } ! } } *************** *** 630,636 **** String rep = importedModules[i].getCompletePath(); ! Object [] o = findModuleFromPath(rep, state.nature); ! AbstractModule mod = (AbstractModule) o[0]; ! String tok = (String) o[1]; if(tok.length() == 0){ --- 676,707 ---- String rep = importedModules[i].getCompletePath(); ! Object [] o = null; ! AbstractModule mod = null; ! String tok = null; ! ! try { ! if (current instanceof SourceModule) { ! File f = ((SourceModule) current).getFile(); ! if (f != null) { ! String full = f.toString(); ! full = this.pythonPathHelper.resolveModule(full); ! full = full.substring(0, full.lastIndexOf('.')); ! if (full != null) { ! full += "." + rep; ! o = findModuleFromPath(full, state.nature); ! mod = (AbstractModule) o[0]; ! tok = (String) o[1]; ! } ! } ! } ! } catch (RuntimeException e) { ! e.printStackTrace();//that's ok... ! } ! ! if(o == null || mod == null || tok == null || current == mod || tok.equals(rep)){ ! o = findModuleFromPath(rep, state.nature); ! mod = (AbstractModule) o[0]; ! tok = (String) o[1]; ! } if(tok.length() == 0){ *************** *** 712,718 **** CompletionState copy = state.getCopy(); copy.activationToken = ""; ! return getCompletionsForModule(mod, state); }else if (mod != null){ ! return mod.getGlobalTokens(tok, this, state.line, state.col, state.nature); } } --- 783,796 ---- CompletionState copy = state.getCopy(); copy.activationToken = ""; ! return getCompletionsForModule(mod, copy); }else if (mod != null){ ! // return mod.getGlobalTokens(tok, this, state.line, state.col, state.nature); ! CompletionState copy = state.getCopy(); ! copy.activationToken = tok; ! copy.col = -1; ! copy.line = -1; ! ! return getCompletionsForModule(mod, copy); ! } } |