Пример #1
0
    def run1 (self, use_display, inline_workaround = False):
        print "run HaxeFindDeclarationCommand"
        view = self.view

        file_name = view.file_name()

        if file_name == None:
            return

        project = hxproject.current_project(view)
        build = project.get_build(view).copy()
        build.args.append(("-D", "no-inline"))

        src = view_tools.get_content(view)

        file_name = os.path.basename(view.file_name())

        using_line = "\nusing hxsublime.FindDeclaration;\n"

        pos = view.sel()[0].a

        word = view.word(pos)

        word_start = word.a
        word_end = word.b

        word_str = src[word_start:word_end]

        prev = src[word_start-1]
        
        field_access = False
        if prev == ".":
            field_access = True

        add = ".sublime_find_decl()"

        if use_display:
            add += ".|"

        start = src[0:word_start]

        end = src[word_end:]

        if inline_workaround:
            add_x = "sublime_find_decl"         
            add_y = ""
            if use_display:
                add_y = ".|"
            new_src = start + add_x + "(" + word_str + ")" + add_y + end;
        else:
            new_src = start + word_str + add + end;

        package_decl = re.search(hxsrctools.package_line, new_src)

        if (package_decl == None):
            new_src = using_line + new_src
        else:
            new_src = new_src[0:package_decl.end(0)]+using_line+new_src[package_decl.end(0):len(new_src)]

        temp_path, temp_file = hxtemp.create_temp_path_and_file(build, view.file_name(), new_src)

        build.add_classpath(temp_path)

        build.add_classpath(plugin_path)
        
        if use_display:
            build.set_auto_completion(temp_file + "@0", False, False)

        server_mode = project.is_server_mode()


        out, err = build.run(project.haxe_exec(), project.haxe_env(), server_mode, view, project)

        hxtemp.remove_path(temp_path)
        

        file_pos = re.compile("\|\|\|\|\|([^|]+)\|\|\|\|\|", re.I)

        res = re.search(file_pos, out)
        if res != None:
            #we've got a proper response
            json_str = res.group(1)
            json_res = json.loads(json_str)

            self.handle_json_response(json_res, add, using_line, word_end, build, temp_path, temp_file, use_display, inline_workaround)
        else:

            if use_display:
                log("nothing found yet (2), try again without display (workaround)")
                self.run1(False)
            else:
                log("nothing found (3), cannot find declaration")
Пример #2
0
def hx_normal_auto_complete(project, view, offset, build, cache):
    
    completion_id = time.time()
    last_completion_id = project.completion_context.current_id

    trigger = project.completion_context.get_and_delete_trigger(view)
    

    manual_completion = trigger is not TRIGGER_SUBLIME

    macro_completion = trigger is TRIGGER_MANUAL_MACRO


    src = view_tools.get_content(view)
    orig_file = view.file_name()
    src_dir = os.path.dirname(orig_file)
    
    

    #find actual autocompletable char.
    prev = src[offset-1]
    
    commas, complete_offset, toplevel_complete, is_new = get_completion_info(view, offset, src, prev)
    
    # autocompletion is triggered, but its already 
    # running as a background process, starting it
    # again would result in multiple queries for
    # the same view and src position
    if project.completion_context.running.exists(last_completion_id):
        o1, id1 = project.completion_context.running.get_or_default(last_completion_id, None)
        if (o1 == complete_offset and id1 == view.id()):
            log("cancel completion, same is running")
            return cancel_completion(view, False)


    

    complete_char = src[complete_offset-1]

    in_control_struct = control_struct.search( src[0:complete_offset] ) is not None

    on_demand = hxsettings.top_level_completions_on_demand()

    toplevel_complete = (toplevel_complete or complete_char in ":(," or in_control_struct) and not on_demand

    if (hxsettings.no_fuzzy_completion() and not manual_completion and not toplevel_complete):
        log("trigger manual -> cancel completion")
        trigger_manual_completion(view, macro_completion)
        
        return cancel_completion(view)

    offset_char = src[offset]
    

    if (offset_char == "\n" and prev == "." and src[offset-2] == "." and src[offset-3] != "."):
        log("iterator completion")
        return [(".\tint iterator", "..")]

    

    comps = []
    log("toplevel_complete:" + str(toplevel_complete))
    if is_new or toplevel_complete :
        all_comps = get_toplevel_completion( project, src , build.copy(), macro_completion, is_new )

        comps = filter_top_level_completions(offset_char, all_comps)
    else:
        log("comps_from_not_top_level")
        comps = []
    
    

    if is_new or (toplevel_complete and (in_control_struct or complete_char not in "(,"))  :
        log("comps_from_top_level_and_control_struct")
        return comps


    

    delayed = hxsettings.is_delayed_completion()

    
    
    comps1 = []
    status = ""

    offset = complete_offset

    current_input = create_completion_input_key(orig_file, offset, commas, src, macro_completion, complete_char)

    

    last_input = cache["input"]

    log("DELAYED COMPLETION: " + str(delayed))

    use_cache = use_completion_cache(last_input, current_input)

    hints = []

    if use_cache :
        log("use completions from cache")
        ret, comps1, status, hints = cache["output"]
    else :
        log("not use cache")
        if supported_compiler_completion_char(complete_char): 
            log(build)
            temp_path, temp_file = hxtemp.create_temp_path_and_file(build, orig_file, src)

            if temp_path is None or temp_file is None:
                # this should never happen, todo proper error message
                log("completion error")
                return []

            build.add_classpath(temp_path)
            display = temp_file + "@" + str(offset)
            def run_compiler_completion (cb, async):
                return get_compiler_completion( project, build, view, display, temp_file, orig_file , async, cb, macro_completion )
            if delayed:
                log("run delayed compiler completion")
                background_completion(project, completion_id, list(comps), temp_file, orig_file,temp_path,
                    view, cache, current_input, complete_offset, run_compiler_completion)
                
                ret, comps1, status, hints = "", [], "", []
            else:
                log("run normal compiler completion")
                ret0 = []
                err0 = []
                def cb(out1, err1):
                    ret0.append(out1)
                    err0.append(err1)
                run_compiler_completion(cb, False)
                ret = ret0[0]
                err = err0[0]
                
                hxtemp.remove_path(temp_path)
                hints, comps1, status, errors = get_completion_output(temp_file, orig_file, err, commas)
                comps1 = [(t[0], t[1]) for t in comps1]
                highlight_errors( errors, view )
        else:
            log("not supported completion char")
            ret, comps1, status, hints = "",[], "", []

    comps.extend(comps1)

    log("hints1:" + str(hints))
    
    if not delayed:
        cache["output"] = (ret,comps1,status, hints)
        cache["input"] = current_input
    

    if status != "":
        if len(comps) > 0 or len(hints > 0):
            log(status)
        else:
            hxpanel.default_panel().writeln( status )


    
    if not use_cache and delayed and hxsettings.only_delayed_completions():
        log("delayed is running: completion cancelled")
        return cancel_completion(view, True)
    
    comps = combine_hints_and_comps(comps, hints)

    log("completion end")
    return comps