コード例 #1
0
 def run(self, edit):
     view = self.view
     unsaved_files = []
     if view.is_dirty():
         unsaved_files.append((sencode(view.file_name()),
                       view.substr(Region(0, view.size()))))
     translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files)
コード例 #2
0
 def run(self, edit):
     view = self.view
     unsaved_files = []
     if view.is_dirty():
         unsaved_files.append((sencode(view.file_name()),
                       view.substr(Region(0, view.size()))))
     translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files)
コード例 #3
0
ファイル: sublimeclang.py プロジェクト: ameyp/py-clang-util
 def recompile(self, view, callback):
     unsaved_files = []
     if view.is_dirty() and get_setting("reparse_use_dirty_buffer", False, view):
         unsaved_files.append((sencode(view.file_name()),
                               view.substr(Region(0, view.size()))))
     if not translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files,
                     callback):
         print "Already parsing."
         self.restart_recompile_timer(1)
コード例 #4
0
ファイル: sublimeclang.py プロジェクト: berkus/SublimeClang
    def recompile(self):
        view = self.view
        unsaved_files = []
        if view.is_dirty() and get_setting("reparse_use_dirty_buffer", False, view):
            unsaved_files.append((sencode(view.file_name()), view.substr(Region(0, view.size()))))
        if not translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files, self.reparse_done):

            # Already parsing so retry in a bit
            self.restart_recompile_timer(1)
コード例 #5
0
    def recompile(self):
        view = self.view
        unsaved_files = []
        if view.is_dirty() and get_setting("reparse_use_dirty_buffer", False, view):
            unsaved_files.append((sencode(view.file_name()),
                                  view.substr(Region(0, view.size()))))
        if not translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files,
                        self.reparse_done):

            # Already parsing so retry in a bit
            self.restart_recompile_timer(1)
コード例 #6
0
def warm_up_cache(view, filename=None):
    if filename == None:
        filename = sencode(view.file_name())
    stat = translationunitcache.tuCache.get_status(filename)
    if stat == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE:
        translationunitcache.tuCache.add(view, filename)
    return stat
コード例 #7
0
def show_error_marks(view):
    '''Adds error marks to view.'''
    erase_error_marks(view)
    if not get_setting("show_visual_error_marks", True):
        return
    fill_outlines = False
    gutter_mark = 'dot'
    outlines = {'warning': [], 'illegal': []}
    fn = sencode(view.file_name())
    markers = {'warning':  get_setting("marker_warning_scope", "comment"),
                'illegal': get_setting("marker_error_scope", "invalid")
                }

    for line in ERRORS[fn].keys():
        outlines['illegal'].append(view.full_line(view.text_point(line, 0)))
    for line in WARNINGS[fn].keys():
        outlines['warning'].append(view.full_line(view.text_point(line, 0)))

    for lint_type in outlines:
        if outlines[lint_type]:
            args = [
                'sublimeclang-outlines-{0}'.format(lint_type),
                outlines[lint_type],
                markers[lint_type],
                gutter_mark
            ]
            if not fill_outlines:
                args.append(sublime.DRAW_OUTLINED)
            view.add_regions(*args)
コード例 #8
0
ファイル: errormarkers.py プロジェクト: zmy235/SublimeClang
def show_error_marks(view):
    '''Adds error marks to view.'''
    erase_error_marks(view)
    if not get_setting("show_visual_error_marks", True):
        return
    fill_outlines = False
    gutter_mark = 'dot'
    outlines = {'warning': [], 'illegal': []}
    fn = sencode(view.file_name())
    markers = {
        'warning': get_setting("marker_warning_scope", "comment"),
        'illegal': get_setting("marker_error_scope", "invalid")
    }

    for line in ERRORS[fn].keys():
        outlines['illegal'].append(view.full_line(view.text_point(line, 0)))
    for line in WARNINGS[fn].keys():
        outlines['warning'].append(view.full_line(view.text_point(line, 0)))

    for lint_type in outlines:
        if outlines[lint_type]:
            args = [
                'sublimeclang-outlines-{0}'.format(lint_type),
                outlines[lint_type], markers[lint_type], gutter_mark
            ]
            if not fill_outlines:
                args.append(sublime.DRAW_OUTLINED)
            view.add_regions(*args)
コード例 #9
0
def warm_up_cache(view, filename=None):
    if filename == None:
        filename = sencode(view.file_name())
    stat = translationunitcache.tuCache.get_status(filename)
    if stat == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE:
        translationunitcache.tuCache.add(view, filename)
    return stat
