prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Recursive variable expansion in lsp_execute command
  **Is your feature request related to a problem? Please describe.**
  
  The documentation states ...
  
  ```js
  [
    // ...
    {
      "caption": "Thread First",
      "command": "lsp_execute",
      "args": {
        "command_name": "thread-first",
        "command_args": ["${file_uri}", 0, 0]
      }
    }
  ]
  ```
  
  Note: `command_args` is optional depending on the `workspace/executeCommand` that are supported by the LSP server.
  The following **variables will be expanded, but only if they are top-level array items** and not within nested arrays or objects:
  
  The **LemMinX** language server provides a validation command which expects [textDocumentIdentifie](https://microsoft.github.io/language-server-protocol/specification#textDocumentIdentifier) as first parameter.
  
  see: https://github.com/eclipse/lemminx/pull/938
  
  The proper command definition in ST would look like
  
  ```
  [
  	{
  		"caption": "XML: Validate File",
  		"command": "lsp_execute",
  		"args": {
  			"command_name": "xml.validation.current.file",
  			"command_args": [{"uri": "${file_uri}"}]
  		}
  	}
  ]
  ```
  
  Unfortunatelly `${file_uri}` is not expanded as it is not in the top-level array.
  
  **Describe the solution you'd like**
  
  The most flexible and straight forward solution would probably be to support recursive variable expansions in all nested arrays and objects.
  
  **Describe alternatives you've considered**
  
  An `$document_id` variable which is expanded to `{"uri": "file:///path/to/file.xml"}` would do the job as well. The command definition would look as follows then.
  
  ```
  [
  	{
  		"caption": "XML: Validate File",
  		"command": "lsp_execute",
  		"args": {
  			"command_name": "xml.validation.current.file",
  			"command_args": ["$document_id"]
  		}
  	}
  ]
  ```
  
  
  
  
  
  </issue>
  <code>
  [start of plugin/execute_command.py]
  1 import sublime
  2 from .core.protocol import Error
  3 from .core.protocol import ExecuteCommandParams
  4 from .core.registry import LspTextCommand
  5 from .core.typing import List, Optional, Any
  6 from .core.views import uri_from_view, offset_to_point, region_to_range
  7 
  8 
  9 class LspExecuteCommand(LspTextCommand):
  10 
  11     capability = 'executeCommandProvider'
  12 
  13     def run(self,
  14             edit: sublime.Edit,
  15             command_name: Optional[str] = None,
  16             command_args: Optional[List[Any]] = None,
  17             session_name: Optional[str] = None,
  18             event: Optional[dict] = None) -> None:
  19         session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)
  20         if session and command_name:
  21             if command_args:
  22                 self._expand_variables(command_args)
  23             params = {"command": command_name}  # type: ExecuteCommandParams
  24             if command_args:
  25                 params["arguments"] = command_args
  26 
  27             def handle_response(response: Any) -> None:
  28                 assert command_name
  29                 if isinstance(response, Error):
  30                     sublime.message_dialog("command {} failed. Reason: {}".format(command_name, str(response)))
  31                     return
  32                 msg = "command {} completed".format(command_name)
  33                 if response:
  34                     msg += "with response: {}".format(response)
  35                 window = self.view.window()
  36                 if window:
  37                     window.status_message(msg)
  38 
  39             session.execute_command(params).then(handle_response)
  40 
  41     def _expand_variables(self, command_args: List[Any]) -> None:
  42         region = self.view.sel()[0]
  43         for i, arg in enumerate(command_args):
  44             if arg in ["$file_uri", "${file_uri}"]:
  45                 command_args[i] = uri_from_view(self.view)
  46             elif arg in ["$selection", "${selection}"]:
  47                 command_args[i] = self.view.substr(region)
  48             elif arg in ["$offset", "${offset}"]:
  49                 command_args[i] = region.b
  50             elif arg in ["$selection_begin", "${selection_begin}"]:
  51                 command_args[i] = region.begin()
  52             elif arg in ["$selection_end", "${selection_end}"]:
  53                 command_args[i] = region.end()
  54             elif arg in ["$position", "${position}"]:
  55                 command_args[i] = offset_to_point(self.view, region.b).to_lsp()
  56             elif arg in ["$range", "${range}"]:
  57                 command_args[i] = region_to_range(self.view, region).to_lsp()
  58
  [end of plugin/execute_command.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/execute_command.py b/plugin/execute_command.py
  --- a/plugin/execute_command.py
  +++ b/plugin/execute_command.py
  @@ -3,7 +3,7 @@
   from .core.protocol import ExecuteCommandParams
   from .core.registry import LspTextCommand
   from .core.typing import List, Optional, Any
  -from .core.views import uri_from_view, offset_to_point, region_to_range
  +from .core.views import uri_from_view, offset_to_point, region_to_range, text_document_identifier
   
   
   class LspExecuteCommand(LspTextCommand):
  @@ -41,6 +41,8 @@
       def _expand_variables(self, command_args: List[Any]) -> None:
           region = self.view.sel()[0]
           for i, arg in enumerate(command_args):
  +            if arg in ["$document_id", "${document_id}"]:
  +                command_args[i] = text_document_identifier(self.view)
               if arg in ["$file_uri", "${file_uri}"]:
                   command_args[i] = uri_from_view(self.view)
               elif arg in ["$selection", "${selection}"]:
  
verification_info: {"golden_diff": "diff --git a/plugin/execute_command.py b/plugin/execute_command.py\n--- a/plugin/execute_command.py\n+++ b/plugin/execute_command.py\n@@ -3,7 +3,7 @@\n from .core.protocol import ExecuteCommandParams\n from .core.registry import LspTextCommand\n from .core.typing import List, Optional, Any\n-from .core.views import uri_from_view, offset_to_point, region_to_range\n+from .core.views import uri_from_view, offset_to_point, region_to_range, text_document_identifier\n \n \n class LspExecuteCommand(LspTextCommand):\n@@ -41,6 +41,8 @@\n     def _expand_variables(self, command_args: List[Any]) -> None:\n         region = self.view.sel()[0]\n         for i, arg in enumerate(command_args):\n+            if arg in [\"$document_id\", \"${document_id}\"]:\n+                command_args[i] = text_document_identifier(self.view)\n             if arg in [\"$file_uri\", \"${file_uri}\"]:\n                 command_args[i] = uri_from_view(self.view)\n             elif arg in [\"$selection\", \"${selection}\"]:\n", "issue": "Recursive variable expansion in lsp_execute command\n**Is your feature request related to a problem? Please describe.**\r\n\r\nThe documentation states ...\r\n\r\n```js\r\n[\r\n  // ...\r\n  {\r\n    \"caption\": \"Thread First\",\r\n    \"command\": \"lsp_execute\",\r\n    \"args\": {\r\n      \"command_name\": \"thread-first\",\r\n      \"command_args\": [\"${file_uri}\", 0, 0]\r\n    }\r\n  }\r\n]\r\n```\r\n\r\nNote: `command_args` is optional depending on the `workspace/executeCommand` that are supported by the LSP server.\r\nThe following **variables will be expanded, but only if they are top-level array items** and not within nested arrays or objects:\r\n\r\nThe **LemMinX** language server provides a validation command which expects [textDocumentIdentifie](https://microsoft.github.io/language-server-protocol/specification#textDocumentIdentifier) as first parameter.\r\n\r\nsee: https://github.com/eclipse/lemminx/pull/938\r\n\r\nThe proper command definition in ST would look like\r\n\r\n```\r\n[\r\n\t{\r\n\t\t\"caption\": \"XML: Validate File\",\r\n\t\t\"command\": \"lsp_execute\",\r\n\t\t\"args\": {\r\n\t\t\t\"command_name\": \"xml.validation.current.file\",\r\n\t\t\t\"command_args\": [{\"uri\": \"${file_uri}\"}]\r\n\t\t}\r\n\t}\r\n]\r\n```\r\n\r\nUnfortunatelly `${file_uri}` is not expanded as it is not in the top-level array.\r\n\r\n**Describe the solution you'd like**\r\n\r\nThe most flexible and straight forward solution would probably be to support recursive variable expansions in all nested arrays and objects.\r\n\r\n**Describe alternatives you've considered**\r\n\r\nAn `$document_id` variable which is expanded to `{\"uri\": \"file:///path/to/file.xml\"}` would do the job as well. The command definition would look as follows then.\r\n\r\n```\r\n[\r\n\t{\r\n\t\t\"caption\": \"XML: Validate File\",\r\n\t\t\"command\": \"lsp_execute\",\r\n\t\t\"args\": {\r\n\t\t\t\"command_name\": \"xml.validation.current.file\",\r\n\t\t\t\"command_args\": [\"$document_id\"]\r\n\t\t}\r\n\t}\r\n]\r\n```\r\n\r\n\r\n\r\n\n", "before_files": [{"content": "import sublime\nfrom .core.protocol import Error\nfrom .core.protocol import ExecuteCommandParams\nfrom .core.registry import LspTextCommand\nfrom .core.typing import List, Optional, Any\nfrom .core.views import uri_from_view, offset_to_point, region_to_range\n\n\nclass LspExecuteCommand(LspTextCommand):\n\n    capability = 'executeCommandProvider'\n\n    def run(self,\n            edit: sublime.Edit,\n            command_name: Optional[str] = None,\n            command_args: Optional[List[Any]] = None,\n            session_name: Optional[str] = None,\n            event: Optional[dict] = None) -> None:\n        session = self.session_by_name(session_name) if session_name else self.best_session(self.capability)\n        if session and command_name:\n            if command_args:\n                self._expand_variables(command_args)\n            params = {\"command\": command_name}  # type: ExecuteCommandParams\n            if command_args:\n                params[\"arguments\"] = command_args\n\n            def handle_response(response: Any) -> None:\n                assert command_name\n                if isinstance(response, Error):\n                    sublime.message_dialog(\"command {} failed. Reason: {}\".format(command_name, str(response)))\n                    return\n                msg = \"command {} completed\".format(command_name)\n                if response:\n                    msg += \"with response: {}\".format(response)\n                window = self.view.window()\n                if window:\n                    window.status_message(msg)\n\n            session.execute_command(params).then(handle_response)\n\n    def _expand_variables(self, command_args: List[Any]) -> None:\n        region = self.view.sel()[0]\n        for i, arg in enumerate(command_args):\n            if arg in [\"$file_uri\", \"${file_uri}\"]:\n                command_args[i] = uri_from_view(self.view)\n            elif arg in [\"$selection\", \"${selection}\"]:\n                command_args[i] = self.view.substr(region)\n            elif arg in [\"$offset\", \"${offset}\"]:\n                command_args[i] = region.b\n            elif arg in [\"$selection_begin\", \"${selection_begin}\"]:\n                command_args[i] = region.begin()\n            elif arg in [\"$selection_end\", \"${selection_end}\"]:\n                command_args[i] = region.end()\n            elif arg in [\"$position\", \"${position}\"]:\n                command_args[i] = offset_to_point(self.view, region.b).to_lsp()\n            elif arg in [\"$range\", \"${range}\"]:\n                command_args[i] = region_to_range(self.view, region).to_lsp()\n", "path": "plugin/execute_command.py"}]}