prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Scopes priorities while selecting configuration
  ## Bug:
  
  When there are multiple language servers configured, all of which are for similar scopes (Ex. `source.json`, `source.json.sublime.settings`) the configuration with the most specific scope should be preferred; however right now one or the other could "win", some times leading to erroneous configuration.
  
  Example comes from configuring **vscode-json-languageserver** to work with both `json` and `jsonc` languageIds.
  
  ### Suggestion:
  
  Give priority to the configuration with the most specific scope that matches.
  
  
  </issue>
  <code>
  [start of plugin/core/configurations.py]
  1 import sublime
  2 
  3 from .settings import ClientConfig, client_configs
  4 from .logging import debug
  5 from .workspace import get_project_config
  6 
  7 assert ClientConfig
  8 
  9 try:
  10     from typing import Any, List, Dict, Tuple, Callable, Optional
  11     assert Any and List and Dict and Tuple and Callable and Optional
  12 except ImportError:
  13     pass
  14 
  15 
  16 window_client_configs = dict()  # type: Dict[int, List[ClientConfig]]
  17 
  18 
  19 def get_scope_client_config(view: 'sublime.View', configs: 'List[ClientConfig]') -> 'Optional[ClientConfig]':
  20     for config in configs:
  21         for scope in config.scopes:
  22             if len(view.sel()) > 0:
  23                 if view.match_selector(view.sel()[0].begin(), scope):
  24                     return config
  25 
  26     return None
  27 
  28 
  29 def register_client_config(config: ClientConfig) -> None:
  30     window_client_configs.clear()
  31     client_configs.add_external_config(config)
  32 
  33 
  34 def get_global_client_config(view: sublime.View) -> 'Optional[ClientConfig]':
  35     return get_scope_client_config(view, client_configs.all)
  36 
  37 
  38 def get_default_client_config(view: sublime.View) -> 'Optional[ClientConfig]':
  39     return get_scope_client_config(view, client_configs.defaults)
  40 
  41 
  42 def get_window_client_config(view: sublime.View) -> 'Optional[ClientConfig]':
  43     window = view.window()
  44     if window:
  45         configs_for_window = window_client_configs.get(window.id(), [])
  46         return get_scope_client_config(view, configs_for_window)
  47     else:
  48         return None
  49 
  50 
  51 def config_for_scope(view: sublime.View) -> 'Optional[ClientConfig]':
  52     # check window_client_config first
  53     window_client_config = get_window_client_config(view)
  54     if not window_client_config:
  55         global_client_config = get_global_client_config(view)
  56 
  57         if global_client_config:
  58             window = view.window()
  59             if window:
  60                 window_client_config = apply_window_settings(global_client_config, view)
  61                 add_window_client_config(window, window_client_config)
  62                 return window_client_config
  63             else:
  64                 # always return a client config even if the view has no window anymore
  65                 return global_client_config
  66 
  67     return window_client_config
  68 
  69 
  70 def add_window_client_config(window: 'sublime.Window', config: 'ClientConfig'):
  71     global window_client_configs
  72     window_client_configs.setdefault(window.id(), []).append(config)
  73 
  74 
  75 def clear_window_client_configs(window: 'sublime.Window'):
  76     global window_client_configs
  77     if window.id() in window_client_configs:
  78         del window_client_configs[window.id()]
  79 
  80 
  81 def apply_window_settings(client_config: 'ClientConfig', view: 'sublime.View') -> 'ClientConfig':
  82     window = view.window()
  83     if window:
  84         window_config = get_project_config(window)
  85 
  86         if client_config.name in window_config:
  87             overrides = window_config[client_config.name]
  88             debug('window has override for', client_config.name, overrides)
  89             return ClientConfig(
  90                 client_config.name,
  91                 overrides.get("command", client_config.binary_args),
  92                 overrides.get("tcp_port", client_config.tcp_port),
  93                 overrides.get("scopes", client_config.scopes),
  94                 overrides.get("syntaxes", client_config.syntaxes),
  95                 overrides.get("languageId", client_config.languageId),
  96                 overrides.get("enabled", client_config.enabled),
  97                 overrides.get("initializationOptions", client_config.init_options),
  98                 overrides.get("settings", client_config.settings),
  99                 overrides.get("env", client_config.env)
  100             )
  101 
  102     return client_config
  103 
  104 
  105 def is_supportable_syntax(syntax: str) -> bool:
  106     # TODO: filter out configs disabled by the user.
  107     for config in client_configs.defaults:
  108         if syntax in config.syntaxes:
  109             return True
  110     return False
  111 
  112 
  113 def is_supported_syntax(syntax: str) -> bool:
  114     for config in client_configs.all:
  115         if syntax in config.syntaxes:
  116             return True
  117     return False
  118 
  119 
  120 def is_supported_view(view: sublime.View) -> bool:
  121     # TODO: perhaps make this check for a client instead of a config
  122     if config_for_scope(view):
  123         return True
  124     else:
  125         return False
  126
  [end of plugin/core/configurations.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/plugin/core/configurations.py b/plugin/core/configurations.py
  --- a/plugin/core/configurations.py
  +++ b/plugin/core/configurations.py
  @@ -17,13 +17,21 @@
   
   
   def get_scope_client_config(view: 'sublime.View', configs: 'List[ClientConfig]') -> 'Optional[ClientConfig]':
  +    # When there are multiple server configurations, all of which are for
  +    # similar scopes (e.g. 'source.json', 'source.json.sublime.settings') the
  +    # configuration with the most specific scope (highest ranked selector)
  +    # in the current position is preferred.
  +    scope_score = 0
  +    scope_client_config = None
       for config in configs:
           for scope in config.scopes:
  -            if len(view.sel()) > 0:
  -                if view.match_selector(view.sel()[0].begin(), scope):
  -                    return config
  -
  -    return None
  +            sel = view.sel()
  +            if len(sel) > 0:
  +                score = view.score_selector(sel[0].begin(), scope)
  +                if score > scope_score:
  +                    scope_score = score
  +                    scope_client_config = config
  +    return scope_client_config
   
   
   def register_client_config(config: ClientConfig) -> None:
  
verification_info: {"golden_diff": "diff --git a/plugin/core/configurations.py b/plugin/core/configurations.py\n--- a/plugin/core/configurations.py\n+++ b/plugin/core/configurations.py\n@@ -17,13 +17,21 @@\n \n \n def get_scope_client_config(view: 'sublime.View', configs: 'List[ClientConfig]') -> 'Optional[ClientConfig]':\n+    # When there are multiple server configurations, all of which are for\n+    # similar scopes (e.g. 'source.json', 'source.json.sublime.settings') the\n+    # configuration with the most specific scope (highest ranked selector)\n+    # in the current position is preferred.\n+    scope_score = 0\n+    scope_client_config = None\n     for config in configs:\n         for scope in config.scopes:\n-            if len(view.sel()) > 0:\n-                if view.match_selector(view.sel()[0].begin(), scope):\n-                    return config\n-\n-    return None\n+            sel = view.sel()\n+            if len(sel) > 0:\n+                score = view.score_selector(sel[0].begin(), scope)\n+                if score > scope_score:\n+                    scope_score = score\n+                    scope_client_config = config\n+    return scope_client_config\n \n \n def register_client_config(config: ClientConfig) -> None:\n", "issue": "Scopes priorities while selecting configuration\n## Bug:\r\n\r\nWhen there are multiple language servers configured, all of which are for similar scopes (Ex. `source.json`, `source.json.sublime.settings`) the configuration with the most specific scope should be preferred; however right now one or the other could \"win\", some times leading to erroneous configuration.\r\n\r\nExample comes from configuring **vscode-json-languageserver** to work with both `json` and `jsonc` languageIds.\r\n\r\n### Suggestion:\r\n\r\nGive priority to the configuration with the most specific scope that matches.\r\n\n", "before_files": [{"content": "import sublime\n\nfrom .settings import ClientConfig, client_configs\nfrom .logging import debug\nfrom .workspace import get_project_config\n\nassert ClientConfig\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\n\nwindow_client_configs = dict()  # type: Dict[int, List[ClientConfig]]\n\n\ndef get_scope_client_config(view: 'sublime.View', configs: 'List[ClientConfig]') -> 'Optional[ClientConfig]':\n    for config in configs:\n        for scope in config.scopes:\n            if len(view.sel()) > 0:\n                if view.match_selector(view.sel()[0].begin(), scope):\n                    return config\n\n    return None\n\n\ndef register_client_config(config: ClientConfig) -> None:\n    window_client_configs.clear()\n    client_configs.add_external_config(config)\n\n\ndef get_global_client_config(view: sublime.View) -> 'Optional[ClientConfig]':\n    return get_scope_client_config(view, client_configs.all)\n\n\ndef get_default_client_config(view: sublime.View) -> 'Optional[ClientConfig]':\n    return get_scope_client_config(view, client_configs.defaults)\n\n\ndef get_window_client_config(view: sublime.View) -> 'Optional[ClientConfig]':\n    window = view.window()\n    if window:\n        configs_for_window = window_client_configs.get(window.id(), [])\n        return get_scope_client_config(view, configs_for_window)\n    else:\n        return None\n\n\ndef config_for_scope(view: sublime.View) -> 'Optional[ClientConfig]':\n    # check window_client_config first\n    window_client_config = get_window_client_config(view)\n    if not window_client_config:\n        global_client_config = get_global_client_config(view)\n\n        if global_client_config:\n            window = view.window()\n            if window:\n                window_client_config = apply_window_settings(global_client_config, view)\n                add_window_client_config(window, window_client_config)\n                return window_client_config\n            else:\n                # always return a client config even if the view has no window anymore\n                return global_client_config\n\n    return window_client_config\n\n\ndef add_window_client_config(window: 'sublime.Window', config: 'ClientConfig'):\n    global window_client_configs\n    window_client_configs.setdefault(window.id(), []).append(config)\n\n\ndef clear_window_client_configs(window: 'sublime.Window'):\n    global window_client_configs\n    if window.id() in window_client_configs:\n        del window_client_configs[window.id()]\n\n\ndef apply_window_settings(client_config: 'ClientConfig', view: 'sublime.View') -> 'ClientConfig':\n    window = view.window()\n    if window:\n        window_config = get_project_config(window)\n\n        if client_config.name in window_config:\n            overrides = window_config[client_config.name]\n            debug('window has override for', client_config.name, overrides)\n            return ClientConfig(\n                client_config.name,\n                overrides.get(\"command\", client_config.binary_args),\n                overrides.get(\"tcp_port\", client_config.tcp_port),\n                overrides.get(\"scopes\", client_config.scopes),\n                overrides.get(\"syntaxes\", client_config.syntaxes),\n                overrides.get(\"languageId\", client_config.languageId),\n                overrides.get(\"enabled\", client_config.enabled),\n                overrides.get(\"initializationOptions\", client_config.init_options),\n                overrides.get(\"settings\", client_config.settings),\n                overrides.get(\"env\", client_config.env)\n            )\n\n    return client_config\n\n\ndef is_supportable_syntax(syntax: str) -> bool:\n    # TODO: filter out configs disabled by the user.\n    for config in client_configs.defaults:\n        if syntax in config.syntaxes:\n            return True\n    return False\n\n\ndef is_supported_syntax(syntax: str) -> bool:\n    for config in client_configs.all:\n        if syntax in config.syntaxes:\n            return True\n    return False\n\n\ndef is_supported_view(view: sublime.View) -> bool:\n    # TODO: perhaps make this check for a client instead of a config\n    if config_for_scope(view):\n        return True\n    else:\n        return False\n", "path": "plugin/core/configurations.py"}]}