def sendNotification(self, method, params): try: r = self.SendMsg(method, params) except OSError: self._observer.onServerDown() raise log.info('send notifications: %s' % method)
def downloadBinary(self, script_path): platform_desc, plat = self._DetectBinaryUrl() if not plat: EchoMessage('non supported platform %s' % platform_desc) return log.warn('downloading clangd binary from url %s' % plat['url']) tarball_file, _ = urlretrieve(plat['url']) if not plat['md5sum'] or not HashFile(tarball_file, 'md5') == plat['md5sum']: if not PresentYesOrNoDialog( 'failed to do checksum on %s, should we use this file?' % tarball_file): return log.warn('downloaded clangd binary to %s' % tarball_file) for dir_name in ['bin', 'lib']: dir_path = os.path.join(script_path, dir_name) if os.path.exists(dir_path): rmtree(dir_path) tar = tarfile.open(name=tarball_file, mode='r:gz') tar.extractall(path=script_path) try: os.unlink(tarball_file) log.info('removed temporary file %s' % tarball_file) except OSError: log.warn('failed to remove temporary file %s' % tarball_file) pass EchoMessage('clangd installed')
def __init__(self, clangd_executable, clangd_log_path, manager): clangd, fdRead, fdWrite, fdClangd = StartProcess( clangd_executable, clangd_log_path) log.info('clangd started, pid %d' % clangd.pid) self._clangd = clangd self._input_fd = fdRead self._output_fd = fdWrite self._clangd_logfd = fdClangd self._rpcclient = JsonRPCClient(self, fdRead, fdWrite) self._client_errs = 0 self._client_timeouts = 0 self._is_alive = True self._manager = manager
def CleanUp(self): if self._clangd.poll() == None: self._clangd.terminate() if self._clangd.poll() == None: self._clangd.kill() log.info('clangd stopped, pid %d' % self._clangd.pid) self._clangd_logfd.close() if sys_platform == 'win32': # only native win32 self._input_fd.close() self._output_fd.close() else: # posix or cygwin os.close(self._input_fd) os.close(self._output_fd)
def initialize(self): try: rr = self._SendRequest(Initialize_REQUEST, { 'processId': os.getpid(), 'rootUri': 'file://' + os.getcwd(), 'capabilities': {}, 'trace': 'off' }, timeout_ms=5000) except TimedOutError as e: log.exception('initialize timedout') # ignore timedout rr = {} pass if not 'capabilities' in rr: rr['capabilities'] = {} log.debug('clangd connected with backend server') for k in rr['capabilities']: v = rr['capabilities'][k] if v: log.info('clangd server capability: %s' % k) self._manager.on_server_connected() return rr
def OnRequest(self, request): log.info('recv request: %s' % request['method']) self._observer.onRequest(request['method'], request['params'])
def OnNotification(self, request): log.info('recv notification: %s' % request['method']) self._observer.onNotification(request['method'], request['params'])
def EchoMessage(s): log.info(s)
def GetCompletions(self): log.info('GetCompletions') return self._manager.GetCompletions()
def CodeCompleteAtCurrent(self): log.info('CodeCompleteAtCurrent') ret = self._manager.CodeCompleteAtCurrent() if ret < 0: return return ret