oleg-shilo / sublime-codemap

CodeMap - is a ST3 plugin for showing the code tree representing the code structure of the active view/document
MIT License
41 stars 4 forks source link

au3 mapper wrong? #20

Closed xianggithubli closed 6 years ago

xianggithubli commented 6 years ago

below is au3 mapper :

`import codecs
map_syntax = 'Packages/AutoItScript/AutoIt.tmLanguage'

def generate(file):
    return autoit_mapper.generate(file)

class autoit_mapper():
    # -----------------
    def generate(file):

        # Pasrse
        item_max_length = 0

        try:
            members = []

            with codecs.open(file, "r") as f:
            # with codecs.open(file, "r", encoding='gbk') as f:
                lines = f.read().split('\n')

            line_num = 0
            for line in lines:
                line = line.replace('\t', '    ')
                line_num = line_num + 1
                code_line = line.lstrip()

                info = None

                if code_line.startswith('Func ') or code_line.startswith('func '):
                    info = (line_num, code_line.split('(')[0].rstrip()+'()')

                if info:
                    length = len(info[1])
                    if item_max_length < length:
                        item_max_length = length
                    members.append(info)

        except Exception as err:
            print ('CodeMap-au3:', err)
            members.clear()

        # format
        map = ''
        for line, content,  in members:
            map = map+'\n'
        return map`

and console output below:

Traceback (most recent call last):
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 389, in run_callback
    expr()
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 452, in <lambda>
    run_callback('on_close', callback, lambda: callback.on_close(v))
  File "sublime_gbk in D:\ProgramFiles\programing\SublimeText303143\Data\Installed Packages\GBK Support.sublime-package", line 58, in on_close
TypeError: argument of type 'NoneType' is not iterable
Traceback (most recent call last):
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 389, in run_callback
    expr()
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 488, in <lambda>
    run_callback('on_modified', callback, lambda: callback.on_modified(v))
  File "D:\ProgramFiles\programing\SublimeText303143\Data\Packages\SublimeCodeIntel\SublimeCodeIntel.py", line 1439, in on_modified
    sublime_scope = getSublimeScope(view)
  File "D:\ProgramFiles\programing\SublimeText303143\Data\Packages\SublimeCodeIntel\SublimeCodeIntel.py", line 391, in getSublimeScope
    sel = view_sel[0]
  File "D:\ProgramFiles\programing\SublimeText303143\sublime.py", line 641, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 389, in run_callback
    expr()
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 505, in <lambda>
    run_callback('on_selection_modified', callback, lambda: callback.on_selection_modified(v))
  File "D:\ProgramFiles\programing\SublimeText303143\Data\Packages\SublimeCodeIntel\SublimeCodeIntel.py", line 1520, in on_selection_modified
    rowcol = view.rowcol(view_sel[0].end())
  File "D:\ProgramFiles\programing\SublimeText303143\sublime.py", line 641, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 389, in run_callback
    expr()
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 488, in <lambda>
    run_callback('on_modified', callback, lambda: callback.on_modified(v))
  File "D:\ProgramFiles\programing\SublimeText303143\Data\Packages\SublimeCodeIntel\SublimeCodeIntel.py", line 1439, in on_modified
    sublime_scope = getSublimeScope(view)
  File "D:\ProgramFiles\programing\SublimeText303143\Data\Packages\SublimeCodeIntel\SublimeCodeIntel.py", line 391, in getSublimeScope
    sel = view_sel[0]
  File "D:\ProgramFiles\programing\SublimeText303143\sublime.py", line 641, in __getitem__
    raise IndexError()
IndexError
Traceback (most recent call last):
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 389, in run_callback
    expr()
  File "D:\ProgramFiles\programing\SublimeText303143\sublime_plugin.py", line 505, in <lambda>
    run_callback('on_selection_modified', callback, lambda: callback.on_selection_modified(v))
  File "D:\ProgramFiles\programing\SublimeText303143\Data\Packages\SublimeCodeIntel\SublimeCodeIntel.py", line 1520, in on_selection_modified
    rowcol = view.rowcol(view_sel[0].end())
  File "D:\ProgramFiles\programing\SublimeText303143\sublime.py", line 641, in __getitem__
    raise IndexError()
IndexError
oleg-shilo commented 6 years ago

I am not sure about this issue. There is no a question nor description of any sort. There is an incomplete mapper code with some console traces that have nothing about CodeMap.

What exactly you are trying to say?


Just if you are having problems with you mapper I have attached something that works:

image

Note, you will need to enable your mapped on settings file: image

Place your mapper script into C:\Users\user\AppData\Roaming\Sublime Text 3\Packages\User\CodeMap\custom_mappers

And ensure your script produces the map. You don't meed CodeMap for that. You just execute your routine outside of the CodeMap and verify that it produces the map text. Right now it doesn't. It simply produces the empty text.

In the attached script I have modified the map building string and switched off setting the language. You should check if the language you want to return is available on Sublime (have a look at 'code_map.py.py') for that.

code_map.au3.py.zip

xianggithubli commented 6 years ago

oleg-shilo,tks,I found the bug, the code is ok to run if the last two lines were revised as below: ` map = map + content +' :'+str(line) +'\n'

return map`