Komodo Edit 9.3.0 - Python : Find All Functions

Hi!

I upgraded my Komodo Edit to 9.3.0 last week… All has been working well, except for the following things when using it with a Python file

  1. Find All Functions - Ctrl-F8 - Gives error “No Python classes or functions found in the document” - there are plenty of both!
    regex shown = ^[ ]*?(def\s+[^\(]+\([^\)]*?\):|class\s+[^:]*?:)

  2. Local variables don’t appear to be coming up in the suggestion bubbles when typing them… If they do, there is a very long delay.

Otherwise, Love this editor!

Hi, could you share a small sample of code that contains Python functions Komodo is not picking up with Ctrl+F8? I cannot reproduce this with my Komodo.

As for local variables taking some time to show up, there are a number of potential causes:

(1) Komodo will only autocomplete them after the first three characters are typed.
(2) Komodo is currently indexing your project so there might be some lag now, but it should clear up later.
(3) 250ms is too slow for you. You can change it to be shorter by going to “Edit > Preferences”, “Code Intelligence”, select “Show All Settings” at the bottom left, then change the “Show completions after X msecs” preference. Note if you change it to something really short, you may experience some lag when you type rapidly.

The Ctrl+F8 functionality is very crude and simply won’t catch all functions for all use-cases. I’ve said this a while ago but it seems it slipped by: we need to remove this from Komodo Edit as stuff like this is better maintained as a separate userscript.

I would recommend you give Komodo IDE a shot as it does this type of stuff much better.

Found the relevant bug, I’ve marked it as priority so it doesn’t get bumped again:

Mitchell,

Here is a simple script that does NOT find any functions…

import string

class testing(object):

def __init__(self ):
    x = 1

def test1(self ):
    y = 2

Can I delete the contents of the code intelligence directory somewhere to get a clean bill of health?

Thanks for your assistance!

Steve

I have also found this error in file : pystderr.log

[2015-11-04 17:29:29,094] [ERROR] codeintel.komodo.KoCodeIntelManager: Error reading data from codeintel
Traceback (most recent call last):
File “C:\Program Files (x86)\ActiveState Komodo Edit 9\lib\mozilla\components\koCodeIntel.py”, line 1166, in run
ch = self.pipe.read(1)
File “C:\Program Files (x86)\ActiveState Komodo Edit 9\lib\mozilla\python\komodo\win32_named_pipe.py”, line 212, in read
raise ctypes.WinError(ctypes.get_last_error())
WindowsError: [Error 109] The pipe has been ended.

Hello!

Is there any movement on this bug? I’ve just upgraded to Komodo Edit 9.3.1 and the problem persists in every Python file that I have.

This was working perfectly in 9.2 and before…

Thanks!

Steve

Please see my post here:

This will not be fixed, we’ll be removing the functionality from edit as it is hacky and crude to begin with. You can easily copy/paste it into a userscript of your own and edit it as needed. Here is a sample userscript:

(function() {

    var language = require("ko/views").current().get('koDoc').languageObj;
    var re = "";
    if (language.name == "Python")
        re = /^[ ]*?(def\s+[^\(]+\([^\)]*?\):|class\s+[^:]*?:)/.toString().slice(1,-1);
    else if (language.name == "JavaScript")
        re = /^[ |\t]*?(?:([\w|\.|_]*?)\s*=\s*function|function\s*([\w|\_]*?)|([\w|\_]*?)\s*:\s*function).*?$/.toString().slice(1,-1);
    else
        return;
    
    var namedBlockDescription = language.namedBlockDescription;
    
    if (re == null || re == '') return;
    
    var findSvc = Cc["@activestate.com/koFindService;1"].getService(Ci.koIFindService);
    
    // save some find options
    var patternType, caseSensitivity, searchBackward, matchWord;
    patternType = findSvc.options.patternType;
    caseSensitivity = findSvc.options.caseSensitivity;
    searchBackward = findSvc.options.searchBackward;
    matchWord = findSvc.options.matchWord;
    
    findSvc.options.patternType = Ci.koIFindOptions.FOT_REGEX_PYTHON;
    findSvc.options.caseSensitivity = Ci.koIFindOptions.FOT_SENSITIVE;
    findSvc.options.searchBackward = false;
    findSvc.options.matchWord = false;
    
    var context = Cc["@activestate.com/koFindContext;1"]
                    .createInstance(Ci.koIFindContext);
    context.type = Ci.koIFindContext.FCT_CURRENT_DOC;
    ko.find.findAll(window, context, re.toString(), namedBlockDescription);
    
    // restore saved find options
    findSvc.options.patternType = patternType;
    findSvc.options.caseSensitivity = caseSensitivity;
    findSvc.options.searchBackward = searchBackward;
    findSvc.options.matchWord = matchWord;

})();

To get the currently configured regex for a file open in Komodo you can execute the following in the console:

require("ko/views").current().get('koDoc').languageObj.namedBlockRE

Again, this functionality will be stripped in a future version (probably Komodo 10), as it does not make sense as a native feature, at least not in its current shape. We may instead just include this as a toolbox sample item.

Thanks for the suggestions…

I DO find the find all functions feature VERY handy when working with a large file / class in Python. So convenient to click and jump to the functions…

Will try the user script to see if that works.

Steve

Note Komodo IDE has a convenient section list for this.

It used to work fine (not only for me, clearly). Now it is broken. Please just fix it!

It is a very useful, or even essential feature, even in the Edit only version of Komodo.

“Give us you money and get the IDE” is not very sympathetic advice. It DID work in Komodo Edit!

1 Like

this works well enough for me:

^\s*?(def|class)\s.?:\s?$

(from the start of the line, skipping whitespace, require the line to have 'def ’ or 'class ‘, then any amount of arbitrary stuff, then end in ‘:’, ignoring trailing spaces’)

I suppose you can write definitions that don’t match this, as I’m new to python.

BUT, while working that out, I found out that the real problem with the default search seems to be that if RE searching is disabled, it fails. Always.. So, open the find dialog, click on that star icon to enable RE matching, and ctrl-f8 works as intended.

Not sure why, nathanr’s post of the code looks like it is supposed to enable RE matching.

WooHoo! The fix of turning on the RegEx searching fixes my original problem with the Ctrl-F8 situation… :smiley: