diff --git a/suricatals/langserver.py b/suricatals/langserver.py index 32321f4..3379de6 100644 --- a/suricatals/langserver.py +++ b/suricatals/langserver.py @@ -351,14 +351,16 @@ def update_workspace_file(self, filepath, read_file=False, allow_empty=False): file_obj = self.workspace.get(filepath) if read_file: if file_obj is None: - file_obj = SuricataFile(filepath, self.rules_tester) # Create empty file if not yet saved to disk if not os.path.isfile(filepath): + file_obj = SuricataFile(filepath, self.rules_tester, empty=True) if allow_empty: self.workspace[filepath] = file_obj return False, None else: return False, 'File does not exist' # Error during load + else: + file_obj = SuricataFile(filepath, self.rules_tester) hash_old = file_obj.hash err_string = None if os.path.isfile(filepath): diff --git a/suricatals/parse_signatures.py b/suricatals/parse_signatures.py index bccd089..8d35172 100644 --- a/suricatals/parse_signatures.py +++ b/suricatals/parse_signatures.py @@ -182,7 +182,7 @@ class SuricataFile: IS_COMMENT = re.compile(r"[ \t]*#") GET_MULTILINES = re.compile(r"\\ *$") - def __init__(self, path, rules_tester): + def __init__(self, path, rules_tester, empty=False): self.path = path self.rules_tester = rules_tester self.contents_split = [] @@ -191,7 +191,8 @@ def __init__(self, path, rules_tester): self.hash = None self.mpm = {} self.diagnosis = None - self.count_lines() + if not empty: + self.count_lines() def count_lines(self): with open(self.path, 'r', encoding='utf-8', errors='replace') as fhandle: