Repository: spyder-ide/pyls-spyder

Issue:
Fix code blocks regular expression
It seems that the regular expression for code block comments that start with dash and number sign are not constrained by the actual number required (four in both cases)

Comments:

Patch:
diff --git a/pyls_spyder/plugin.py b/pyls_spyder/plugin.py
index 676eab7..60947e8 100644
--- a/pyls_spyder/plugin.py
+++ b/pyls_spyder/plugin.py
@@ -40,10 +40,10 @@ CELL_REGEX = RegexEvaluator({
 # Block comment regular expressions
 # 1. Block comments declared with 4 dashes, i.e., # ---- Block comment
 BLOCK_DASH = (
-    'BLOCK_DASH', re.compile(r'^[\t ]*# ?-{4}([^-\n\r]?.*)?$'))
+    'BLOCK_DASH', re.compile(r'^[\t ]*# ?-{4}([^-\n\r].*)?$'))
 # 2. Block comments declared with 3 consecutive hashes, i.e., #### Comment
 BLOCK_HASH = (
-    'BLOCK_HASH', re.compile(r'^[\t ]*##{3}([^\#\n\r]?.*)?$'))
+    'BLOCK_HASH', re.compile(r'^[\t ]*##{3}([^\#\n\r].*)?$'))
 
 BLOCK_REGEX = RegexEvaluator(dict([BLOCK_DASH, BLOCK_HASH]))
 
@@ -133,7 +133,12 @@ def pyls_document_symbols(config: Config,
                             current_name) = peek_symbol(cell_stack)
                     cell_stack.insert(0, (line_num, cell_level, cell_name))
         elif block_match is not None and enable_block_comments:
-            block_name = block_match.group(1).strip()
+            block_name = block_match.group(1)
+            if block_name is None:
+                block_name = ''
+            else:
+                block_name = block_name.strip()
+
             if block_name == '':
                 block_name = 'Unnamed comment {0}'.format(unnamed_block)
                 unnamed_block += 1


Test patch:
diff --git a/pyls_spyder/tests/test_plugin.py b/pyls_spyder/tests/test_plugin.py
index b7d5c3a..98e2388 100644
--- a/pyls_spyder/tests/test_plugin.py
+++ b/pyls_spyder/tests/test_plugin.py
@@ -44,8 +44,11 @@ def b():
 # In[25]
 ####
 
-#%% Empty cell
+#%% Invalid comments
 #----
+# ---------- This should not work
+###### This either
+#%% Empty cell
 """
 
 
@@ -74,8 +77,9 @@ def test_cell_block_symbols(config, workspace):
         ('Pass inside b', 17, 17, 224),
         ('25', 20, 20, 225),
         ('Unnamed comment 2', 21, 21, 224),
-        ('Empty cell', 23, 24, 225),
-        ('Unnamed comment 3', 24, 24, 224)
+        ('Invalid comments', 23, 26, 225),
+        ('Unnamed comment 3', 24, 24, 224),
+        ('Empty cell', 27, 27, 225)
     ]
     test_results = []
     for symbol in symbols:
@@ -105,8 +109,9 @@ def test_ungroup_cell_symbols(config, workspace):
         ('Pass inside b', 17, 17, 224),
         ('25', 20, 20, 225),
         ('Unnamed comment 2', 21, 21, 224),
-        ('Empty cell', 23, 23, 225),
-        ('Unnamed comment 3', 24, 24, 224)
+        ('Invalid comments', 23, 23, 225),
+        ('Unnamed comment 3', 24, 24, 224),
+        ('Empty cell', 27, 27, 225)
     ]
     test_results = []
     for symbol in symbols:
@@ -131,7 +136,8 @@ def test_disable_block_comments(config, workspace):
         ('Cell', 12, 14, 225),
         ('Unnamed cell 2', 15, 22, 225),
         ('25', 20, 20, 225),
-        ('Empty cell', 23, 24, 225)
+        ('Invalid comments', 23, 26, 225),
+        ('Empty cell', 27, 27, 225)
     ]
     test_results = []
     for symbol in symbols:
@@ -155,7 +161,8 @@ def test_cell_folding_regions(config, workspace):
         (12, 14),
         (15, 22),
         (20, 22),
-        (23, 24)
+        (23, 26),
+        (27, 27)
     ]
     test_results = []
     for region in regions: