Example #1
0
def get_context(view):
    s = view.settings()
    project = s.get('subclim.project', None)
    relative_path = s.get('subclim.project_relative_path', None)
    if project is None:
        project, relative_path = eclim.get_context(view.file_name())
        if project is not None:
            s.set('subclim.project', project)
        if relative_path is not None:
            s.set('subclim.project_relative_path', relative_path)
    return project, relative_path
Example #2
0
def get_context(view):
    s = view.settings()
    project = s.get('subclim.project', None)
    relative_path = s.get('subclim.project_relative_path', None)
    if project is None:
        project, relative_path = eclim.get_context(view.file_name())
        if project is not None:
            s.set('subclim.project', project)
        if relative_path is not None:
            s.set('subclim.project_relative_path', relative_path)
    return project, relative_path
def completion_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)

    proposals, with_snippets = to_proposals(call_eclim(project, file, pos))
    if with_snippets:
        completion_popup_with_snippet(proposals)
    else:
        completion_popup(proposals)
Example #4
0
def rename_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    identifier = current_identifier()
    pos = code.find(identifier, pos-len(identifier))
    
    new_name = util.get_input(default=identifier,title="Enter new name")
    
    call_eclim(project, file, len(identifier), pos, new_name)
def go_to_definition_command():
    project, file = eclim.get_context()    
    # we cannot read the code from TM via stdin, as it will not have 
    # the correct line endings when editing windows files (it will just have \n)
    #code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    identifier = current_identifier()
    pos = code.find(identifier, pos-len(identifier))

    locations = call_eclim(project, file, pos, len(identifier))
    locations = to_list(locations)
    if len(locations) == 1:
        go_to_location(locations[0])
Example #6
0
def get_context(view):
    s = view.settings()
    project = s.get('subclim.view.project', None)
    relative_path = s.get('subclim.view.project_relative_path', None)
    if project is None or relative_path is None:
        p, relative_path = eclim.get_context(view.file_name())

        if project is None:
            project = s.get('subclim_eclipse_project_name', None) or p

        if relative_path is None:
            root_path = s.get('subclim_eclipse_root_path', None)
            if root_path:
                relative_path = os.path.relpath(view.file_name(), root_path)

        if project is not None:   
            s.set('subclim.view.project', project)
        if relative_path is not None:
            s.set('subclim.view.project_relative_path', relative_path)
    return project, relative_path
def correction_command():
    project, file = eclim.get_context()
    # we cannot read the code from TM via stdin, as it will not have
    # the correct line endings when editing windows files (it will just have \n)
    # code = sys.stdin.read()

    # so we read from disk
    with open(os.environ["TM_FILEPATH"]) as f:
        code = f.read()
    pos = caret_position(code)
    line = int(os.environ["TM_LINE_NUMBER"])

    corrections = call_eclim(project, file, line, pos)
    corrections = to_list(corrections)
    if corrections:
        correction_to_apply = show_corrections_window(corrections)
    else:
        correction_to_apply = None
    if correction_to_apply != None:
        new_code = call_eclim(project, file, line, pos, correction_to_apply)
        if new_code:
            return new_code
    return code
Example #8
0
    
    
    complete_cmd = "$ECLIM -command java_import_order \
                             -p %s" % project
    popen = subprocess.Popen(
         complete_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE,shell=True)
    order, err = popen.communicate()
    return class_name.strip(), order

def add_import(code, class_name, order):
    if class_name=="":
        tooltip("No class found")
    elif "\n" in class_name:
        tooltip("Exception: "+class_name)
    else:
        lines = code.split("\n")
        last_import_idx = 0
        for idx, l in enumerate(lines):
            if "{" in l: break
            if "import" in l: last_import_idx = idx
        doc = "\n".join(lines[:last_import_idx+1] + ["import "+class_name+";"] + lines[last_import_idx+1:])
        return doc
    return code
    
project, file = eclim.get_context()
code = sys.stdin.read()
word = os.environ["TM_CURRENT_WORD"]
class_name, order = call_eclim(project, word)
new_code = add_import(code, class_name, order)
print new_code