Ejemplo n.º 1
0
 def unparse(self):
     return [[
         key(":type"),
         sym("element"),
         key(":object-id"), self.object_id,
         key(":index"), self.index
     ]]
Ejemplo n.º 2
0
 def unparse(self):
     return [[
         key(":type"),
         sym("field"),
         key(":object-id"), self.object_id,
         key(":field"), self.field
     ]]
Ejemplo n.º 3
0
    def clang(self, req, filename, call_id):
        cmd = None
        sys.stdout.flush()

        if util.is_unit(filename):
            cmd = self.clang_base_cmd() + [filename]
            util.send_sexp(
                req, [key(":clear-file-notes"), [filename]])
        elif util.is_header(filename):
            self.__nuke_all_precompiled_headers()
            util.send_sexp(
                req,
                [key(":clear-all-notes"), True])

            dg = depgraph.DepGraph(self.source_roots, self.compile_include_dirs)
            invalidated = dg.files_including(filename)
            units = [f for f in invalidated if util.is_unit(f)]

#            print "Clearing errors in " + str(len(units)) + " files."
#            util.send_sexp(
#                    req, [key(":clear-file-notes"), list(invalidated)])
#
            print "Recompiling " + str(len(units)) + " dependent units."
            cmd = self.clang_base_cmd() + units
            sys.stdout.flush()
        else:
            assert False, "WTF. Not header OR source unit?"

        clang_output = util.run_process(" ".join(cmd))
        self.receive_syntax_checker_output(req, clang_output)
        util.send_sexp(req, util.return_ok(True, call_id))
Ejemplo n.º 4
0
    def unparse(self):
        base = [key(":file"), self.file]

        if self.contents is not None:
            base.extend([key(":contents"), self.contents])
        if self.contents_in is not None:
            base.extend([key(":contents-in"), self.contents_in])
        return [base]
Ejemplo n.º 5
0
    def unparse(self):
        base = [key(":file"), self.file]

        if self.contents is not None:
            base.extend([key(":contents"), self.contents])
        if self.contents_in is not None:
            base.extend([key(":contents-in"), self.contents_in])
        return [base]
Ejemplo n.º 6
0
 def unparse(self):
     return [[
         key(":type"),
         sym("slot"),
         key(":thread-id"), self.thread_id,
         key(":frame"), self.frame,
         key(":offset"), self.offset
     ]]
Ejemplo n.º 7
0
 def handle_sexp(self, in_sexp):
     call_id = in_sexp[-1]
     if in_sexp[0] == key(":swank-rpc"):
         req = in_sexp[1]
         rpc_tag = req[0]
         print "Handling swank:rpc " + str(rpc_tag) + " request."
         if rpc_tag == key("swank:connection-info"):
             proj.handle_rpc_connection_info(req, self.request, call_id)
         elif rpc_tag == key("swank:init-project"):
             proj.handle_rpc_init_project(req, self.request, call_id)
         elif rpc_tag == key("swank:check-file"):
             proj.handle_rpc_check_file(req, self.request, call_id)
         elif rpc_tag == key("swank:check-all"):
             proj.handle_rpc_check_all(req, self.request, call_id)
         elif rpc_tag == key("swank:analyze-all"):
             proj.handle_rpc_analyze_all(req, self.request, call_id)
         elif rpc_tag == key("swank:analyze-file"):
             proj.handle_rpc_analyze_file(req, self.request, call_id)
         elif rpc_tag == key("swank:completions"):
             proj.handle_rpc_completions(req, self.request, call_id)
         else:
             print "Unrecognized rpc " + str(rpc_tag)
             util.send_sexp(self.request, 
                            util.return_ok(False, call_id))
     else:
         print "Unrecognized call type " + str(in_sexp)
         util.send_sexp(self.request, 
                        util.return_ok(False, call_id))
Ejemplo n.º 8
0
 def handle_reply(self, server_info):
   if server_info[1][0] == key(":ok"):
     sublime.status_message("Initializing... ")
     ensime_environment.ensime_env.client().initialize_project(self.handle_init_reply)
   else:
     sublime.error_message("There was problem initializing ensime, msgno: " + 
                           str(server_info[2]) + ".")
Ejemplo n.º 9
0
def sexp_to_key_map(sexp):
    key_type = type(key(":key"))
    result = {}
    for i in xrange(0, len(sexp), 2):
        k, val = sexp[i], sexp[i + 1]
        if type(k) == key_type:
            result[str(k)] = val
    return result
Ejemplo n.º 10
0
 def parse_list(cls, raw):
     if not raw: return []
     if type(raw[0]) == type(key(":key")):
         m = sexp.sexp_to_key_map(raw)
         field = ":" + cls.__name__.lower() + "s"
         return [cls.parse(raw) for raw in (m[field] if field in m else [])]
     else:
         return [cls.parse(raw) for raw in raw]
