From 8789de969e6673b195cbb28a692cc3fbbaa806e1 Mon Sep 17 00:00:00 2001 From: m-kru Date: Sat, 15 Aug 2020 04:17:53 +0200 Subject: py: adjust blank lines to PEP 8 for vhdl_langserver (#1434) Why? 1. Conform to PEP 8. 2. Easier to read. 3. Make tools, such as PyCharm, not complain. --- python/libghdl/__init__.py | 2 ++ python/vhdl_langserver/document.py | 1 + python/vhdl_langserver/lsp.py | 9 +++++++++ python/vhdl_langserver/lsptools.py | 4 ++++ python/vhdl_langserver/main.py | 2 ++ python/vhdl_langserver/references.py | 2 ++ python/vhdl_langserver/symbols.py | 3 +++ python/vhdl_langserver/workspace.py | 4 ++-- 8 files changed, 25 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/python/libghdl/__init__.py b/python/libghdl/__init__.py index 1258a5643..6ea3a4177 100644 --- a/python/libghdl/__init__.py +++ b/python/libghdl/__init__.py @@ -5,6 +5,7 @@ from os.path import dirname, join, exists, normpath from shutil import which from libghdl.version import __version__ + def _to_char_p(arg): return ctypes.c_char_p(arg), len(arg) @@ -83,6 +84,7 @@ libghdl.libghdl__set_hooks_for_analysis() libghdl.libghdl__set_exec_prefix( *_to_char_p(dirname(dirname(_libghdl_path)).encode('utf-8'))) + def set_option(opt): "Set option OPT. Return true iff the option is known and handled" return libghdl.libghdl__set_option(*_to_char_p(opt)) == 0 diff --git a/python/vhdl_langserver/document.py b/python/vhdl_langserver/document.py index 26f02ba65..1b3cbf40b 100644 --- a/python/vhdl_langserver/document.py +++ b/python/vhdl_langserver/document.py @@ -14,6 +14,7 @@ from . import symbols, references log = logging.getLogger(__name__) + class Document(object): # The encoding used for the files. # Unfortunately this is not fully reliable. The client can read the diff --git a/python/vhdl_langserver/lsp.py b/python/vhdl_langserver/lsp.py index 8f5a98e5e..9a93b2a16 100644 --- a/python/vhdl_langserver/lsp.py +++ b/python/vhdl_langserver/lsp.py @@ -12,9 +12,11 @@ except ImportError: log = logging.getLogger('ghdl-ls') + class ProtocolError(Exception): pass + class LSPConn: def __init__(self, reader, writer): self.reader = reader @@ -32,6 +34,7 @@ class LSPConn: self.writer.write(out.encode()) self.writer.flush() + def path_from_uri(uri): # Convert file uri to path (strip html like head part) if not uri.startswith("file://"): @@ -193,6 +196,7 @@ class LanguageProtocolServer(object): # Standard defines and object types # + class JSONErrorCodes(object): # Defined by JSON RPC ParseError = -32700 @@ -237,17 +241,20 @@ class DiagnosticSeverity(object): Information = 3 Hint = 4 + class TextDocumentSyncKind(object): NONE = 0, FULL = 1 INCREMENTAL = 2 + class MessageType(object): Error = 1 Warning = 2 Info = 3 Log = 4 + class SymbolKind(object): File = 1 Module = 2 @@ -268,6 +275,7 @@ class SymbolKind(object): Boolean = 17 Array = 18 + @attr.s class HoverInfo(object): language = attr.ib() @@ -287,6 +295,7 @@ class Position(object): line = attr.ib() character = attr.ib() + @attr.s class Range(object): start = attr.ib(validator=instance_of(Position)) diff --git a/python/vhdl_langserver/lsptools.py b/python/vhdl_langserver/lsptools.py index 0e34c82f5..8b9fd0a17 100644 --- a/python/vhdl_langserver/lsptools.py +++ b/python/vhdl_langserver/lsptools.py @@ -3,6 +3,7 @@ import argparse import json from . import lsp + def lsp2json(): "Utility that transforms lsp log file to a JSON list" conn = lsp.LSPConn(sys.stdin.buffer, sys.stdout.buffer) @@ -15,6 +16,7 @@ def lsp2json(): res.append(json.loads(req)) print(json.dumps(res, indent=2)) + def json2lsp(): "Utility that transform a JSON list to an lsp file" res = json.load(sys.stdin) @@ -23,6 +25,7 @@ def json2lsp(): for req in res: ls.write_output(req) + def main(): parser = argparse.ArgumentParser() subparsers = parser.add_subparsers(help="sub-command help") @@ -35,5 +38,6 @@ def main(): args = parser.parse_args() args.func() + if __name__ == "__main__": main() diff --git a/python/vhdl_langserver/main.py b/python/vhdl_langserver/main.py index 4831000fc..0759043e6 100644 --- a/python/vhdl_langserver/main.py +++ b/python/vhdl_langserver/main.py @@ -15,6 +15,7 @@ from . import vhdl_ls logger = logging.getLogger('ghdl-ls') + class LSPConnTrace(object): """Wrapper class to save in and out packets""" def __init__(self, basename, conn): @@ -47,6 +48,7 @@ def rotate_log_files(basename, num): if os.path.isfile(basename): os.rename(basename, '{}.0'.format(basename)) + def main(): parser = argparse.ArgumentParser( description='VHDL Language Protocol Server') diff --git a/python/vhdl_langserver/references.py b/python/vhdl_langserver/references.py index fa1033c04..76cca2a19 100644 --- a/python/vhdl_langserver/references.py +++ b/python/vhdl_langserver/references.py @@ -6,6 +6,7 @@ import libghdl.thin.name_table as name_table log = logging.getLogger(__name__) + def find_def_chain(first, loc): n1 = first while n1 != nodes.Null_Iir: @@ -81,6 +82,7 @@ def find_def(n, loc): return None + def goto_definition(n, loc): "Return the declaration (as a node) under :param loc: or None" ref = find_def(n, loc) diff --git a/python/vhdl_langserver/symbols.py b/python/vhdl_langserver/symbols.py index b39827bed..11335408c 100644 --- a/python/vhdl_langserver/symbols.py +++ b/python/vhdl_langserver/symbols.py @@ -67,16 +67,19 @@ SYMBOLS_MAP = { nodes.Iir_Kind.Configuration_Specification: {'kind': None}, } + def location_to_position(fe, loc): assert loc != files_map.No_Location line = files_map.Location_File_To_Line(loc, fe) off = files_map.Location_File_Line_To_Offset(loc, fe, line) return {'line': line - 1, 'character': off} + def get_symbols_chain(fe, n): res = [get_symbols(fe, el) for el in pyutils.chain_iter(n)] return [e for e in res if e is not None] + def get_symbols(fe, n): if n == nodes.Null_Iir: return None diff --git a/python/vhdl_langserver/workspace.py b/python/vhdl_langserver/workspace.py index baf18f0ce..a2cf9db4b 100644 --- a/python/vhdl_langserver/workspace.py +++ b/python/vhdl_langserver/workspace.py @@ -21,12 +21,14 @@ from . import document, symbols log = logging.getLogger(__name__) + class ProjectError(Exception): "Exception raised in case of unrecoverable error in the project file." def __init__(self, msg): super().__init__() self.msg = msg + class Workspace(object): def __init__(self, root_uri, server): self._root_uri = root_uri @@ -193,7 +195,6 @@ class Workspace(object): self._server.show_message(lsp.MessageType.Error, "error in project file: {}".format(e.msg)) - def read_files_from_project(self): try: files = self._prj.get('files', []) @@ -431,7 +432,6 @@ class Workspace(object): 'generics': create_interfaces(nodes.Get_Generic_Chain(ent)), 'ports': create_interfaces(nodes.Get_Port_Chain(ent))} - def compute_anti_dependences(self): """Return a dictionnary of anti dependencies for design unit""" res = {} -- cgit v1.2.3