We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Code actions of CodeActionLiteral type are not supported (used by eslint-server)
While experimenting with [eslint-server](https://github.com/Microsoft/vscode-eslint/tree/master/server), I've noticed that its code actions for fixing lint issues are not handled properly.

I found two issues:
 - handling CodeActions action list as an array of `Command` while protocol also allows array of `CodeAction`.
 - Passing `args` param to `workspace/executeCommand` instead of expected `arguments` param.

--- 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/core/sessions.py`
Content:
```
1 from .types import ClientConfig, ClientStates, Settings
2 from .protocol import Request
3 from .transports import start_tcp_transport
4 from .rpc import Client, attach_stdio_client
5 from .process import start_server
6 from .url import filename_to_uri
7 from .logging import debug
8 import os
9 from .protocol import CompletionItemKind, SymbolKind
10 try:
11     from typing import Callable, Dict, Any, Optional
12     assert Callable and Dict and Any and Optional
13 except ImportError:
14     pass
15 
16 
17 def create_session(config: ClientConfig, project_path: str, env: dict, settings: Settings,
18                    on_created=None, on_ended: 'Optional[Callable[[str], None]]' = None,
19                    bootstrap_client=None) -> 'Optional[Session]':
20     session = None
21     if config.binary_args:
22 
23         process = start_server(config.binary_args, project_path, env, settings.log_stderr)
24         if process:
25             if config.tcp_port:
26                 transport = start_tcp_transport(config.tcp_port, config.tcp_host)
27                 if transport:
28                     session = Session(config, project_path, Client(transport, settings), on_created, on_ended)
29                 else:
30                     # try to terminate the process
31                     try:
32                         process.terminate()
33                     except Exception:
34                         pass
35             else:
36                 client = attach_stdio_client(process, settings)
37                 session = Session(config, project_path, client, on_created, on_ended)
38     else:
39         if config.tcp_port:
40             transport = start_tcp_transport(config.tcp_port)
41 
42             session = Session(config, project_path, Client(transport, settings),
43                               on_created, on_ended)
44         elif bootstrap_client:
45             session = Session(config, project_path, bootstrap_client,
46                               on_created, on_ended)
47         else:
48             debug("No way to start session")
49 
50     return session
51 
52 
53 def get_initialize_params(project_path: str, config: ClientConfig):
54     initializeParams = {
55         "processId": os.getpid(),
56         "rootUri": filename_to_uri(project_path),
57         "rootPath": project_path,
58         "capabilities": {
59             "textDocument": {
60                 "synchronization": {
61                     "didSave": True
62                 },
63                 "hover": {
64                     "contentFormat": ["markdown", "plaintext"]
65                 },
66                 "completion": {
67                     "completionItem": {
68                         "snippetSupport": True
69                     },
70                     "completionItemKind": {
71                         "valueSet": [
72                             CompletionItemKind.Text,
73                             CompletionItemKind.Method,
74                             CompletionItemKind.Function,
75                             CompletionItemKind.Constructor,
76                             CompletionItemKind.Field,
77                             CompletionItemKind.Variable,
78                             CompletionItemKind.Class,
79                             CompletionItemKind.Interface,
80                             CompletionItemKind.Module,
81                             CompletionItemKind.Property,
82                             CompletionItemKind.Unit,
83                             CompletionItemKind.Value,
84                             CompletionItemKind.Enum,
85                             CompletionItemKind.Keyword,
86                             CompletionItemKind.Snippet,
87                             CompletionItemKind.Color,
88                             CompletionItemKind.File,
89                             CompletionItemKind.Reference
90                         ]
91                     }
92                 },
93                 "signatureHelp": {
94                     "signatureInformation": {
95                         "documentationFormat": ["markdown", "plaintext"],
96                         "parameterInformation": {
97                             "labelOffsetSupport": True
98                         }
99                     }
100                 },
101                 "references": {},
102                 "documentHighlight": {},
103                 "documentSymbol": {
104                     "symbolKind": {
105                         "valueSet": [
106                             SymbolKind.File,
107                             SymbolKind.Module,
108                             SymbolKind.Namespace,
109                             SymbolKind.Package,
110                             SymbolKind.Class,
111                             SymbolKind.Method,
112                             SymbolKind.Property,
113                             SymbolKind.Field,
114                             SymbolKind.Constructor,
115                             SymbolKind.Enum,
116                             SymbolKind.Interface,
117                             SymbolKind.Function,
118                             SymbolKind.Variable,
119                             SymbolKind.Constant,
120                             SymbolKind.String,
121                             SymbolKind.Number,
122                             SymbolKind.Boolean,
123                             SymbolKind.Array,
124                             SymbolKind.Object,
125                             SymbolKind.Key,
126                             SymbolKind.Null,
127                             SymbolKind.EnumMember,
128                             SymbolKind.Struct,
129                             SymbolKind.Event,
130                             SymbolKind.Operator,
131                             SymbolKind.TypeParameter
132                         ]
133                     }
134                 },
135                 "formatting": {},
136                 "rangeFormatting": {},
137                 "definition": {},
138                 "codeAction": {},
139                 "rename": {}
140             },
141             "workspace": {
142                 "applyEdit": True,
143                 "didChangeConfiguration": {}
144             }
145         }
146     }
147     if config.init_options:
148         initializeParams['initializationOptions'] = config.init_options
149 
150     return initializeParams
151 
152 
153 class Session(object):
154     def __init__(self, config: ClientConfig, project_path, client: Client,
155                  on_created=None, on_ended: 'Optional[Callable[[str], None]]' = None) -> None:
156         self.config = config
157         self.project_path = project_path
158         self.state = ClientStates.STARTING
159         self._on_created = on_created
160         self._on_ended = on_ended
161         self.capabilities = dict()  # type: Dict[str, Any]
162         self.client = client
163         self.initialize()
164 
165     def has_capability(self, capability):
166         return capability in self.capabilities and self.capabilities[capability] is not False
167 
168     def get_capability(self, capability):
169         return self.capabilities.get(capability)
170 
171     def initialize(self):
172         params = get_initialize_params(self.project_path, self.config)
173         self.client.send_request(
174             Request.initialize(params),
175             lambda result: self._handle_initialize_result(result))
176 
177     def _handle_initialize_result(self, result):
178         self.state = ClientStates.READY
179         self.capabilities = result.get('capabilities', dict())
180         if self._on_created:
181             self._on_created(self)
182 
183     def end(self):
184         self.state = ClientStates.STOPPING
185         self.client.send_request(
186             Request.shutdown(),
187             lambda result: self._handle_shutdown_result(),
188             lambda: self._handle_shutdown_result())
189 
190     def _handle_shutdown_result(self):
191         self.client.exit()
192         self.client = None
193         self.capabilities = dict()
194         if self._on_ended:
195             self._on_ended(self.config.name)
196
```

Path: `plugin/code_actions.py`
Content:
```
1 import sublime_plugin
2 import sublime
3 
4 try:
5     from typing import Any, List, Dict, Callable, Optional
6     assert Any and List and Dict and Callable and Optional
7 except ImportError:
8     pass
9 
10 from .core.registry import client_for_view, LspTextCommand
11 from .core.protocol import Request
12 from .diagnostics import get_point_diagnostics
13 from .core.url import filename_to_uri
14 from .core.views import region_to_range
15 from .core.registry import session_for_view
16 from .core.settings import settings
17 
18 
19 def send_code_action_request(view, on_response_recieved: 'Callable'):
20     session = session_for_view(view)
21     if not session or not session.has_capability('codeActionProvider'):
22         # the server doesn't support code actions, just return
23         return
24 
25     region = view.sel()[0]
26     pos = region.begin()
27     point_diagnostics = get_point_diagnostics(view, pos)
28     params = {
29         "textDocument": {
30             "uri": filename_to_uri(view.file_name())
31         },
32         "range": region_to_range(view, region).to_lsp(),
33         "context": {
34             "diagnostics": list(diagnostic.to_lsp() for diagnostic in point_diagnostics)
35         }
36     }
37     session.client.send_request(
38         Request.codeAction(params),
39         lambda response: on_response_recieved(response))
40 
41 
42 class LspCodeActionBulbListener(sublime_plugin.ViewEventListener):
43     def __init__(self, view: sublime.View) -> None:
44         super().__init__(view)
45         self._stored_point = -1
46 
47     @classmethod
48     def is_applicable(cls, _settings):
49         if settings.show_code_actions_bulb:
50             return True
51         return False
52 
53     def on_selection_modified_async(self):
54         self.hide_bulb()
55         self.schedule_request()
56 
57     def schedule_request(self):
58         current_point = self.view.sel()[0].begin()
59         if self._stored_point != current_point:
60             self._stored_point = current_point
61             sublime.set_timeout_async(lambda: self.fire_request(current_point), 800)
62 
63     def fire_request(self, current_point: int) -> None:
64         if current_point == self._stored_point:
65             send_code_action_request(self.view, self.handle_response)
66 
67     def handle_response(self, response) -> None:
68         if settings.show_code_actions_bulb:
69             if len(response) > 0:
70                 self.show_bulb()
71             else:
72                 self.hide_bulb()
73 
74     def show_bulb(self) -> None:
75         region = self.view.sel()[0]
76         flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE
77         self.view.add_regions('lsp_bulb', [region], 'markup.changed', 'Packages/LSP/icons/lightbulb.png', flags)
78 
79     def hide_bulb(self) -> None:
80         self.view.erase_regions('lsp_bulb')
81 
82 
83 class LspCodeActionsCommand(LspTextCommand):
84     def is_enabled(self):
85         return self.has_client_with_capability('codeActionProvider')
86 
87     def run(self, edit):
88         self.commands = []  # type: List[Dict]
89 
90         send_code_action_request(self.view, self.handle_response)
91 
92     def get_titles(self):
93         ''' Return a list of all command titles. '''
94         titles = []
95         for command in self.commands:
96             titles.append(command.get('title'))  # TODO parse command and arguments
97         return titles
98 
99     def handle_response(self, response: 'Optional[List[Dict]]') -> None:
100         self.commands = response or []
101         self.show_popup_menu()
102 
103     def show_popup_menu(self) -> None:
104         if len(self.commands) > 0:
105             self.view.show_popup_menu(self.get_titles(), self.handle_select)
106         else:
107             self.view.show_popup('No actions available', sublime.HIDE_ON_MOUSE_MOVE_AWAY)
108 
109     def handle_select(self, index: int) -> None:
110         if index > -1:
111             client = client_for_view(self.view)
112             if client:
113                 client.send_request(
114                     Request.executeCommand(self.commands[index]),
115                     self.handle_command_response)
116 
117     def handle_command_response(self, response):
118         pass
119
```

Path: `plugin/execute_command.py`
Content:
```
1 import sublime
2 from .core.registry import client_for_view, LspTextCommand
3 from .core.protocol import Request
4 from .core.rpc import Client
5 
6 try:
7     from typing import List, Optional, Dict, Any, Tuple
8     assert List and Optional and Dict and Any, Tuple
9 except ImportError:
10     pass
11 
12 
13 class LspExecuteCommand(LspTextCommand):
14     def __init__(self, view):
15         super().__init__(view)
16 
17     def run(self, edit, command_name=None, command_args=None) -> None:
18         client = client_for_view(self.view)
19         if client and command_name:
20             self.view.window().status_message("Running command {}".format(command_name))
21             self._send_command(client, command_name, command_args)
22 
23     def _handle_response(self, command: str, response: 'Optional[Any]') -> None:
24         msg = "command {} completed".format(command)
25         if response:
26             msg += "with response: {}".format(response)
27         sublime.message_dialog(msg)
28 
29     def _handle_error(self, command: str, error: 'Dict[str, Any]') -> None:
30         msg = "command {} failed. Reason: {}".format(command, error.get("message", "none provided by server :("))
31         sublime.message_dialog(msg)
32 
33     def _send_command(self, client: Client, command_name: str, command_args: 'Dict[str, Any]') -> None:
34         request = {
35             "command": command_name,
36             "arguments": command_args
37         }
38         client.send_request(Request.executeCommand(request),
39                             lambda reponse: self._handle_response(command_name, reponse),
40                             lambda error: self._handle_error(command_name, error))
41
```
--- 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/code_actions.py b/plugin/code_actions.py
--- a/plugin/code_actions.py
+++ b/plugin/code_actions.py
@@ -10,6 +10,7 @@
 from .core.registry import client_for_view, LspTextCommand
 from .core.protocol import Request
 from .diagnostics import get_point_diagnostics
+from .core.edit import parse_workspace_edit
 from .core.url import filename_to_uri
 from .core.views import region_to_range
 from .core.registry import session_for_view
@@ -80,6 +81,11 @@
         self.view.erase_regions('lsp_bulb')
 
 
+def is_command(command_or_code_action: dict) -> bool:
+    command_field = command_or_code_action.get('command')
+    return isinstance(command_field, str)
+
+
 class LspCodeActionsCommand(LspTextCommand):
     def is_enabled(self):
         return self.has_client_with_capability('codeActionProvider')
@@ -108,11 +114,26 @@
 
     def handle_select(self, index: int) -> None:
         if index > -1:
-            client = client_for_view(self.view)
-            if client:
-                client.send_request(
-                    Request.executeCommand(self.commands[index]),
-                    self.handle_command_response)
+
+            selected = self.commands[index]
+            if is_command(selected):
+                self.run_command(selected)
+            else:
+                # CodeAction can have an edit and/or command.
+                maybe_edit = selected.get('edit')
+                if maybe_edit:
+                    changes = parse_workspace_edit(maybe_edit)
+                    self.view.window().run_command("lsp_apply_workspace_edit", {'changes': changes})
+                maybe_command = selected.get('command')
+                if maybe_command:
+                    self.run_command(maybe_command)
+
+    def run_command(self, command) -> None:
+        client = client_for_view(self.view)
+        if client:
+            client.send_request(
+                Request.executeCommand(command),
+                self.handle_command_response)
 
     def handle_command_response(self, response):
         pass
diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py
--- a/plugin/core/sessions.py
+++ b/plugin/core/sessions.py
@@ -135,12 +135,15 @@
                 "formatting": {},
                 "rangeFormatting": {},
                 "definition": {},
-                "codeAction": {},
+                "codeAction": {
+                    "codeActionLiteralSupport": {}
+                },
                 "rename": {}
             },
             "workspace": {
                 "applyEdit": True,
-                "didChangeConfiguration": {}
+                "didChangeConfiguration": {},
+                "executeCommand": {},
             }
         }
     }
diff --git a/plugin/execute_command.py b/plugin/execute_command.py
--- a/plugin/execute_command.py
+++ b/plugin/execute_command.py
@@ -24,13 +24,14 @@
         msg = "command {} completed".format(command)
         if response:
             msg += "with response: {}".format(response)
+
         sublime.message_dialog(msg)
 
     def _handle_error(self, command: str, error: 'Dict[str, Any]') -> None:
         msg = "command {} failed. Reason: {}".format(command, error.get("message", "none provided by server :("))
         sublime.message_dialog(msg)
 
-    def _send_command(self, client: Client, command_name: str, command_args: 'Dict[str, Any]') -> None:
+    def _send_command(self, client: Client, command_name: str, command_args: 'Optional[List[Any]]') -> None:
         request = {
             "command": command_name,
             "arguments": command_args

{"golden_diff": "diff --git a/plugin/code_actions.py b/plugin/code_actions.py\n--- a/plugin/code_actions.py\n+++ b/plugin/code_actions.py\n@@ -10,6 +10,7 @@\n from .core.registry import client_for_view, LspTextCommand\n from .core.protocol import Request\n from .diagnostics import get_point_diagnostics\n+from .core.edit import parse_workspace_edit\n from .core.url import filename_to_uri\n from .core.views import region_to_range\n from .core.registry import session_for_view\n@@ -80,6 +81,11 @@\n         self.view.erase_regions('lsp_bulb')\n \n \n+def is_command(command_or_code_action: dict) -> bool:\n+    command_field = command_or_code_action.get('command')\n+    return isinstance(command_field, str)\n+\n+\n class LspCodeActionsCommand(LspTextCommand):\n     def is_enabled(self):\n         return self.has_client_with_capability('codeActionProvider')\n@@ -108,11 +114,26 @@\n \n     def handle_select(self, index: int) -> None:\n         if index > -1:\n-            client = client_for_view(self.view)\n-            if client:\n-                client.send_request(\n-                    Request.executeCommand(self.commands[index]),\n-                    self.handle_command_response)\n+\n+            selected = self.commands[index]\n+            if is_command(selected):\n+                self.run_command(selected)\n+            else:\n+                # CodeAction can have an edit and/or command.\n+                maybe_edit = selected.get('edit')\n+                if maybe_edit:\n+                    changes = parse_workspace_edit(maybe_edit)\n+                    self.view.window().run_command(\"lsp_apply_workspace_edit\", {'changes': changes})\n+                maybe_command = selected.get('command')\n+                if maybe_command:\n+                    self.run_command(maybe_command)\n+\n+    def run_command(self, command) -> None:\n+        client = client_for_view(self.view)\n+        if client:\n+            client.send_request(\n+                Request.executeCommand(command),\n+                self.handle_command_response)\n \n     def handle_command_response(self, response):\n         pass\ndiff --git a/plugin/core/sessions.py b/plugin/core/sessions.py\n--- a/plugin/core/sessions.py\n+++ b/plugin/core/sessions.py\n@@ -135,12 +135,15 @@\n                 \"formatting\": {},\n                 \"rangeFormatting\": {},\n                 \"definition\": {},\n-                \"codeAction\": {},\n+                \"codeAction\": {\n+                    \"codeActionLiteralSupport\": {}\n+                },\n                 \"rename\": {}\n             },\n             \"workspace\": {\n                 \"applyEdit\": True,\n-                \"didChangeConfiguration\": {}\n+                \"didChangeConfiguration\": {},\n+                \"executeCommand\": {},\n             }\n         }\n     }\ndiff --git a/plugin/execute_command.py b/plugin/execute_command.py\n--- a/plugin/execute_command.py\n+++ b/plugin/execute_command.py\n@@ -24,13 +24,14 @@\n         msg = \"command {} completed\".format(command)\n         if response:\n             msg += \"with response: {}\".format(response)\n+\n         sublime.message_dialog(msg)\n \n     def _handle_error(self, command: str, error: 'Dict[str, Any]') -> None:\n         msg = \"command {} failed. Reason: {}\".format(command, error.get(\"message\", \"none provided by server :(\"))\n         sublime.message_dialog(msg)\n \n-    def _send_command(self, client: Client, command_name: str, command_args: 'Dict[str, Any]') -> None:\n+    def _send_command(self, client: Client, command_name: str, command_args: 'Optional[List[Any]]') -> None:\n         request = {\n             \"command\": command_name,\n             \"arguments\": command_args\n", "issue": "Code actions of CodeActionLiteral type are not supported (used by eslint-server)\nWhile experimenting with [eslint-server](https://github.com/Microsoft/vscode-eslint/tree/master/server), I've noticed that its code actions for fixing lint issues are not handled properly.\r\n\r\nI found two issues:\r\n - handling CodeActions action list as an array of `Command` while protocol also allows array of `CodeAction`.\r\n - Passing `args` param to `workspace/executeCommand` instead of expected `arguments` param.\n", "before_files": [{"content": "from .types import ClientConfig, ClientStates, Settings\nfrom .protocol import Request\nfrom .transports import start_tcp_transport\nfrom .rpc import Client, attach_stdio_client\nfrom .process import start_server\nfrom .url import filename_to_uri\nfrom .logging import debug\nimport os\nfrom .protocol import CompletionItemKind, SymbolKind\ntry:\n    from typing import Callable, Dict, Any, Optional\n    assert Callable and Dict and Any and Optional\nexcept ImportError:\n    pass\n\n\ndef create_session(config: ClientConfig, project_path: str, env: dict, settings: Settings,\n                   on_created=None, on_ended: 'Optional[Callable[[str], None]]' = None,\n                   bootstrap_client=None) -> 'Optional[Session]':\n    session = None\n    if config.binary_args:\n\n        process = start_server(config.binary_args, project_path, env, settings.log_stderr)\n        if process:\n            if config.tcp_port:\n                transport = start_tcp_transport(config.tcp_port, config.tcp_host)\n                if transport:\n                    session = Session(config, project_path, Client(transport, settings), on_created, on_ended)\n                else:\n                    # try to terminate the process\n                    try:\n                        process.terminate()\n                    except Exception:\n                        pass\n            else:\n                client = attach_stdio_client(process, settings)\n                session = Session(config, project_path, client, on_created, on_ended)\n    else:\n        if config.tcp_port:\n            transport = start_tcp_transport(config.tcp_port)\n\n            session = Session(config, project_path, Client(transport, settings),\n                              on_created, on_ended)\n        elif bootstrap_client:\n            session = Session(config, project_path, bootstrap_client,\n                              on_created, on_ended)\n        else:\n            debug(\"No way to start session\")\n\n    return session\n\n\ndef get_initialize_params(project_path: str, config: ClientConfig):\n    initializeParams = {\n        \"processId\": os.getpid(),\n        \"rootUri\": filename_to_uri(project_path),\n        \"rootPath\": project_path,\n        \"capabilities\": {\n            \"textDocument\": {\n                \"synchronization\": {\n                    \"didSave\": True\n                },\n                \"hover\": {\n                    \"contentFormat\": [\"markdown\", \"plaintext\"]\n                },\n                \"completion\": {\n                    \"completionItem\": {\n                        \"snippetSupport\": True\n                    },\n                    \"completionItemKind\": {\n                        \"valueSet\": [\n                            CompletionItemKind.Text,\n                            CompletionItemKind.Method,\n                            CompletionItemKind.Function,\n                            CompletionItemKind.Constructor,\n                            CompletionItemKind.Field,\n                            CompletionItemKind.Variable,\n                            CompletionItemKind.Class,\n                            CompletionItemKind.Interface,\n                            CompletionItemKind.Module,\n                            CompletionItemKind.Property,\n                            CompletionItemKind.Unit,\n                            CompletionItemKind.Value,\n                            CompletionItemKind.Enum,\n                            CompletionItemKind.Keyword,\n                            CompletionItemKind.Snippet,\n                            CompletionItemKind.Color,\n                            CompletionItemKind.File,\n                            CompletionItemKind.Reference\n                        ]\n                    }\n                },\n                \"signatureHelp\": {\n                    \"signatureInformation\": {\n                        \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                        \"parameterInformation\": {\n                            \"labelOffsetSupport\": True\n                        }\n                    }\n                },\n                \"references\": {},\n                \"documentHighlight\": {},\n                \"documentSymbol\": {\n                    \"symbolKind\": {\n                        \"valueSet\": [\n                            SymbolKind.File,\n                            SymbolKind.Module,\n                            SymbolKind.Namespace,\n                            SymbolKind.Package,\n                            SymbolKind.Class,\n                            SymbolKind.Method,\n                            SymbolKind.Property,\n                            SymbolKind.Field,\n                            SymbolKind.Constructor,\n                            SymbolKind.Enum,\n                            SymbolKind.Interface,\n                            SymbolKind.Function,\n                            SymbolKind.Variable,\n                            SymbolKind.Constant,\n                            SymbolKind.String,\n                            SymbolKind.Number,\n                            SymbolKind.Boolean,\n                            SymbolKind.Array,\n                            SymbolKind.Object,\n                            SymbolKind.Key,\n                            SymbolKind.Null,\n                            SymbolKind.EnumMember,\n                            SymbolKind.Struct,\n                            SymbolKind.Event,\n                            SymbolKind.Operator,\n                            SymbolKind.TypeParameter\n                        ]\n                    }\n                },\n                \"formatting\": {},\n                \"rangeFormatting\": {},\n                \"definition\": {},\n                \"codeAction\": {},\n                \"rename\": {}\n            },\n            \"workspace\": {\n                \"applyEdit\": True,\n                \"didChangeConfiguration\": {}\n            }\n        }\n    }\n    if config.init_options:\n        initializeParams['initializationOptions'] = config.init_options\n\n    return initializeParams\n\n\nclass Session(object):\n    def __init__(self, config: ClientConfig, project_path, client: Client,\n                 on_created=None, on_ended: 'Optional[Callable[[str], None]]' = None) -> None:\n        self.config = config\n        self.project_path = project_path\n        self.state = ClientStates.STARTING\n        self._on_created = on_created\n        self._on_ended = on_ended\n        self.capabilities = dict()  # type: Dict[str, Any]\n        self.client = client\n        self.initialize()\n\n    def has_capability(self, capability):\n        return capability in self.capabilities and self.capabilities[capability] is not False\n\n    def get_capability(self, capability):\n        return self.capabilities.get(capability)\n\n    def initialize(self):\n        params = get_initialize_params(self.project_path, self.config)\n        self.client.send_request(\n            Request.initialize(params),\n            lambda result: self._handle_initialize_result(result))\n\n    def _handle_initialize_result(self, result):\n        self.state = ClientStates.READY\n        self.capabilities = result.get('capabilities', dict())\n        if self._on_created:\n            self._on_created(self)\n\n    def end(self):\n        self.state = ClientStates.STOPPING\n        self.client.send_request(\n            Request.shutdown(),\n            lambda result: self._handle_shutdown_result(),\n            lambda: self._handle_shutdown_result())\n\n    def _handle_shutdown_result(self):\n        self.client.exit()\n        self.client = None\n        self.capabilities = dict()\n        if self._on_ended:\n            self._on_ended(self.config.name)\n", "path": "plugin/core/sessions.py"}, {"content": "import sublime_plugin\nimport sublime\n\ntry:\n    from typing import Any, List, Dict, Callable, Optional\n    assert Any and List and Dict and Callable and Optional\nexcept ImportError:\n    pass\n\nfrom .core.registry import client_for_view, LspTextCommand\nfrom .core.protocol import Request\nfrom .diagnostics import get_point_diagnostics\nfrom .core.url import filename_to_uri\nfrom .core.views import region_to_range\nfrom .core.registry import session_for_view\nfrom .core.settings import settings\n\n\ndef send_code_action_request(view, on_response_recieved: 'Callable'):\n    session = session_for_view(view)\n    if not session or not session.has_capability('codeActionProvider'):\n        # the server doesn't support code actions, just return\n        return\n\n    region = view.sel()[0]\n    pos = region.begin()\n    point_diagnostics = get_point_diagnostics(view, pos)\n    params = {\n        \"textDocument\": {\n            \"uri\": filename_to_uri(view.file_name())\n        },\n        \"range\": region_to_range(view, region).to_lsp(),\n        \"context\": {\n            \"diagnostics\": list(diagnostic.to_lsp() for diagnostic in point_diagnostics)\n        }\n    }\n    session.client.send_request(\n        Request.codeAction(params),\n        lambda response: on_response_recieved(response))\n\n\nclass LspCodeActionBulbListener(sublime_plugin.ViewEventListener):\n    def __init__(self, view: sublime.View) -> None:\n        super().__init__(view)\n        self._stored_point = -1\n\n    @classmethod\n    def is_applicable(cls, _settings):\n        if settings.show_code_actions_bulb:\n            return True\n        return False\n\n    def on_selection_modified_async(self):\n        self.hide_bulb()\n        self.schedule_request()\n\n    def schedule_request(self):\n        current_point = self.view.sel()[0].begin()\n        if self._stored_point != current_point:\n            self._stored_point = current_point\n            sublime.set_timeout_async(lambda: self.fire_request(current_point), 800)\n\n    def fire_request(self, current_point: int) -> None:\n        if current_point == self._stored_point:\n            send_code_action_request(self.view, self.handle_response)\n\n    def handle_response(self, response) -> None:\n        if settings.show_code_actions_bulb:\n            if len(response) > 0:\n                self.show_bulb()\n            else:\n                self.hide_bulb()\n\n    def show_bulb(self) -> None:\n        region = self.view.sel()[0]\n        flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE\n        self.view.add_regions('lsp_bulb', [region], 'markup.changed', 'Packages/LSP/icons/lightbulb.png', flags)\n\n    def hide_bulb(self) -> None:\n        self.view.erase_regions('lsp_bulb')\n\n\nclass LspCodeActionsCommand(LspTextCommand):\n    def is_enabled(self):\n        return self.has_client_with_capability('codeActionProvider')\n\n    def run(self, edit):\n        self.commands = []  # type: List[Dict]\n\n        send_code_action_request(self.view, self.handle_response)\n\n    def get_titles(self):\n        ''' Return a list of all command titles. '''\n        titles = []\n        for command in self.commands:\n            titles.append(command.get('title'))  # TODO parse command and arguments\n        return titles\n\n    def handle_response(self, response: 'Optional[List[Dict]]') -> None:\n        self.commands = response or []\n        self.show_popup_menu()\n\n    def show_popup_menu(self) -> None:\n        if len(self.commands) > 0:\n            self.view.show_popup_menu(self.get_titles(), self.handle_select)\n        else:\n            self.view.show_popup('No actions available', sublime.HIDE_ON_MOUSE_MOVE_AWAY)\n\n    def handle_select(self, index: int) -> None:\n        if index > -1:\n            client = client_for_view(self.view)\n            if client:\n                client.send_request(\n                    Request.executeCommand(self.commands[index]),\n                    self.handle_command_response)\n\n    def handle_command_response(self, response):\n        pass\n", "path": "plugin/code_actions.py"}, {"content": "import sublime\nfrom .core.registry import client_for_view, LspTextCommand\nfrom .core.protocol import Request\nfrom .core.rpc import Client\n\ntry:\n    from typing import List, Optional, Dict, Any, Tuple\n    assert List and Optional and Dict and Any, Tuple\nexcept ImportError:\n    pass\n\n\nclass LspExecuteCommand(LspTextCommand):\n    def __init__(self, view):\n        super().__init__(view)\n\n    def run(self, edit, command_name=None, command_args=None) -> None:\n        client = client_for_view(self.view)\n        if client and command_name:\n            self.view.window().status_message(\"Running command {}\".format(command_name))\n            self._send_command(client, command_name, command_args)\n\n    def _handle_response(self, command: str, response: 'Optional[Any]') -> None:\n        msg = \"command {} completed\".format(command)\n        if response:\n            msg += \"with response: {}\".format(response)\n        sublime.message_dialog(msg)\n\n    def _handle_error(self, command: str, error: 'Dict[str, Any]') -> None:\n        msg = \"command {} failed. Reason: {}\".format(command, error.get(\"message\", \"none provided by server :(\"))\n        sublime.message_dialog(msg)\n\n    def _send_command(self, client: Client, command_name: str, command_args: 'Dict[str, Any]') -> None:\n        request = {\n            \"command\": command_name,\n            \"arguments\": command_args\n        }\n        client.send_request(Request.executeCommand(request),\n                            lambda reponse: self._handle_response(command_name, reponse),\n                            lambda error: self._handle_error(command_name, error))\n", "path": "plugin/execute_command.py"}], "after_files": [{"content": "from .types import ClientConfig, ClientStates, Settings\nfrom .protocol import Request\nfrom .transports import start_tcp_transport\nfrom .rpc import Client, attach_stdio_client\nfrom .process import start_server\nfrom .url import filename_to_uri\nfrom .logging import debug\nimport os\nfrom .protocol import CompletionItemKind, SymbolKind\ntry:\n    from typing import Callable, Dict, Any, Optional\n    assert Callable and Dict and Any and Optional\nexcept ImportError:\n    pass\n\n\ndef create_session(config: ClientConfig, project_path: str, env: dict, settings: Settings,\n                   on_created=None, on_ended: 'Optional[Callable[[str], None]]' = None,\n                   bootstrap_client=None) -> 'Optional[Session]':\n    session = None\n    if config.binary_args:\n\n        process = start_server(config.binary_args, project_path, env, settings.log_stderr)\n        if process:\n            if config.tcp_port:\n                transport = start_tcp_transport(config.tcp_port, config.tcp_host)\n                if transport:\n                    session = Session(config, project_path, Client(transport, settings), on_created, on_ended)\n                else:\n                    # try to terminate the process\n                    try:\n                        process.terminate()\n                    except Exception:\n                        pass\n            else:\n                client = attach_stdio_client(process, settings)\n                session = Session(config, project_path, client, on_created, on_ended)\n    else:\n        if config.tcp_port:\n            transport = start_tcp_transport(config.tcp_port)\n\n            session = Session(config, project_path, Client(transport, settings),\n                              on_created, on_ended)\n        elif bootstrap_client:\n            session = Session(config, project_path, bootstrap_client,\n                              on_created, on_ended)\n        else:\n            debug(\"No way to start session\")\n\n    return session\n\n\ndef get_initialize_params(project_path: str, config: ClientConfig):\n    initializeParams = {\n        \"processId\": os.getpid(),\n        \"rootUri\": filename_to_uri(project_path),\n        \"rootPath\": project_path,\n        \"capabilities\": {\n            \"textDocument\": {\n                \"synchronization\": {\n                    \"didSave\": True\n                },\n                \"hover\": {\n                    \"contentFormat\": [\"markdown\", \"plaintext\"]\n                },\n                \"completion\": {\n                    \"completionItem\": {\n                        \"snippetSupport\": True\n                    },\n                    \"completionItemKind\": {\n                        \"valueSet\": [\n                            CompletionItemKind.Text,\n                            CompletionItemKind.Method,\n                            CompletionItemKind.Function,\n                            CompletionItemKind.Constructor,\n                            CompletionItemKind.Field,\n                            CompletionItemKind.Variable,\n                            CompletionItemKind.Class,\n                            CompletionItemKind.Interface,\n                            CompletionItemKind.Module,\n                            CompletionItemKind.Property,\n                            CompletionItemKind.Unit,\n                            CompletionItemKind.Value,\n                            CompletionItemKind.Enum,\n                            CompletionItemKind.Keyword,\n                            CompletionItemKind.Snippet,\n                            CompletionItemKind.Color,\n                            CompletionItemKind.File,\n                            CompletionItemKind.Reference\n                        ]\n                    }\n                },\n                \"signatureHelp\": {\n                    \"signatureInformation\": {\n                        \"documentationFormat\": [\"markdown\", \"plaintext\"],\n                        \"parameterInformation\": {\n                            \"labelOffsetSupport\": True\n                        }\n                    }\n                },\n                \"references\": {},\n                \"documentHighlight\": {},\n                \"documentSymbol\": {\n                    \"symbolKind\": {\n                        \"valueSet\": [\n                            SymbolKind.File,\n                            SymbolKind.Module,\n                            SymbolKind.Namespace,\n                            SymbolKind.Package,\n                            SymbolKind.Class,\n                            SymbolKind.Method,\n                            SymbolKind.Property,\n                            SymbolKind.Field,\n                            SymbolKind.Constructor,\n                            SymbolKind.Enum,\n                            SymbolKind.Interface,\n                            SymbolKind.Function,\n                            SymbolKind.Variable,\n                            SymbolKind.Constant,\n                            SymbolKind.String,\n                            SymbolKind.Number,\n                            SymbolKind.Boolean,\n                            SymbolKind.Array,\n                            SymbolKind.Object,\n                            SymbolKind.Key,\n                            SymbolKind.Null,\n                            SymbolKind.EnumMember,\n                            SymbolKind.Struct,\n                            SymbolKind.Event,\n                            SymbolKind.Operator,\n                            SymbolKind.TypeParameter\n                        ]\n                    }\n                },\n                \"formatting\": {},\n                \"rangeFormatting\": {},\n                \"definition\": {},\n                \"codeAction\": {\n                    \"codeActionLiteralSupport\": {}\n                },\n                \"rename\": {}\n            },\n            \"workspace\": {\n                \"applyEdit\": True,\n                \"didChangeConfiguration\": {},\n                \"executeCommand\": {},\n            }\n        }\n    }\n    if config.init_options:\n        initializeParams['initializationOptions'] = config.init_options\n\n    return initializeParams\n\n\nclass Session(object):\n    def __init__(self, config: ClientConfig, project_path, client: Client,\n                 on_created=None, on_ended: 'Optional[Callable[[str], None]]' = None) -> None:\n        self.config = config\n        self.project_path = project_path\n        self.state = ClientStates.STARTING\n        self._on_created = on_created\n        self._on_ended = on_ended\n        self.capabilities = dict()  # type: Dict[str, Any]\n        self.client = client\n        self.initialize()\n\n    def has_capability(self, capability):\n        return capability in self.capabilities and self.capabilities[capability] is not False\n\n    def get_capability(self, capability):\n        return self.capabilities.get(capability)\n\n    def initialize(self):\n        params = get_initialize_params(self.project_path, self.config)\n        self.client.send_request(\n            Request.initialize(params),\n            lambda result: self._handle_initialize_result(result))\n\n    def _handle_initialize_result(self, result):\n        self.state = ClientStates.READY\n        self.capabilities = result.get('capabilities', dict())\n        if self._on_created:\n            self._on_created(self)\n\n    def end(self):\n        self.state = ClientStates.STOPPING\n        self.client.send_request(\n            Request.shutdown(),\n            lambda result: self._handle_shutdown_result(),\n            lambda: self._handle_shutdown_result())\n\n    def _handle_shutdown_result(self):\n        self.client.exit()\n        self.client = None\n        self.capabilities = dict()\n        if self._on_ended:\n            self._on_ended(self.config.name)\n", "path": "plugin/core/sessions.py"}, {"content": "import sublime_plugin\nimport sublime\n\ntry:\n    from typing import Any, List, Dict, Callable, Optional\n    assert Any and List and Dict and Callable and Optional\nexcept ImportError:\n    pass\n\nfrom .core.registry import client_for_view, LspTextCommand\nfrom .core.protocol import Request\nfrom .diagnostics import get_point_diagnostics\nfrom .core.edit import parse_workspace_edit\nfrom .core.url import filename_to_uri\nfrom .core.views import region_to_range\nfrom .core.registry import session_for_view\nfrom .core.settings import settings\n\n\ndef send_code_action_request(view, on_response_recieved: 'Callable'):\n    session = session_for_view(view)\n    if not session or not session.has_capability('codeActionProvider'):\n        # the server doesn't support code actions, just return\n        return\n\n    region = view.sel()[0]\n    pos = region.begin()\n    point_diagnostics = get_point_diagnostics(view, pos)\n    params = {\n        \"textDocument\": {\n            \"uri\": filename_to_uri(view.file_name())\n        },\n        \"range\": region_to_range(view, region).to_lsp(),\n        \"context\": {\n            \"diagnostics\": list(diagnostic.to_lsp() for diagnostic in point_diagnostics)\n        }\n    }\n    session.client.send_request(\n        Request.codeAction(params),\n        lambda response: on_response_recieved(response))\n\n\nclass LspCodeActionBulbListener(sublime_plugin.ViewEventListener):\n    def __init__(self, view: sublime.View) -> None:\n        super().__init__(view)\n        self._stored_point = -1\n\n    @classmethod\n    def is_applicable(cls, _settings):\n        if settings.show_code_actions_bulb:\n            return True\n        return False\n\n    def on_selection_modified_async(self):\n        self.hide_bulb()\n        self.schedule_request()\n\n    def schedule_request(self):\n        current_point = self.view.sel()[0].begin()\n        if self._stored_point != current_point:\n            self._stored_point = current_point\n            sublime.set_timeout_async(lambda: self.fire_request(current_point), 800)\n\n    def fire_request(self, current_point: int) -> None:\n        if current_point == self._stored_point:\n            send_code_action_request(self.view, self.handle_response)\n\n    def handle_response(self, response) -> None:\n        if settings.show_code_actions_bulb:\n            if len(response) > 0:\n                self.show_bulb()\n            else:\n                self.hide_bulb()\n\n    def show_bulb(self) -> None:\n        region = self.view.sel()[0]\n        flags = sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE\n        self.view.add_regions('lsp_bulb', [region], 'markup.changed', 'Packages/LSP/icons/lightbulb.png', flags)\n\n    def hide_bulb(self) -> None:\n        self.view.erase_regions('lsp_bulb')\n\n\ndef is_command(command_or_code_action: dict) -> bool:\n    command_field = command_or_code_action.get('command')\n    return isinstance(command_field, str)\n\n\nclass LspCodeActionsCommand(LspTextCommand):\n    def is_enabled(self):\n        return self.has_client_with_capability('codeActionProvider')\n\n    def run(self, edit):\n        self.commands = []  # type: List[Dict]\n\n        send_code_action_request(self.view, self.handle_response)\n\n    def get_titles(self):\n        ''' Return a list of all command titles. '''\n        titles = []\n        for command in self.commands:\n            titles.append(command.get('title'))  # TODO parse command and arguments\n        return titles\n\n    def handle_response(self, response: 'Optional[List[Dict]]') -> None:\n        self.commands = response or []\n        self.show_popup_menu()\n\n    def show_popup_menu(self) -> None:\n        if len(self.commands) > 0:\n            self.view.show_popup_menu(self.get_titles(), self.handle_select)\n        else:\n            self.view.show_popup('No actions available', sublime.HIDE_ON_MOUSE_MOVE_AWAY)\n\n    def handle_select(self, index: int) -> None:\n        if index > -1:\n\n            selected = self.commands[index]\n            if is_command(selected):\n                self.run_command(selected)\n            else:\n                # CodeAction can have an edit and/or command.\n                maybe_edit = selected.get('edit')\n                if maybe_edit:\n                    changes = parse_workspace_edit(maybe_edit)\n                    self.view.window().run_command(\"lsp_apply_workspace_edit\", {'changes': changes})\n                maybe_command = selected.get('command')\n                if maybe_command:\n                    self.run_command(maybe_command)\n\n    def run_command(self, command) -> None:\n        client = client_for_view(self.view)\n        if client:\n            client.send_request(\n                Request.executeCommand(command),\n                self.handle_command_response)\n\n    def handle_command_response(self, response):\n        pass\n", "path": "plugin/code_actions.py"}, {"content": "import sublime\nfrom .core.registry import client_for_view, LspTextCommand\nfrom .core.protocol import Request\nfrom .core.rpc import Client\n\ntry:\n    from typing import List, Optional, Dict, Any, Tuple\n    assert List and Optional and Dict and Any, Tuple\nexcept ImportError:\n    pass\n\n\nclass LspExecuteCommand(LspTextCommand):\n    def __init__(self, view):\n        super().__init__(view)\n\n    def run(self, edit, command_name=None, command_args=None) -> None:\n        client = client_for_view(self.view)\n        if client and command_name:\n            self.view.window().status_message(\"Running command {}\".format(command_name))\n            self._send_command(client, command_name, command_args)\n\n    def _handle_response(self, command: str, response: 'Optional[Any]') -> None:\n        msg = \"command {} completed\".format(command)\n        if response:\n            msg += \"with response: {}\".format(response)\n\n        sublime.message_dialog(msg)\n\n    def _handle_error(self, command: str, error: 'Dict[str, Any]') -> None:\n        msg = \"command {} failed. Reason: {}\".format(command, error.get(\"message\", \"none provided by server :(\"))\n        sublime.message_dialog(msg)\n\n    def _send_command(self, client: Client, command_name: str, command_args: 'Optional[List[Any]]') -> None:\n        request = {\n            \"command\": command_name,\n            \"arguments\": command_args\n        }\n        client.send_request(Request.executeCommand(request),\n                            lambda reponse: self._handle_response(command_name, reponse),\n                            lambda error: self._handle_error(command_name, error))\n", "path": "plugin/execute_command.py"}]}