Ejemplo n.º 11
0
 def parse_list(cls, raw):
     if not raw: return []
     if type(raw[0]) == type(key(":key")):
         m = sexp.sexp_to_key_map(raw)
         field = ":" + cls.__name__.lower() + "s"
         return [cls.parse(raw) for raw in (m[field] if field in m else [])]
     else:
         return [cls.parse(raw) for raw in raw]
Ejemplo n.º 12
0
def sexp_to_key_map(sexp):
    key_type = type(key(":key"))
    result = {}
    for i in xrange(0, len(sexp), 2):
        k,val = sexp[i],sexp[i+1]
        if type(k) == key_type:
            result[str(k)] = val
    return result
Ejemplo n.º 13
0
    def clang_analyze_all(self, req, call_id):
        cmd = self.analyzer_base_cmd()
        for s in self.all_units():
            cmd.append(s)

        clang_output = util.run_process(" ".join(cmd))

        util.send_sexp(
            req,
            [key(":clear-all-notes"), True])

        self.receive_syntax_checker_output(req, clang_output)

        util.send_sexp(req, util.return_ok(True, call_id))

        util.send_sexp(
            req,
            [key(":full-check-finished"), True])
Ejemplo n.º 14
0
 def handle_reply(self, server_info):
     if server_info[1][0] == key(":ok"):
         sublime.status_message("Initializing... ")
         ensime_environment.ensime_env.client().initialize_project(
             self.handle_init_reply)
     else:
         sublime.error_message(
             "There was problem initializing ensime, msgno: " +
             str(server_info[2]) + ".")
Ejemplo n.º 15
0
 def clang_completions(self, req, filename, line, col, prefix, call_id):
     cmd = self.clang_completions_base_cmd(filename, line, col)
     print cmd
     sys.stdout.flush()
     clang_output = util.run_process(" ".join(cmd))
     candidates = []
     for line in clang_output:
         print line
         m = self.RE_COMPLETION.match(line)
         if m:
             name = m.group(1)
             tpe = m.group(2)
             if name.find(prefix) == 0:
                 candidates.append(
                     [key(":name"),m.group(1),
                      key(":type-sig"),m.group(2),
                      key(":is-callable"),False,
                      ])
     util.send_sexp(req, util.return_ok(candidates, call_id))
Ejemplo n.º 16
0
    def clang_analyze_file(self, req, filename, call_id):
        cmd = self.analyzer_base_cmd() + [filename]

        clang_output = util.run_process(" ".join(cmd))

        util.send_sexp(
            req,
            [key(":clear-all-notes"), True])

        self.receive_syntax_checker_output(req, clang_output)

        util.send_sexp(req, util.return_ok(True, call_id))
Ejemplo n.º 17
0
    def handle_rpc_init_project(self, rpc, req, call_id):

        conf = util.sexp_to_key_map(rpc[1])

        self.root_dir = os.path.abspath(conf[':root-dir'])
        self.source_roots = [os.path.join(self.root_dir,r) for r in (conf[':source-roots'] or [])]
        self.project_name = "Unnamed Project"

        self.compile_options = conf[':compile-options'] or []
        self.compile_directives = conf[':compile-directives'] or []
        self.compile_include_dirs = conf[':compile-include-dirs'] or []
        self.compile_include_headers = conf[':compile-include-headers'] or []
        self.analyzer_options = conf[':analyzer-options'] or []
        self.completion_options = conf[':completion-options'] or []

        util.send_sexp(req,
                       util.return_ok([
                    key(":project-name"), self.project_name,
                    key(":source-roots"), self.source_roots,
                    key(":root-dir"), self.root_dir,
                    ], call_id))
Ejemplo n.º 18
0
 def receive_syntax_checker_output(self, req, clang_output):
     for line in clang_output:
         m = self.RE_ITEM.match(line)
         if m:
             print line
             sys.stdout.flush()
             filename = m.group(1)
             line = int(m.group(2))
             col = int(m.group(3))
             item_type = m.group(4)
             msg = m.group(5)
             util.send_sexp(
                 req,
                 [key(":notes"), 
                  [key(":notes"),
                   [[key(":file"), filename,
                     key(":line"), line,
                     key(":col"), col,
                     key(":beg"), False,
                     key(":end"), False,
                     key(":severity"), sym(self.SEVERITY_MAP[item_type]),
                     key(":msg"), msg
                     ]]]])
Ejemplo n.º 19
0
    def on_data(self, data):
        print "on_data: " + str(data)
        self.feedback(str(data))
        # match a message with a registered response handler.
        # if the message has no registered handler check if it's a
        # background message.
        if data[0] == key(":return"):
            th = self._reply_handlers

            # if data[0][0][0][1:] == "procedure-id" and self.procedure_handlers.has_key(data[0][0][1]):
            #   self.procedure_handlers[data[0][0][1]](data)
            #   del self.proceure_handlers[data[0][0][1]]

            if self.message_handlers.has_key(data[-1]):
                reply_type = str(data[1][0])
                th[reply_type](data)
            else:
                print "Unhandled message: " + str(data)
        else:
            self.handle_server_message(data)