コード例 #10
0
def get_translation_unit(view, filename=None, blocking=False):
    if filename == None:
        filename = sencode(view.file_name())
    if get_setting("warm_up_in_separate_thread", True, view) and not blocking:
        stat = warm_up_cache(view, filename)
        if stat == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE:
            return None
        elif stat == translationunitcache.TranslationUnitCache.STATUS_PARSING:
            sublime.status_message("Hold your horses, cache still warming up")
            return None
    return translationunitcache.tuCache.get_translation_unit(filename, translationunitcache.tuCache.get_opts(view), translationunitcache.tuCache.get_opts_script(view))
コード例 #11
0
def get_translation_unit(view, filename=None, blocking=False):
    if filename == None:
        filename = sencode(view.file_name())
    if get_setting("warm_up_in_separate_thread", True, view) and not blocking:
        stat = warm_up_cache(view, filename)
        if stat == translationunitcache.TranslationUnitCache.STATUS_NOT_IN_CACHE:
            return None
        elif stat == translationunitcache.TranslationUnitCache.STATUS_PARSING:
            sublime.status_message("Hold your horses, cache still warming up")
            return None
    return translationunitcache.tuCache.get_translation_unit(filename, translationunitcache.tuCache.get_opts(view), translationunitcache.tuCache.get_opts_script(view))
コード例 #12
0
ファイル: errormarkers.py プロジェクト: ensisoft/SublimeClang
def update_statusbar(view):
    fn = view.file_name()
    if fn is not None:
        fn = common.sencode(fn)
    lineno = last_selected_lineno(view)

    if fn in ERRORS and lineno in ERRORS[fn]:
        view.set_status("SublimeClang_line", "Error: %s" % "; ".join(ERRORS[fn][lineno]))
    elif fn in WARNINGS and lineno in WARNINGS[fn]:
        view.set_status("SublimeClang_line", "Warning: %s" % "; ".join(WARNINGS[fn][lineno]))
    else:
        view.erase_status("SublimeClang_line")
コード例 #13
0
ファイル: sublimeclang.py プロジェクト: berkus/SublimeClang
 def on_close(self, view):
     if not get_setting("pop_on_close", True, view):
         return
     # If the view we just closed was last in the navigation_stack,
     # consider it "popped" from the stack
     fn = view.file_name()
     if fn == None:
         return
     fn = sencode(fn)
     while True:
         if len(navigation_stack) == 0 or not navigation_stack[len(navigation_stack) - 1][1].startswith(fn):
             break
         navigation_stack.pop()
コード例 #14
0
def update_statusbar(view):
    fn = view.file_name()
    if fn is not None:
        fn = common.sencode(fn)
    lineno = last_selected_lineno(view)

    if fn in ERRORS and lineno in ERRORS[fn]:
        view.set_status('SublimeClang_line',
                        "Error: %s" % '; '.join(ERRORS[fn][lineno]))
    elif fn in WARNINGS and lineno in WARNINGS[fn]:
        view.set_status('SublimeClang_line',
                        "Warning: %s" % '; '.join(WARNINGS[fn][lineno]))
    else:
        view.erase_status('SublimeClang_line')
コード例 #15
0
 def on_close(self, view):
     if not get_setting("pop_on_close", True, view):
         return
     # If the view we just closed was last in the navigation_stack,
     # consider it "popped" from the stack
     fn = view.file_name()
     if fn == None:
         return
     fn = sencode(fn)
     while True:
         if len(navigation_stack) == 0 or \
                 not navigation_stack[
                     len(navigation_stack) - 1][1].startswith(fn):
             break
         navigation_stack.pop()
コード例 #16
0
ファイル: errormarkers.py プロジェクト: ensisoft/SublimeClang
 def run(self, edit):
     v = self.view
     fn = common.sencode(v.file_name())
     line, column = v.rowcol(v.sel()[0].a)
     gotoline = -1
     if fn in ERRORS:
         for errLine in ERRORS[fn]:
             if errLine < line:
                 gotoline = errLine
     if fn in WARNINGS:
         for warnLine in WARNINGS[fn]:
             if warnLine < line:
                 if gotoline == -1 or warnLine > gotoline:
                     gotoline = warnLine
     if gotoline != -1:
         v.window().open_file("%s:%d" % (fn, gotoline + 1), sublime.ENCODED_POSITION)
     else:
         sublime.status_message("No more errors or warnings!")
