Repository: sublimelsp/LSP

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
```


Discussion:
Thanks for reporting! I am guessing the 'syntax' argument is `None` ? Perhaps we can guard against this?
I am not sure yet. Since I added the debug message, I did not receive it yet.

But, if it is receiving None, I would investigate first from where it comes from. I will know more when this happens again because later on, I also added for it to print the stack trace.
I'm seeing a similar error:

```
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 369, in <lambda>
    lambda: check_view_event_listeners(view))
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 356, in check_view_event_listeners
    want = is_view_event_listener_applicable(cls, view)
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 321, in is_view_event_listener_applicable
    if not cls.is_applicable(view.settings()):
  File "/Users/margus/Library/Application Support/Sublime Text 3/Packages/LSP/plugin/completion.py", line 144, in is_applicable
    return is_supported_syntax(syntax)
  File "/Users/margus/Library/Application Support/Sublime Text 3/Packages/LSP/plugin/core/configurations.py", line 91, in is_supported_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
```

I traced it back to:
https://github.com/tomv564/LSP/blob/6d64e31fed6a008473ed3f692c85cb94e45be17e/plugin/completion.py#L141

it seems there is a bug of some sort in sublime, where `settings.get('syntax')` returns `0` instead of `None`. Might be the issue for the original report as well.  

Atm I fixed it with just removing the strict `None` check:

```
if syntax:
```
It could be a new bug on Sublime Text Core similar to:
1. https://github.com/SublimeTextIssues/Core/issues/2548 view.settings().get('setting_name', 10) returns None randomly

If you can, you could try to isolate and figure out where it is coming from.
Thanks for linking to Sublime Text issues - it feels like recent developments (are you guys all on dev builds?) are responsible for this. Would like to avoid changing to less-precise logic if ST fixes this on their end. 
I am not using dev builds since they started crashing in December last year: https://github.com/SublimeTextIssues/Core/issues/2519

As of now, I use the latest stable build 3200.
Same here, stable 3200. 
Ah, a new non-dev build came out, that would explain things. Given the number of users on 3200 I think @kerma's fix might be worth releasing!

Resolving patch:
diff --git a/plugin/completion.py b/plugin/completion.py
--- a/plugin/completion.py
+++ b/plugin/completion.py
@@ -51,10 +51,7 @@ def __init__(self, view):
     @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


Test patch: