File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 29
29
--- }
30
30
--- ```
31
31
---
32
+ --- Source actions such as organizing imports and removing unused code are available via `:LspTypescriptSourceAction`.
33
+ ---
32
34
--- ### Vue support
33
35
---
34
36
--- As of 2.0.0, Volar no longer supports TypeScript itself. Instead, a plugin
@@ -93,4 +95,19 @@ return {
93
95
return vim .NIL
94
96
end ,
95
97
},
98
+ on_attach = function (client )
99
+ -- ts_ls provides code actions that have a prefix `source.` that apply to the whole file. These will only appear in
100
+ -- `vim.lsp.buf.code_action()` if specified in `context.only`.
101
+ vim .api .nvim_buf_create_user_command (0 , ' LspTypescriptSourceAction' , function ()
102
+ local source_actions = vim .tbl_filter (function (action )
103
+ return vim .startswith (action , ' source.' )
104
+ end , client .server_capabilities .codeActionProvider .codeActionKinds )
105
+
106
+ vim .lsp .buf .code_action ({
107
+ context = {
108
+ only = source_actions ,
109
+ },
110
+ })
111
+ end , {})
112
+ end ,
96
113
}
You can’t perform that action at this time.
0 commit comments