We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
TypeError: expected string or buffer
https://github.com/tomv564/LSP/blob/e37c4e6d7d959890c465cada35dff7fef22feb6e/plugin/core/types.py#L50-L54

It happened only once so far, when `plugin_loaded` was called on start up. After restarting Sublime Text right away, it did not happened again.

```
Traceback (most recent call last):
  File "F:\SublimeText\sublime_plugin.py", line 298, in on_api_ready
    plc()
  File "F:\SublimeText\Data\Packages\LSP\boot.py", line 30, in plugin_loaded
    startup()
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\main.py", line 25, in startup
    start_active_window()
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\main.py", line 44, in start_active_window
    windows.lookup(window).start_active_views()
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\windows.py", line 336, in start_active_views
    self._initialize_on_open(view)
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\windows.py", line 348, in _initialize_on_open
    self._configs.syntax_configs(view))
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\configurations.py", line 120, in syntax_configs
    return list(filter(lambda c: config_supports_syntax(c, syntax) and c.enabled, self.all))
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\configurations.py", line 120, in <lambda>
    return list(filter(lambda c: config_supports_syntax(c, syntax) and c.enabled, self.all))
  File "F:\SublimeText\Data\Packages\LSP\plugin\core\types.py", line 81, in config_supports_syntax
    if re.search(r'|'.join(r'\b%s\b' % re.escape(s) for s in language.syntaxes), syntax, re.IGNORECASE):
  File "./python3.3/re.py", line 161, in search
TypeError: expected string or buffer
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `plugin/completion.py`
Content:
```
1 import sublime
2 import sublime_plugin
3 
4 try:
5     from typing import Any, List, Dict, Tuple, Callable, Optional
6     assert Any and List and Dict and Tuple and Callable and Optional
7 except ImportError:
8     pass
9 
10 from .core.protocol import Request
11 from .core.events import global_events
12 from .core.settings import settings, client_configs
13 from .core.logging import debug
14 from .core.completion import parse_completion_response
15 from .core.registry import session_for_view, client_for_view
16 from .core.configurations import is_supported_syntax
17 from .core.documents import get_document_position
18 from .core.sessions import Session
19 
20 NO_COMPLETION_SCOPES = 'comment, string'
21 
22 
23 class CompletionState(object):
24     IDLE = 0
25     REQUESTING = 1
26     APPLYING = 2
27     CANCELLING = 3
28 
29 
30 last_text_command = None
31 
32 
33 class CompletionHelper(sublime_plugin.EventListener):
34     def on_text_command(self, view, command_name, args):
35         global last_text_command
36         last_text_command = command_name
37 
38 
39 class CompletionHandler(sublime_plugin.ViewEventListener):
40     def __init__(self, view):
41         self.view = view
42         self.initialized = False
43         self.enabled = False
44         self.trigger_chars = []  # type: List[str]
45         self.state = CompletionState.IDLE
46         self.completions = []  # type: List[Any]
47         self.next_request = None  # type: Optional[Tuple[str, List[int]]]
48         self.last_prefix = ""
49         self.last_location = 0
50 
51     @classmethod
52     def is_applicable(cls, settings):
53         syntax = settings.get('syntax')
54         if syntax is not None:
55             return is_supported_syntax(syntax, client_configs.all)
56         else:
57             return False
58 
59     def initialize(self):
60         self.initialized = True
61         session = session_for_view(self.view)
62         if session:
63             completionProvider = session.get_capability(
64                 'completionProvider')
65             if completionProvider:
66                 self.enabled = True
67                 self.trigger_chars = completionProvider.get(
68                     'triggerCharacters') or []
69                 if self.trigger_chars:
70                     self.register_trigger_chars(session)
71 
72     def _view_language(self, config_name: str) -> 'Optional[str]':
73         languages = self.view.settings().get('lsp_language')
74         return languages.get(config_name) if languages else None
75 
76     def register_trigger_chars(self, session: Session) -> None:
77         completion_triggers = self.view.settings().get('auto_complete_triggers', [])
78         view_language = self._view_language(session.config.name)
79         if view_language:
80             for language in session.config.languages:
81                 if language.id == view_language:
82                     for scope in language.scopes:
83                         # debug("registering", self.trigger_chars, "for", scope)
84                         scope_trigger = next(
85                             (trigger for trigger in completion_triggers if trigger.get('selector', None) == scope),
86                             None
87                         )
88                         if scope_trigger:
89                             scope_trigger['characters'] = "".join(self.trigger_chars)
90                         else:
91                             completion_triggers.append({
92                                 'characters': "".join(self.trigger_chars),
93                                 'selector': scope
94                             })
95 
96             self.view.settings().set('auto_complete_triggers', completion_triggers)
97 
98     def is_after_trigger_character(self, location):
99         if location > 0:
100             prev_char = self.view.substr(location - 1)
101             return prev_char in self.trigger_chars
102 
103     def is_same_completion(self, prefix, locations):
104         # completion requests from the same location with the same prefix are cached.
105         current_start = locations[0] - len(prefix)
106         last_start = self.last_location - len(self.last_prefix)
107         return prefix.startswith(self.last_prefix) and current_start == last_start
108 
109     def on_modified(self):
110         # hide completion when backspacing past last completion.
111         if self.view.sel()[0].begin() < self.last_location:
112             self.last_location = 0
113             self.view.run_command("hide_auto_complete")
114         # cancel current completion if the previous input is an space
115         prev_char = self.view.substr(self.view.sel()[0].begin() - 1)
116         if self.state == CompletionState.REQUESTING and prev_char.isspace():
117             self.state = CompletionState.CANCELLING
118 
119     def on_query_completions(self, prefix, locations):
120         if prefix != "" and self.view.match_selector(locations[0], NO_COMPLETION_SCOPES):
121             # debug('discarding completion because no completion scope with prefix {}'.format(prefix))
122             return (
123                 [],
124                 sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS
125             )
126 
127         if not self.initialized:
128             self.initialize()
129 
130         if self.enabled:
131             reuse_completion = self.is_same_completion(prefix, locations)
132             if self.state == CompletionState.IDLE:
133                 if not reuse_completion:
134                     self.last_prefix = prefix
135                     self.last_location = locations[0]
136                     self.do_request(prefix, locations)
137                     self.completions = []
138 
139             elif self.state in (CompletionState.REQUESTING, CompletionState.CANCELLING):
140                 self.next_request = (prefix, locations)
141                 self.state = CompletionState.CANCELLING
142 
143             elif self.state == CompletionState.APPLYING:
144                 self.state = CompletionState.IDLE
145 
146             return (
147                 self.completions,
148                 0 if not settings.only_show_lsp_completions
149                 else sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS
150             )
151 
152     def do_request(self, prefix: str, locations: 'List[int]'):
153         self.next_request = None
154         view = self.view
155 
156         # don't store client so we can handle restarts
157         client = client_for_view(view)
158         if not client:
159             return
160 
161         if settings.complete_all_chars or self.is_after_trigger_character(locations[0]):
162             global_events.publish("view.on_purge_changes", self.view)
163             document_position = get_document_position(view, locations[0])
164             if document_position:
165                 client.send_request(
166                     Request.complete(document_position),
167                     self.handle_response,
168                     self.handle_error)
169                 self.state = CompletionState.REQUESTING
170 
171     def handle_response(self, response: 'Optional[Dict]'):
172 
173         if self.state == CompletionState.REQUESTING:
174             last_start = self.last_location - len(self.last_prefix)
175             last_row, last_col = self.view.rowcol(last_start)
176             self.completions = parse_completion_response(response, last_col, settings)
177 
178             # if insert_best_completion was just ran, undo it before presenting new completions.
179             prev_char = self.view.substr(self.view.sel()[0].begin() - 1)
180             if prev_char.isspace():
181                 if last_text_command == "insert_best_completion":
182                     self.view.run_command("undo")
183 
184             self.state = CompletionState.APPLYING
185             self.view.run_command("hide_auto_complete")
186             self.run_auto_complete()
187         elif self.state == CompletionState.CANCELLING:
188             self.state = CompletionState.IDLE
189             if self.next_request:
190                 prefix, locations = self.next_request
191                 self.do_request(prefix, locations)
192         else:
193             debug('Got unexpected response while in state {}'.format(self.state))
194 
195     def handle_error(self, error: dict):
196         sublime.status_message('Completion error: ' + str(error.get('message')))
197         self.state = CompletionState.IDLE
198 
199     def run_auto_complete(self):
200         self.view.run_command(
201             "auto_complete", {
202                 'disable_auto_insert': True,
203                 'api_completions_only': settings.only_show_lsp_completions,
204                 'next_completion_if_showing': False
205             })
206
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/plugin/completion.py b/plugin/completion.py
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -51,10 +51,7 @@
     @classmethod
     def is_applicable(cls, settings):
         syntax = settings.get('syntax')