コード例 #17
0
 def run(self, edit):
     v = self.view
     fn = common.sencode(v.file_name())
     line, column = v.rowcol(v.sel()[0].a)
     gotoline = -1
     if fn in ERRORS:
         for errLine in ERRORS[fn]:
             if errLine < line:
                 gotoline = errLine
     if fn in WARNINGS:
         for warnLine in WARNINGS[fn]:
             if warnLine < line:
                 if gotoline == -1 or warnLine > gotoline:
                     gotoline = warnLine
     if gotoline != -1:
         v.window().open_file("%s:%d" % (fn, gotoline + 1),
                              sublime.ENCODED_POSITION)
     else:
         sublime.status_message("No more errors or warnings!")
コード例 #18
0
ファイル: errormarkers.py プロジェクト: ensisoft/SublimeClang
def show_error_marks(view):
    """Adds error marks to view."""
    erase_error_marks(view)
    fill_outlines = False
    gutter_mark = "dot"
    outlines = {"warning": [], "illegal": []}
    fn = common.sencode(view.file_name())
    markers = {"warning": "comment", "illegal": "invalid"}

    for line in ERRORS[fn].keys():
        outlines["illegal"].append(view.full_line(view.text_point(line, 0)))
    for line in WARNINGS[fn].keys():
        outlines["warning"].append(view.full_line(view.text_point(line, 0)))

    for lint_type in outlines:
        if outlines[lint_type]:
            args = ["sublimeclang-outlines-{0}".format(lint_type), outlines[lint_type], markers[lint_type], gutter_mark]
            if not fill_outlines:
                args.append(sublime.DRAW_OUTLINED)
            view.add_regions(*args)
コード例 #19
0
def show_error_marks(view):
    '''Adds error marks to view.'''
    erase_error_marks(view)
    fill_outlines = False
    gutter_mark = 'dot'
    outlines = {'warning': [], 'illegal': []}
    fn = common.sencode(view.file_name())
    markers = {'warning': "comment", 'illegal': "invalid"}

    for line in ERRORS[fn].keys():
        outlines['illegal'].append(view.full_line(view.text_point(line, 0)))
    for line in WARNINGS[fn].keys():
        outlines['warning'].append(view.full_line(view.text_point(line, 0)))

    for lint_type in outlines:
        if outlines[lint_type]:
            args = [
                'sublimeclang-outlines-{0}'.format(lint_type),
                outlines[lint_type], markers[lint_type], gutter_mark
            ]
            if not fill_outlines:
                args.append(sublime.DRAW_OUTLINED)
            view.add_regions(*args)
コード例 #20
0
ファイル: sublimeclang.py プロジェクト: ameyp/py-clang-util
 def reparse(self, view, callback):
     unsaved_files = []
     if view.is_dirty():
         unsaved_files.append((sencode(view.file_name()),
                       view.substr(Region(0, view.size()))))
     translationunitcache.tuCache.reparse(view, sencode(view.file_name()), unsaved_files, callback, (view,))
コード例 #21
0
 def has_errors(self, view):
     fn = view.file_name()
     if fn is None:
         return False
     return common.sencode(fn) in ERRORS or fn in WARNINGS
コード例 #22
0
def get_filename(view):
    return common.sencode(view.file_name())
コード例 #23
0
 def on_close(self, view):
     if self.remove_on_close and is_supported_language(view):
         translationunitcache.tuCache.remove(sencode(view.file_name()))
コード例 #24
0
ファイル: errormarkers.py プロジェクト: ensisoft/SublimeClang
 def has_errors(self, view):
     fn = view.file_name()
     if fn is None:
         return False
     return common.sencode(fn) in ERRORS or fn in WARNINGS