Ejemplo n.º 20
0
  def on_data(self, data):
    print "on_data: " + str(data)
    self.feedback(str(data))
    # match a message with a registered response handler.
    # if the message has no registered handler check if it's a 
    # background message.
    if data[0] == key(":return"):
      th = self._reply_handlers

      # if data[0][0][0][1:] == "procedure-id" and self.procedure_handlers.has_key(data[0][0][1]):
      #   self.procedure_handlers[data[0][0][1]](data)
      #   del self.proceure_handlers[data[0][0][1]]

      if self.message_handlers.has_key(data[-1]):
        reply_type = str(data[1][0])
        th[reply_type](data)
      else:
        print "Unhandled message: " + str(data)
    else:
        self.handle_server_message(data)
Ejemplo n.º 21
0
def load(window):
  """Intelligently guess the appropriate .ensime file location for the
  given window. Load the .ensime and parse as s-expression.
  Return: (inferred project root directory, config sexp)
  """
  for f in locations(window):
    root = encode_path(os.path.dirname(f))
    src = "()"
    with open(f) as open_file:
      src = open_file.read()
    try:
      conf = sexp.read_relaxed(src)
      m = sexp.sexp_to_key_map(conf)
      if m.get(":root-dir"):
        root = m[":root-dir"]
      else:
        conf = conf + [key(":root-dir"), root]
      return (root, conf, None)
    except:
      return (None, None, bind(error_bad_config, window, f, sys.exc_info()))
  return (None, None, bind(error_no_config, window))
Ejemplo n.º 22
0
def load(window):
    """Intelligently guess the appropriate .ensime file location for the
    given window. Load the .ensime and parse as s-expression.
    Return: (inferred project root directory, config sexp)
    """
    for f in locations(window):
        root = encode_path(os.path.dirname(f))
        src = "()"
        with open(f) as open_file:
            src = open_file.read()
        try:
            conf = sexp.read_relaxed(src)
            m = sexp.sexp_to_key_map(conf)
            if m.get(":root-dir"):
                root = m[":root-dir"]
            else:
                conf = conf + [key(":root-dir"), root]
            return (root, conf, None)
        except:
            return (None, None, bind(error_bad_config, window, f, sys.exc_info()))
    return (None, None, None)
Ejemplo n.º 23
0
 def unparse(self):
     return [[
         key(":type"),
         sym("reference"),
         key(":object-id"), self.object_id
     ]]
Ejemplo n.º 24
0
 def format(self, data, count=None):
     if count:
         return [key(":swank-rpc"), data, count]
     else:
         return [key(":swank-rpc"), data]
Ejemplo n.º 25
0
 def __initialize_project(self, conf, subproj_name, on_complete):
   conf = conf + [key(":root-dir"), self.project_root]
   conf = conf + [key(":active-subproject"), subproj_name]
   self.req([sym("swank:init-project"), conf], on_complete)
Ejemplo n.º 26
0
 def format(self, data, count = None):
   if count:
     return [key(":swank-rpc"), data, count]
   else:
     return [key(":swank-rpc"), data]
Ejemplo n.º 27
0
 def handle_rpc_connection_info(self, rpc, req, call_id):
     util.send_sexp(req, util.return_ok(                
             [key(":pid"),os.getpid(),
              key(":style"),False,
              key(":server-implementation"),[
                     key(":type"),False,
                     key(":name"),False,
                     key(":version"),"0.0.1",
                     key(":program"),False
                     ],
              key(":machine"),[
                     key(":instance"),False,
                     key(":type"),False,
                     key(":version"),False
                     ],
              key(":features"),False,
              key(":package"),False,
              key(":version"), "0.0.1",
              key(":modules"),False,
              ], call_id))
Ejemplo n.º 28
0
 def unparse(self):
     return [
         [key(":type"), sym("slot"), key(":thread-id"), self.thread_id, key(":frame"), self.frame, key(":offset"),
          self.offset]]
Ejemplo n.º 29
0
 def unparse(self):
     return [[key(":type"), sym("field"), key(":object-id"), self.object_id, key(":field"), self.field]]
Ejemplo n.º 30
0
 def unparse(self):
     return [[key(":type"), sym("reference"), key(":object-id"), self.object_id]]
Ejemplo n.º 31
0
 def __initialize_project(self, conf, subproj_name, on_complete):
     conf = conf + [key(":root-dir"), self.project_root]
     conf = conf + [key(":active-subproject"), subproj_name]
     self.req([sym("swank:init-project"), conf], on_complete)
Ejemplo n.º 32
0
 def unparse(self):
     return [[key(":type"), sym("element"), key(":object-id"), self.object_id, key(":index"), self.index]]
Ejemplo n.º 33
0
def return_ok(val, call_id):
    return [key(":return"), [ key(":ok"), val ], call_id]