-        if syntax is not None:
-            return is_supported_syntax(syntax, client_configs.all)
-        else:
-            return False
+        return is_supported_syntax(syntax) if syntax else False
 
     def initialize(self):
         self.initialized = True

{"golden_diff": "diff --git a/plugin/completion.py b/plugin/completion.py\n--- a/plugin/completion.py\n+++ b/plugin/completion.py\n@@ -51,10 +51,7 @@\n     @classmethod\n     def is_applicable(cls, settings):\n         syntax = settings.get('syntax')\n-        if syntax is not None:\n-            return is_supported_syntax(syntax, client_configs.all)\n-        else:\n-            return False\n+        return is_supported_syntax(syntax) if syntax else False\n \n     def initialize(self):\n         self.initialized = True\n", "issue": "TypeError: expected string or buffer\nhttps://github.com/tomv564/LSP/blob/e37c4e6d7d959890c465cada35dff7fef22feb6e/plugin/core/types.py#L50-L54\r\n\r\nIt happened only once so far, when `plugin_loaded` was called on start up. After restarting Sublime Text right away, it did not happened again.\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"F:\\SublimeText\\sublime_plugin.py\", line 298, in on_api_ready\r\n    plc()\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\boot.py\", line 30, in plugin_loaded\r\n    startup()\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\main.py\", line 25, in startup\r\n    start_active_window()\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\main.py\", line 44, in start_active_window\r\n    windows.lookup(window).start_active_views()\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\windows.py\", line 336, in start_active_views\r\n    self._initialize_on_open(view)\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\windows.py\", line 348, in _initialize_on_open\r\n    self._configs.syntax_configs(view))\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\configurations.py\", line 120, in syntax_configs\r\n    return list(filter(lambda c: config_supports_syntax(c, syntax) and c.enabled, self.all))\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\configurations.py\", line 120, in <lambda>\r\n    return list(filter(lambda c: config_supports_syntax(c, syntax) and c.enabled, self.all))\r\n  File \"F:\\SublimeText\\Data\\Packages\\LSP\\plugin\\core\\types.py\", line 81, in config_supports_syntax\r\n    if re.search(r'|'.join(r'\\b%s\\b' % re.escape(s) for s in language.syntaxes), syntax, re.IGNORECASE):\r\n  File \"./python3.3/re.py\", line 161, in search\r\nTypeError: expected string or buffer\r\n```\n", "before_files": [{"content": "import sublime\nimport sublime_plugin\n\ntry:\n    from typing import Any, List, Dict, Tuple, Callable, Optional\n    assert Any and List and Dict and Tuple and Callable and Optional\nexcept ImportError:\n    pass\n\nfrom .core.protocol import Request\nfrom .core.events import global_events\nfrom .core.settings import settings, client_configs\nfrom .core.logging import debug\nfrom .core.completion import parse_completion_response\nfrom .core.registry import session_for_view, client_for_view\nfrom .core.configurations import is_supported_syntax\nfrom .core.documents import get_document_position\nfrom .core.sessions import Session\n\nNO_COMPLETION_SCOPES = 'comment, string'\n\n\nclass CompletionState(object):\n    IDLE = 0\n    REQUESTING = 1\n    APPLYING = 2\n    CANCELLING = 3\n\n\nlast_text_command = None\n\n\nclass CompletionHelper(sublime_plugin.EventListener):\n    def on_text_command(self, view, command_name, args):\n        global last_text_command\n        last_text_command = command_name\n\n\nclass CompletionHandler(sublime_plugin.ViewEventListener):\n    def __init__(self, view):\n        self.view = view\n        self.initialized = False\n        self.enabled = False\n        self.trigger_chars = []  # type: List[str]\n        self.state = CompletionState.IDLE\n        self.completions = []  # type: List[Any]\n        self.next_request = None  # type: Optional[Tuple[str, List[int]]]\n        self.last_prefix = \"\"\n        self.last_location = 0\n\n    @classmethod\n    def is_applicable(cls, settings):\n        syntax = settings.get('syntax')\n        if syntax is not None:\n            return is_supported_syntax(syntax, client_configs.all)\n        else:\n            return False\n\n    def initialize(self):\n        self.initialized = True\n        session = session_for_view(self.view)\n        if session:\n            completionProvider = session.get_capability(\n                'completionProvider')\n            if completionProvider:\n                self.enabled = True\n                self.trigger_chars = completionProvider.get(\n                    'triggerCharacters') or []\n                if self.trigger_chars:\n                    self.register_trigger_chars(session)\n\n    def _view_language(self, config_name: str) -> 'Optional[str]':\n        languages = self.view.settings().get('lsp_language')\n        return languages.get(config_name) if languages else None\n\n    def register_trigger_chars(self, session: Session) -> None:\n        completion_triggers = self.view.settings().get('auto_complete_triggers', [])\n        view_language = self._view_language(session.config.name)\n        if view_language:\n            for language in session.config.languages:\n                if language.id == view_language:\n                    for scope in language.scopes:\n                        # debug(\"registering\", self.trigger_chars, \"for\", scope)\n                        scope_trigger = next(\n                            (trigger for trigger in completion_triggers if trigger.get('selector', None) == scope),\n                            None\n                        )\n                        if scope_trigger:\n                            scope_trigger['characters'] = \"\".join(self.trigger_chars)\n                        else:\n                            completion_triggers.append({\n                                'characters': \"\".join(self.trigger_chars),\n                                'selector': scope\n                            })\n\n            self.view.settings().set('auto_complete_triggers', completion_triggers)\n\n    def is_after_trigger_character(self, location):\n        if location > 0:\n            prev_char = self.view.substr(location - 1)\n            return prev_char in self.trigger_chars\n\n    def is_same_completion(self, prefix, locations):\n        # completion requests from the same location with the same prefix are cached.\n        current_start = locations[0] - len(prefix)\n        last_start = self.last_location - len(self.last_prefix)\n        return prefix.startswith(self.last_prefix) and current_start == last_start\n\n    def on_modified(self):\n        # hide completion when backspacing past last completion.\n        if self.view.sel()[0].begin() < self.last_location:\n            self.last_location = 0\n            self.view.run_command(\"hide_auto_complete\")\n        # cancel current completion if the previous input is an space\n        prev_char = self.view.substr(self.view.sel()[0].begin() - 1)\n        if self.state == CompletionState.REQUESTING and prev_char.isspace():\n            self.state = CompletionState.CANCELLING\n\n    def on_query_completions(self, prefix, locations):\n        if prefix != \"\" and self.view.match_selector(locations[0], NO_COMPLETION_SCOPES):\n            # debug('discarding completion because no completion scope with prefix {}'.format(prefix))\n            return (\n                [],\n                sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS\n            )\n\n        if not self.initialized:\n            self.initialize()\n\n        if self.enabled:\n            reuse_completion = self.is_same_completion(prefix, locations)\n            if self.state == CompletionState.IDLE:\n                if not reuse_completion:\n                    self.last_prefix = prefix\n                    self.last_location = locations[0]\n                    self.do_request(prefix, locations)\n                    self.completions = []\n\n            elif self.state in (CompletionState.REQUESTING, CompletionState.CANCELLING):\n                self.next_request = (prefix, locations)\n                self.state = CompletionState.CANCELLING\n\n            elif self.state == CompletionState.APPLYING:\n                self.state = CompletionState.IDLE\n\n            return (\n                self.completions,\n                0 if not settings.only_show_lsp_completions\n                else sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS\n            )\n\n    def do_request(self, prefix: str, locations: 'List[int]'):\n        self.next_request = None\n        view = self.view\n\n        # don't store client so we can handle restarts\n        client = client_for_view(view)\n        if not client:\n            return\n\n        if settings.complete_all_chars or self.is_after_trigger_character(locations[0]):\n            global_events.publish(\"view.on_purge_changes\", self.view)\n            document_position = get_document_position(view, locations[0])\n            if document_position:\n                client.send_request(\n                    Request.complete(document_position),\n                    self.handle_response,\n                    self.handle_error)\n                self.state = CompletionState.REQUESTING\n\n    def handle_response(self, response: 'Optional[Dict]'):\n\n        if self.state == CompletionState.REQUESTING:\n            last_start = self.last_location - len(self.last_prefix)\n            last_row, last_col = self.view.rowcol(last_start)\n            self.completions = parse_completion_response(response, last_col, settings)\n\n            # if insert_best_completion was just ran, undo it before presenting new completions.\n            prev_char = self.view.substr(self.view.sel()[0].begin() - 1)\n            if prev_char.isspace():\n                if last_text_command == \"insert_best_completion\":\n                    self.view.run_command(\"undo\")\n\n            self.state = CompletionState.APPLYING\n            self.view.run_command(\"hide_auto_complete\")\n            self.run_auto_complete()\n        elif self.state == CompletionState.CANCELLING:\n            self.state = CompletionState.IDLE\n            if self.next_request:\n                prefix, locations = self.next_request\n                self.do_request(prefix, locations)\n        else:\n            debug('Got unexpected response while in state {}'.format(self.state))\n\n    def handle_error(self, error: dict):\n        sublime.status_message('Completion error: ' + str(error.get('message')))\n        self.state = CompletionState.IDLE\n\n    def run_auto_complete(self):\n        self.view.run_command(\n            \"auto_complete\", {\n                'disable_auto_insert': True,\n                'api_completions_only': settings.only_show_lsp_completions,\n                'next_completion_if_showing': False\n            })\n", "path": "plugin/completion.py"}], "after_files": [{"content": "import sublime\nimport sublime_plugin\n\ntry:\n    from typing import Any, List, Dict, Tuple, Callable, Optional\n    assert Any and List and Dict and Tuple and Callable and Optional\nexcept ImportError:\n    pass\n\nfrom .core.protocol import Request\nfrom .core.events import global_events\nfrom .core.settings import settings, client_configs\nfrom .core.logging import debug\nfrom .core.completion import parse_completion_response\nfrom .core.registry import session_for_view, client_for_view\nfrom .core.configurations import is_supported_syntax\nfrom .core.documents import get_document_position\nfrom .core.sessions import Session\n\nNO_COMPLETION_SCOPES = 'comment, string'\n\n\nclass CompletionState(object):\n    IDLE = 0\n    REQUESTING = 1\n    APPLYING = 2\n    CANCELLING = 3\n\n\nlast_text_command = None\n\n\nclass CompletionHelper(sublime_plugin.EventListener):\n    def on_text_command(self, view, command_name, args):\n        global last_text_command\n        last_text_command = command_name\n\n\nclass CompletionHandler(sublime_plugin.ViewEventListener):\n    def __init__(self, view):\n        self.view = view\n        self.initialized = False\n        self.enabled = False\n        self.trigger_chars = []  # type: List[str]\n        self.state = CompletionState.IDLE\n        self.completions = []  # type: List[Any]\n        self.next_request = None  # type: Optional[Tuple[str, List[int]]]\n        self.last_prefix = \"\"\n        self.last_location = 0\n\n    @classmethod\n    def is_applicable(cls, settings):\n        syntax = settings.get('syntax')\n        return is_supported_syntax(syntax) if syntax else False\n\n    def initialize(self):\n        self.initialized = True\n        session = session_for_view(self.view)\n        if session:\n            completionProvider = session.get_capability(\n                'completionProvider')\n            if completionProvider:\n                self.enabled = True\n                self.trigger_chars = completionProvider.get(\n                    'triggerCharacters') or []\n                if self.trigger_chars:\n                    self.register_trigger_chars(session)\n\n    def _view_language(self, config_name: str) -> 'Optional[str]':\n        languages = self.view.settings().get('lsp_language')\n        return languages.get(config_name) if languages else None\n\n    def register_trigger_chars(self, session: Session) -> None:\n        completion_triggers = self.view.settings().get('auto_complete_triggers', [])\n        view_language = self._view_language(session.config.name)\n        if view_language:\n            for language in session.config.languages:\n                if language.id == view_language:\n                    for scope in language.scopes:\n                        # debug(\"registering\", self.trigger_chars, \"for\", scope)\n                        scope_trigger = next(\n                            (trigger for trigger in completion_triggers if trigger.get('selector', None) == scope),\n                            None\n                        )\n                        if scope_trigger:\n                            scope_trigger['characters'] = \"\".join(self.trigger_chars)\n                        else:\n                            completion_triggers.append({\n                                'characters': \"\".join(self.trigger_chars),\n                                'selector': scope\n                            })\n\n            self.view.settings().set('auto_complete_triggers', completion_triggers)\n\n    def is_after_trigger_character(self, location):\n        if location > 0:\n            prev_char = self.view.substr(location - 1)\n            return prev_char in self.trigger_chars\n\n    def is_same_completion(self, prefix, locations):\n        # completion requests from the same location with the same prefix are cached.\n        current_start = locations[0] - len(prefix)\n        last_start = self.last_location - len(self.last_prefix)\n        return prefix.startswith(self.last_prefix) and current_start == last_start\n\n    def on_modified(self):\n        # hide completion when backspacing past last completion.\n        if self.view.sel()[0].begin() < self.last_location:\n            self.last_location = 0\n            self.view.run_command(\"hide_auto_complete\")\n        # cancel current completion if the previous input is an space\n        prev_char = self.view.substr(self.view.sel()[0].begin() - 1)\n        if self.state == CompletionState.REQUESTING and prev_char.isspace():\n            self.state = CompletionState.CANCELLING\n\n    def on_query_completions(self, prefix, locations):\n        if prefix != \"\" and self.view.match_selector(locations[0], NO_COMPLETION_SCOPES):\n            # debug('discarding completion because no completion scope with prefix {}'.format(prefix))\n            return (\n                [],\n                sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS\n            )\n\n        if not self.initialized:\n            self.initialize()\n\n        if self.enabled:\n            reuse_completion = self.is_same_completion(prefix, locations)\n            if self.state == CompletionState.IDLE:\n                if not reuse_completion:\n                    self.last_prefix = prefix\n                    self.last_location = locations[0]\n                    self.do_request(prefix, locations)\n                    self.completions = []\n\n            elif self.state in (CompletionState.REQUESTING, CompletionState.CANCELLING):\n                self.next_request = (prefix, locations)\n                self.state = CompletionState.CANCELLING\n\n            elif self.state == CompletionState.APPLYING:\n                self.state = CompletionState.IDLE\n\n            return (\n                self.completions,\n                0 if not settings.only_show_lsp_completions\n                else sublime.INHIBIT_WORD_COMPLETIONS | sublime.INHIBIT_EXPLICIT_COMPLETIONS\n            )\n\n    def do_request(self, prefix: str, locations: 'List[int]'):\n        self.next_request = None\n        view = self.view\n\n        # don't store client so we can handle restarts\n        client = client_for_view(view)\n        if not client:\n            return\n\n        if settings.complete_all_chars or self.is_after_trigger_character(locations[0]):\n            global_events.publish(\"view.on_purge_changes\", self.view)\n            document_position = get_document_position(view, locations[0])\n            if document_position:\n                client.send_request(\n                    Request.complete(document_position),\n                    self.handle_response,\n                    self.handle_error)\n                self.state = CompletionState.REQUESTING\n\n    def handle_response(self, response: 'Optional[Dict]'):\n\n        if self.state == CompletionState.REQUESTING:\n            last_start = self.last_location - len(self.last_prefix)\n            last_row, last_col = self.view.rowcol(last_start)\n            self.completions = parse_completion_response(response, last_col, settings)\n\n            # if insert_best_completion was just ran, undo it before presenting new completions.\n            prev_char = self.view.substr(self.view.sel()[0].begin() - 1)\n            if prev_char.isspace():\n                if last_text_command == \"insert_best_completion\":\n                    self.view.run_command(\"undo\")\n\n            self.state = CompletionState.APPLYING\n            self.view.run_command(\"hide_auto_complete\")\n            self.run_auto_complete()\n        elif self.state == CompletionState.CANCELLING:\n            self.state = CompletionState.IDLE\n            if self.next_request:\n                prefix, locations = self.next_request\n                self.do_request(prefix, locations)\n        else:\n            debug('Got unexpected response while in state {}'.format(self.state))\n\n    def handle_error(self, error: dict):\n        sublime.status_message('Completion error: ' + str(error.get('message')))\n        self.state = CompletionState.IDLE\n\n    def run_auto_complete(self):\n        self.view.run_command(\n            \"auto_complete\", {\n                'disable_auto_insert': True,\n                'api_completions_only': settings.only_show_lsp_completions,\n                'next_completion_if_showing': False\n            })\n", "path": "plugin/completion.py"}]}