def __init__(self): self._project_file = toBytes(getProjectFile() or self._default_conf_filename).decode() self._backup_file = p.join( p.dirname(self._project_file), '.' + p.basename(self._project_file) + '.backup')
def getBuildSequence(self): """ Gets the build sequence for the current path """ self._postQueuedMessages() if not self._isServerAlive(): return project_file = vim_helpers.getProjectFile() request = GetBuildSequence(project_file=project_file, path=vim.current.buffer.name) response = request.sendRequest() if response is not None: self._logger.debug("Response: %s", str(response.json()['sequence'])) sequence = response.json()['sequence'] if sequence: i = 1 msg = ["Build sequence for %s\n" % vim.current.buffer.name] for i in range(len(sequence)): # pylint:disable=consider-using-enumerate msg += ["%d: %s" % (i, sequence[i])] return '\n'.join(msg) return "Build sequence is empty" return ""
def getDependencies(self): """ Gets the dependencies for a given path """ self._postQueuedMessages() if not self._isServerAlive(): return project_file = vim_helpers.getProjectFile() request = GetDependencies(self._host, self._port, project_file=project_file, path=vim.current.buffer.name) response = request.sendRequest() if response is not None: self._logger.debug("Response: %s", str(response.json()['dependencies'])) return "\n".join( ["Dependencies for %s" % vim.current.buffer.name] + ["- %s" % x for x in response.json()['dependencies']]) else: return "Source has no dependencies"
def getVimhdlInfo(self): """ Gets info about the current project and hdlcc server """ project_file = vim_helpers.getProjectFile() request = RequestHdlccInfo(host=self._host, port=self._port, project_file=project_file) response = request.sendRequest() if response is not None: # The server has responded something, so just print it self._logger.info("Response: %s", str(response.json()['info'])) return "\n".join([ "- %s" % x for x in ["vimhdl version: %s\n" % vimhdl.__version__] + response.json()['info'] ]) else: return "\n".join([ "- %s" % x for x in [ "vimhdl version: %s\n" % vimhdl.__version__, "hdlcc server is not running" ] ])
def test(): for prj_filename in (it._local_prj_filename, ): assert not p.exists(prj_filename) open(prj_filename, 'w').close() it.assertEqual(it._local_prj_filename, vim_helpers.getProjectFile()) deleteProjectFiles()
def getMessages(self, vim_buffer=None, vim_var=None): """ Returns a list of messages to populate the quickfix list. For more info, check :help getqflist() """ if not self._isServerAlive(): self._logger.warning("Server is not alive, can't get messages") return if vim_buffer is None: vim_buffer = vim.current.buffer if vim_var is not None: vim.command("let {0} = []".format(vim_var)) project_file = vim_helpers.getProjectFile() path = p.abspath(vim_buffer.name) request = RequestMessagesByPath(host=self._host, port=self._port, project_file=project_file, path=path) response = request.sendRequest() if response is None: return messages = [] for msg in response.json().get('messages', []): text = str(msg['error_message']) if msg['error_message'] else '' vim_fmt_dict = { 'lnum': str(msg['line_number']) or '-1', 'bufnr': str(vim_buffer.number), 'filename': str(msg['filename']) or vim_buffer.name, 'valid': '1', 'text': text, 'nr': str(msg['error_number']) or '0', 'type': str(msg['error_type']) or 'E', 'col': str(msg['column']) or '0' } try: vim_fmt_dict['subtype'] = str(msg['error_subtype']) except KeyError: pass _logger.info(vim_fmt_dict) messages.append(vim_fmt_dict) self.requestUiMessages('getMessages') if vim_var is None: return _sortBuildMessages(messages) for msg in _sortBuildMessages(messages): vim_helpers.toVimDict(msg, '_dict') vim.command("let {0} += [{1}]".format(vim_var, '_dict')) vim.command("unlet! _dict")
def getMessages(self, vim_buffer=None, vim_var=None): """ Returns a list of messages to populate the quickfix list. For more info, check :help getqflist() """ if not self._isServerAlive(): self._logger.warning("Server is not alive, can't get messages") return if vim_buffer is None: vim_buffer = vim.current.buffer project_file = vim_helpers.getProjectFile() path = p.abspath(vim_buffer.name) request = RequestMessagesByPath(host=self._host, port=self._port, project_file=project_file, path=path) response = request.sendRequest() if response is None: return messages = [] for message in response.json().get('messages', []): text = (str(message['error_message']) or '').replace("'", '"') vim_fmt_dict = { 'lnum' : str(message['line_number']) or '-1', 'bufnr' : str(vim_buffer.number), 'filename' : str(message['filename']) or vim_buffer.name, 'valid' : '1', 'text' : text, 'nr' : str(message['error_number']) or '0', 'type' : str(message['error_type']) or 'E', 'col' : str(message['column']) or '0'} try: vim_fmt_dict['subtype'] = str(message['error_subtype']) except KeyError: pass _logger.info(vim_fmt_dict) messages.append(vim_fmt_dict) self.requestUiMessages('getMessages') if vim_var is None: return _sortBuildMessages(messages) try: vim.command('let {0} = {1}'.format(vim_var, _sortBuildMessages(messages))) except: # pylint: disable=bare-except self._logger.exception("Error decoding some messages") self._postError("Error decoding some messages")
def rebuildProject(self): "Rebuilds the current project" vim_helpers.postVimInfo("Rebuilding project...") project_file = vim_helpers.getProjectFile() request = RequestProjectRebuild(host=self._host, port=self._port, project_file=project_file) response = request.sendRequest() if response is None: return "hdlcc server is not running" self._logger.info("Response: %s", repr(response))
def getVimhdlInfo(self): "Gets info about the current project and hdlcc server" project_file = vim_helpers.getProjectFile() request = RequestHdlccInfo(host=self._host, port=self._port, project_file=project_file) response = request.sendRequest() if response is None: return "hdlcc server is not running" return "\n".join(["vimhdl version: " + vimhdl.__version__] + ["%s: %s" % (k, v) for k, v in response.json().items()])
def requestUiMessages(self, event): """Retrieves UI messages from the server and post them with the appropriate severity level""" self._logger.info("Handling event '%s'. Filetype is %s", event, vim.eval('&filetype')) self._postQueuedMessages() if not self._isServerAlive(): return project_file = vim_helpers.getProjectFile() request = RequestQueuedMessages(project_file=project_file) request.sendRequestAsync(self._handleAsyncRequest)
def onBufferLeave(self): """ Notifies the hdlcc server that Vim user has left the current buffer """ self._postQueuedMessages() if not self._isServerAlive(): return project_file = vim_helpers.getProjectFile() request = OnBufferLeave(project_file=project_file, path=vim.current.buffer.name) request.sendRequestAsync(self._handleAsyncRequest)
def requestUiMessages(self, event): """Retrieves UI messages from the server and post them with the appropriate severity level""" self._logger.info("Handling event '%s'. Filetype is %s", event, vim.eval('&filetype')) self._postQueuedMessages() if not self._isServerAlive(): return project_file = vim_helpers.getProjectFile() request = RequestQueuedMessages(self._host, self._port, project_file=project_file) request.sendRequestAsync(self._handleAsyncRequest)
def rebuildProject(self): """ Rebuilds the current project """ if vim.eval('&filetype') not in ('vhdl', 'verilog', 'systemverilog'): vim_helpers.postVimWarning("Not a VHDL file, can't rebuild") return vim_helpers.postVimInfo("Rebuilding project...") project_file = vim_helpers.getProjectFile() request = RequestProjectRebuild(project_file=project_file) response = request.sendRequest() if response is None: return "hdlcc server is not running" self._logger.info("Response: %s", repr(response))
def onBufferLeave(self): """ Notifies the hdlcc server that Vim user has left the current buffer """ self._postQueuedMessages() if not self._isServerAlive(): return project_file = vim_helpers.getProjectFile() request = OnBufferLeave(self._host, self._port, project_file=project_file, path=vim.current.buffer.name) request.sendRequestAsync(self._handleAsyncRequest)
def getMessages(self, vim_buffer=None): """Returns a list (vim.List) of messages (vim.Dictionary) to populate the quickfix list. For more info, check :help getqflist()""" if not self._isServerAlive(): return if vim_buffer is None: vim_buffer = vim.current.buffer project_file = vim_helpers.getProjectFile() path = p.abspath(vim_buffer.name) request = RequestMessagesByPath(host=self._host, port=self._port, project_file=project_file, path=path) response = request.sendRequest() if response is None: return messages = [] for message in response.json().get('messages', []): vim_fmt_dict = { 'lnum' : message['line_number'] or '-1', 'bufnr' : vim_buffer.number, 'filename' : message['filename'] or vim_buffer.name, 'valid' : '1', 'text' : message['error_message'] or '<none>', 'nr' : message['error_number'] or '0', 'type' : message['error_type'] or 'E', 'col' : message['column'] or '0' } try: vim_fmt_dict['subtype'] = message['error_subtype'] except KeyError: pass _logger.info(vim_fmt_dict) messages.append(vim_helpers.dict(vim_fmt_dict)) self.requestUiMessages('getMessages') return vim_helpers.list(_sortBuildMessages(messages))
def getVimhdlInfo(self): """ Gets info about the current project and hdlcc server """ project_file = vim_helpers.getProjectFile() request = RequestHdlccInfo(host=self._host, port=self._port, project_file=project_file) response = request.sendRequest() if response is not None: # The server has responded something, so just print it self._logger.info("Response: %s", str(response.json()['info'])) return "\n".join( ["- %s" % x for x in ["vimhdl version: %s\n" % vimhdl.__version__] + response.json()['info']]) else: return "\n".join( ["- %s" % x for x in ["vimhdl version: %s\n" % vimhdl.__version__, "hdlcc server is not running"]])
def test(): deleteProjectFiles() it.assertIsNone(vim_helpers.getProjectFile()) deleteProjectFiles()