diff --git a/hdlcc/handlers.py b/hdlcc/handlers.py index 863939c..bcc1506 100644 --- a/hdlcc/handlers.py +++ b/hdlcc/handlers.py @@ -168,7 +168,13 @@ def getMessagesByPath(): "no content" if content is None else "with content") server = _getServerByProjectFile(project_file) - return {'messages': server.getMessagesByPath(path)} + response = {} + if content is None: + response['messages'] = server.getMessagesByPath(path) + else: + response['messages'] = server.getMessagesWithText(path, content) + + return response @app.post('/get_ui_messages') @_exceptionWrapper diff --git a/hdlcc/parsers/base_parser.py b/hdlcc/parsers/base_parser.py index af839cc..dca5301 100644 --- a/hdlcc/parsers/base_parser.py +++ b/hdlcc/parsers/base_parser.py @@ -51,7 +51,9 @@ def __init__(self, filename, library='work', flags=None): self._content = None self._mtime = 0 self.filetype = getFileType(self.filename) + self._prev = None + self.abspath = p.abspath(filename) def getState(self): @@ -122,7 +124,6 @@ def _changed(self): provided by p.getmtime """ if self.getmtime() > self._mtime: - _logger.debug("File '%s' has changed", self.filename) return True return False @@ -186,7 +187,6 @@ def _setBufferContent(self, content): buffer_dump_path = self.getDumpPath() _logger.debug("Dumping buffer content to '%s'", buffer_dump_path) open(buffer_dump_path, 'w').write(self._content) - return buffer_dump_path def _clearBufferContent(self): """ @@ -204,6 +204,7 @@ def getSourceContent(self): """ Cached version of the _getSourceContent method """ + self._clearCachesIfChanged() if self._content is None: @@ -221,7 +222,6 @@ def getRawSourceContent(self): if self.hasBufferContent(): return self._content - if 'raw_content' not in self._cache or self._changed(): self._cache['raw_content'] = \ open(self.filename, mode='rb').read().decode(errors='ignore') diff --git a/hdlcc/tests/test_server_handlers.py b/hdlcc/tests/test_server_handlers.py index 4cef1d8..39bc04b 100644 --- a/hdlcc/tests/test_server_handlers.py +++ b/hdlcc/tests/test_server_handlers.py @@ -355,35 +355,35 @@ def build_with_buffer_leave(): # TODO: This test has side effects and makes other tests fail. Skip # it for now - # @it.should("get messages with content") - # def test(): - # data = { - # 'project_file' : it.PROJECT_FILE, - # 'path' : p.join( - # VIM_HDL_EXAMPLES, 'another_library', 'foo.vhd'), - # 'content' : '-- TODO: Nothing to see here'} - - # ui_reply = it.app.post('/get_ui_messages', data) - # reply = it.app.post('/get_messages_by_path', data) - - # _logger.info("UI reply: %s", ui_reply) - # _logger.info("Reply: %s", reply) - - # messages = reply.json['messages'] - - # for message in messages: - # it.assertTrue(utils.samefile(message.pop('filename'), - # data['path'])) - - # it.assertIn( - # {"error_type" : "W", - # "checker" : "HDL Code Checker/static", - # "line_number" : 1, - # "column" : 4, - # "error_subtype" : "", - # "error_number" : "0", - # "error_message" : "TODO: Nothing to see here"}, - # messages) + @it.should("get messages with content") + def test(): + data = { + 'project_file' : it.PROJECT_FILE, + 'path' : p.join( + VIM_HDL_EXAMPLES, 'another_library', 'foo.vhd'), + 'content' : '-- TODO: Nothing to see here'} + + ui_reply = it.app.post('/get_ui_messages', data) + reply = it.app.post('/get_messages_by_path', data) + + _logger.info("UI reply: %s", ui_reply) + _logger.info("Reply: %s", reply) + + messages = reply.json['messages'] + + for message in messages: + it.assertTrue(utils.samefile(message.pop('filename'), + data['path'])) + + it.assertIn( + {"error_type" : "W", + "checker" : "HDL Code Checker/static", + "line_number" : 1, + "column" : 4, + "error_subtype" : "", + "error_number" : "0", + "error_message" : "TODO: Nothing to see here"}, + messages) @it.should("get source dependencies") @mock.patch('hdlcc.config_parser.foundVunit', lambda: False)