Repository: python-lsp/python-lsp-server

Issue:
Autoimport keep throwing exception when delete a line
```
--- Send (notification): textDocument/didChange

--- Send (58706): textDocument/completion
2022-11-28 22:45:51,446 CST - WARNING - pylsp.config.config - Failed to load hook pylsp_completions: 'NoneType' object has no attribute 'value'
Traceback (most recent call last):
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pylsp/config/config.py", line 33, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 327, in traced_hookexec
    return outcome.get_result()
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_result.py", line 33, in from_call
    result = func()
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_manager.py", line 324, in <lambda>
    lambda: oldcall(hook_name, hook_impls, kwargs, firstresult)
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 60, in _multicall
    return outcome.get_result()
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_result.py", line 60, in get_result
    raise ex[1].with_traceback(ex[2])
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pluggy/_callers.py", line 39, in _multicall
    res = hook_impl.function(*args)
  File "▒▒▒▒▒▒▒▒/venv/lib/python3.10/site-packages/pylsp/plugins/rope_autoimport.py", line 159, in pylsp_completions
    word = word_node.value
AttributeError: 'NoneType' object has no attribute 'value'
```

After I digging in code, I found the var [`line`](https://github.com/python-lsp/python-lsp-server/blob/develop/pylsp/plugins/rope_autoimport.py#L154) is alway a empty string when I delete a line

Discussion:
douo: Done, Thanks @ccordoba12.

Patch:
diff --git a/pylsp/plugins/rope_autoimport.py b/pylsp/plugins/rope_autoimport.py
index f636698..2c0c46e 100644
--- a/pylsp/plugins/rope_autoimport.py
+++ b/pylsp/plugins/rope_autoimport.py
@@ -28,13 +28,15 @@ def pylsp_settings() -> Dict[str, Dict[str, Dict[str, Any]]]:
     return {"plugins": {"rope_autoimport": {"enabled": False, "memory": False}}}
 
 
-def _should_insert(expr: tree.BaseNode, word_node: tree.Leaf) -> bool:
+def _should_insert(expr: tree.BaseNode, word_node: tree.Leaf) -> bool:  # pylint: disable=too-many-return-statements
     """
     Check if we should insert the word_node on the given expr.
 
     Works for both correct and incorrect code. This is because the
     user is often working on the code as they write it.
     """
+    if not word_node:
+        return False
     if len(expr.children) == 0:
         return True
     first_child = expr.children[0]


Test patch:
diff --git a/test/plugins/test_autoimport.py b/test/plugins/test_autoimport.py
index b017b92..a1ddd77 100644
--- a/test/plugins/test_autoimport.py
+++ b/test/plugins/test_autoimport.py
@@ -101,6 +101,11 @@ def test_autoimport_class(completions):
     assert len(completions) == 0
 
 
+@pytest.mark.parametrize("completions", [("""\n""", 0)], indirect=True)
+def test_autoimport_empty_line(completions):
+    assert len(completions) == 0
+
+
 @pytest.mark.parametrize("completions", [("""class Test(NamedTupl):""", 20)],
                          indirect=True)
 def test_autoimport_class_complete(completions):