コード例 #25
0
    def on_query_completions(self, view, prefix, locations):
        global clang_complete_enabled
        if not is_supported_language(view) or not clang_complete_enabled or \
                not view.match_selector(locations[0], '-string -comment -constant'):
            return []

        line = view.substr(sublime.Region(view.line(locations[0]).begin(), locations[0]))
        match = re.search(r"[,\s]*(\w+)\s+\w+$", line)
        if match != None:
            valid = ["new", "delete", "return", "goto", "case", "const", "static", "class", "struct", "typedef", "union"]
            if match.group(1) not in valid:
                # Probably a variable or function declaration
                # There's no point in trying to complete
                # a name that hasn't been typed yet...
                return self.return_completions([], view)

        timing = ""
        tot = 0
        start = time.time()
        tu = get_translation_unit(view)
        if tu == None:
            return self.return_completions([], view)
        ret = None
        tu.lock()
        try:
            if self.time_completions:
                curr = (time.time() - start)*1000
                tot += curr
                timing += "TU: %f" % (curr)
                start = time.time()

            cached_results = None
            if clang_fast_completions and get_setting("enable_fast_completions", True, view):
                data = view.substr(sublime.Region(0, locations[0]))
                try:
                    cached_results = tu.cache.complete(data, prefix)
                except:
                    traceback.print_exc()
            if cached_results != None:
                # print("found fast completions")
                ret = cached_results
            else:
                # print("doing slow completions")
                row, col = view.rowcol(locations[0] - len(prefix))
                unsaved_files = []
                if view.is_dirty():
                    unsaved_files.append((sencode(view.file_name()),
                                      view.substr(Region(0, view.size()))))
                ret = tu.cache.clangcomplete(sencode(view.file_name()), row+1, col+1, unsaved_files, is_member_completion(view, locations[0] - len(prefix)))
            if self.time_completions:
                curr = (time.time() - start)*1000
                tot += curr
                timing += ", Comp: %f" % (curr)
                start = time.time()

            if len(self.dont_complete_startswith) and ret:
                i = 0
                while i < len(ret):
                    disp = ret[i][0]
                    pop = False
                    for comp in self.dont_complete_startswith:
                        if disp.startswith(comp):
                            pop = True
                            break

                    if pop:
                        ret.pop(i)
                    else:
                        i += 1

            if self.time_completions:
                curr = (time.time() - start)*1000
                tot += curr
                timing += ", Filter: %f" % (curr)
                timing += ", Tot: %f ms" % (tot)
                print(timing)
                sublime.status_message(timing)
        finally:
            tu.unlock()

        if not ret is None:
            return self.return_completions(ret, view)
        return self.return_completions([], view)
コード例 #26
0
def format_current_file(view):
    row, col = view.rowcol(view.sel()[0].a)
    return "%s:%d:%d" % (sencode(view.file_name()), row + 1, col + 1)
コード例 #27
0
def format_current_file(view):
    row, col = view.rowcol(view.sel()[0].a)
    return "%s:%d:%d" % (sencode(view.file_name()), row + 1, col + 1)
コード例 #28
0
    def on_query_completions(self, view, prefix, locations):
        global clang_complete_enabled
        if not is_supported_language(view) or not clang_complete_enabled or \
                not view.match_selector(locations[0], '-string -comment -constant'):
            return []

        line = view.substr(
            sublime.Region(view.line(locations[0]).begin(), locations[0]))
        match = re.search(r"[,\s]*(\w+)\s+\w+$", line)
        if match != None:
            valid = [
                "new", "delete", "return", "goto", "case", "const", "static",
                "class", "struct", "typedef", "union"
            ]
            if match.group(1) not in valid:
                # Probably a variable or function declaration
                # There's no point in trying to complete
                # a name that hasn't been typed yet...
                return self.return_completions([], view)

        timing = ""
        tot = 0
        start = time.time()
        tu = get_translation_unit(view)
        if tu == None:
            return self.return_completions([], view)
        ret = None
        tu.lock()
        try:
            if self.time_completions:
                curr = (time.time() - start) * 1000
                tot += curr
                timing += "TU: %f" % (curr)
                start = time.time()

            cached_results = None
            if clang_fast_completions and get_setting(
                    "enable_fast_completions", True, view):
                data = view.substr(sublime.Region(0, locations[0]))
                try:
                    cached_results = tu.cache.complete(data, prefix)
                except:
                    traceback.print_exc()
            if cached_results != None:
                # print("found fast completions")
                ret = cached_results
            else:
                # print("doing slow completions")
                row, col = view.rowcol(locations[0] - len(prefix))
                unsaved_files = []
                if view.is_dirty():
                    unsaved_files.append((sencode(view.file_name()),
                                          view.substr(Region(0, view.size()))))
                ret = tu.cache.clangcomplete(
                    sencode(view.file_name()), row + 1, col + 1, unsaved_files,
                    is_member_completion(view, locations[0] - len(prefix)))
            if self.time_completions:
                curr = (time.time() - start) * 1000
                tot += curr
                timing += ", Comp: %f" % (curr)
                start = time.time()

            if len(self.dont_complete_startswith) and ret:
                i = 0
                while i < len(ret):
                    disp = ret[i][0]
                    pop = False
                    for comp in self.dont_complete_startswith:
                        if disp.startswith(comp):
                            pop = True
                            break

                    if pop:
                        ret.pop(i)
                    else:
                        i += 1

            if self.time_completions:
                curr = (time.time() - start) * 1000
                tot += curr
                timing += ", Filter: %f" % (curr)
                timing += ", Tot: %f ms" % (tot)
                print(timing)
                sublime.status_message(timing)
        finally:
            tu.unlock()

        if not ret is None:
            return self.return_completions(ret, view)
        return self.return_completions([], view)
コード例 #29
0
 def on_close(self, view):
     if self.remove_on_close and is_supported_language(view):
         translationunitcache.tuCache.remove(sencode(view.file_name()))