Esempio n. 1
0
    def callback(self):
        line_num = self.line_num
        key = self.key
        view = self.view
        # info(":callback: line {0} key {1} point{2}".format(
        #      line_num,  key,  view.text_point(line_num - 1, 0)))
        # sublime has some bug and this is a workaround
        #use case: when load src, if file is too large, scoll will not work
        #wkr: temp wait when file completes loading
        if view.text_point(line_num - 1, 0) == 0 and \
            self.wait_count < ScrollHighlightCommand.MAX_RETRY:
            sublime.set_timeout(self.callback, 550)
            self.wait_count += 1
            return

        sel_start = view.text_point(line_num - 1, 0)
        sel_end = view.text_point(line_num, 0) - 1

        line_region = sublime.Region(view.text_point(line_num - 1, 0),
                                     view.text_point(line_num, 0))
        line = view.substr(line_region)
        # info("Region {0}   row_count {2}".format(
        #     line_region, line, line_num))

        if not key in line:
            info("no key '{0}' in line '{1}' view {2}' ".format(
                key, line, view.file_name()))
        else:
            st_idx = line.rindex(key)
            sel_start += st_idx
            sel_end = sel_start + len(key)

        view.sel().clear()
        view.sel().add(sublime.Region(sel_start, sel_end))
        view.show_at_center(view.text_point(line_num - 1, 0))
Esempio n. 2
0
    def _load_project_data(self):
        project_data = self.win.project_data()
        self.project_name = self.win.project_file_name()

        self.path_cscope_lib = project_data["path_cscope_lib"]
        self.init_files = project_data[
            "initial_files"] if "initial_files" in project_data else []

        info("Initiated: {}".format(os.path.basename(self.project_name)))
Esempio n. 3
0
    def run(self, edit, mode=None, word=None):

        if not self.win_manager:
            self.win_manager = WindowManger(self.view.window())
            self.win_manager.make_sure_initiated()
            self.proj_central = ProjectCentral.Get(self.project_name)
        if not word:
            valid, word = Validator.WantedLookup(self.view)
            if not valid:
                return
        if word == self.processing_word:
            return
        self.processing_word = word

        #lookup mode selection

        if mode == "def_only":
            info("Lookup Def: {}".format(word))
            dfn = self.proj_central.FindDef(word)
            symref = ""

        else:
            info("Lookup Both: {}".format(word))
            [dfn, symref] = self.proj_central.FindBoth(word)

        #parse result
        main_console_text, dfn_path, line_num = self.formatter.Parse(
            dfn, symref, word, self.win_manager.Root())

        #print on main console
        self.win_manager.PrintMain(main_console_text)

        #read dfn file and scroll to that line
        self.view.run_command(
            "load_win", {
                "filepath": dfn_path,
                "line_num": line_num,
                "word": word,
                "mode": "load_def"
            })
Esempio n. 4
0
 def make_sure_initiated(self):
     if not ProjectCentral.Exist(self.project_name):
         info("make_sure_initiated ")
         self.win.run_command("init_heisenberg")
Esempio n. 5
0
 def run(self):
     ProjectCentral.Get(self.project_name).SaveToDisk()
     info("")