25
25
# Local imports
26
26
from spyder .config .gui import get_font
27
27
from spyder .config .manager import CONF
28
- from spyder .py3compat import PY3 , to_text_string
29
- from spyder .widgets .calltip import CallTipWidget , ToolTipWidget
30
- from spyder .widgets .mixins import BaseEditMixin
31
28
from spyder .plugins .editor .api .decoration import TextDecoration , DRAW_ORDERS
32
29
from spyder .plugins .editor .utils .decoration import TextDecorationsManager
33
30
from spyder .plugins .editor .widgets .completion import CompletionWidget
31
+ from spyder .plugins .completion .api import CompletionItemKind
34
32
from spyder .plugins .outlineexplorer .api import is_cell_header , document_cells
33
+ from spyder .py3compat import PY3 , to_text_string
35
34
from spyder .utils .palette import SpyderPalette
35
+ from spyder .widgets .calltip import CallTipWidget , ToolTipWidget
36
+ from spyder .widgets .mixins import BaseEditMixin
37
+
36
38
37
39
class TextEditBaseWidget (QPlainTextEdit , BaseEditMixin ):
38
40
"""Text edit base widget"""
@@ -941,8 +943,10 @@ def insert_completion(self, completion, completion_position):
941
943
text = str (completion ['textEdit' ]['newText' ])
942
944
else :
943
945
text = completion
946
+ kind = None
944
947
if isinstance (completion , dict ):
945
948
text = completion ['insertText' ]
949
+ kind = completion ['kind' ]
946
950
text = str (text )
947
951
948
952
# Get word to the left of the cursor.
@@ -962,6 +966,20 @@ def insert_completion(self, completion, completion_position):
962
966
if current_text in self .auto_completion_characters :
963
967
is_auto_completion_character = True
964
968
969
+ # Adjustments for file completions
970
+ if kind == CompletionItemKind .FILE :
971
+ # This is necessary to inseert file completions when
972
+ # requesting them next to a colon
973
+ if current_text in ['"' , "'" ]:
974
+ current_text = ''
975
+ start_position += 1
976
+
977
+ # And this insert completions for files or directories that
978
+ # start with a dot
979
+ if current_text in ['".' , "'." ]:
980
+ current_text = '.'
981
+ start_position += 1
982
+
965
983
if not is_auto_completion_character :
966
984
# Check if the completion position is in the expected range
967
985
if not (
@@ -971,7 +989,10 @@ def insert_completion(self, completion, completion_position):
971
989
cursor .setPosition (start_position )
972
990
973
991
# Remove the word under the cursor
974
- cursor .setPosition (end_position , QTextCursor .KeepAnchor )
992
+ if current_text :
993
+ cursor .setPosition (
994
+ end_position , QTextCursor .KeepAnchor
995
+ )
975
996
else :
976
997
# Check if we are in the correct position
977
998
if cursor .position () != completion_position :
0 commit comments