|
1 |
| -if vim.fn.exists "g:disable_typescript_tools" == 1 then |
2 |
| - return |
3 |
| -end |
4 |
| -if vim.fn.exists "b:did_typescript_tools_ftplugin" == 1 then |
5 |
| - return |
6 |
| -end |
7 |
| -vim.b.did_typescript_tools_ftplugin = true |
| 1 | +local M = {} |
8 | 2 |
|
9 |
| ----@param name string |
10 |
| ----@param fn function |
11 |
| -local function create_command(name, fn) |
12 |
| - local command_completion = { |
13 |
| - nargs = "?", |
14 |
| - complete = function() |
15 |
| - return { "sync" } |
16 |
| - end, |
17 |
| - } |
18 |
| - vim.api.nvim_buf_create_user_command(0, name, function(cmd) |
19 |
| - local words = cmd.fargs |
| 3 | +M.initialize = function() |
| 4 | + if vim.fn.exists "g:disable_typescript_tools" == 1 then |
| 5 | + return |
| 6 | + end |
| 7 | + if vim.fn.exists "b:did_typescript_tools_ftplugin" == 1 then |
| 8 | + return |
| 9 | + end |
| 10 | + vim.b.did_typescript_tools_ftplugin = true |
20 | 11 |
|
21 |
| - if #words == 1 and words[1] ~= "sync" then |
22 |
| - vim.notify("No such command", vim.log.levels.ERROR) |
23 |
| - return |
24 |
| - end |
| 12 | + ---@param name string |
| 13 | + ---@param fn function |
| 14 | + local function create_command(name, fn) |
| 15 | + local command_completion = { |
| 16 | + nargs = "?", |
| 17 | + complete = function() |
| 18 | + return { "sync" } |
| 19 | + end, |
| 20 | + } |
| 21 | + vim.api.nvim_buf_create_user_command(0, name, function(cmd) |
| 22 | + local words = cmd.fargs |
25 | 23 |
|
26 |
| - fn(#words == 1) |
27 |
| - end, command_completion) |
28 |
| -end |
| 24 | + if #words == 1 and words[1] ~= "sync" then |
| 25 | + vim.notify("No such command", vim.log.levels.ERROR) |
| 26 | + return |
| 27 | + end |
29 | 28 |
|
30 |
| -create_command("TSToolsOrganizeImports", function(is_sync) |
31 |
| - require("typescript-tools.api").organize_imports(is_sync) |
32 |
| -end) |
| 29 | + fn(#words == 1) |
| 30 | + end, command_completion) |
| 31 | + end |
33 | 32 |
|
34 |
| -create_command("TSToolsSortImports", function(is_sync) |
35 |
| - require("typescript-tools.api").sort_imports(is_sync) |
36 |
| -end) |
| 33 | + create_command("TSToolsOrganizeImports", function(is_sync) |
| 34 | + require("typescript-tools.api").organize_imports(is_sync) |
| 35 | + end) |
37 | 36 |
|
38 |
| -create_command("TSToolsRemoveUnusedImports", function(is_sync) |
39 |
| - require("typescript-tools.api").remove_unused_imports(is_sync) |
40 |
| -end) |
| 37 | + create_command("TSToolsSortImports", function(is_sync) |
| 38 | + require("typescript-tools.api").sort_imports(is_sync) |
| 39 | + end) |
41 | 40 |
|
42 |
| -create_command("TSToolsGoToSourceDefinition", function(is_sync) |
43 |
| - require("typescript-tools.api").go_to_source_definition(is_sync) |
44 |
| -end) |
| 41 | + create_command("TSToolsRemoveUnusedImports", function(is_sync) |
| 42 | + require("typescript-tools.api").remove_unused_imports(is_sync) |
| 43 | + end) |
45 | 44 |
|
46 |
| -create_command("TSToolsRemoveUnused", function(is_sync) |
47 |
| - require("typescript-tools.api").remove_unused(is_sync) |
48 |
| -end) |
| 45 | + create_command("TSToolsGoToSourceDefinition", function(is_sync) |
| 46 | + require("typescript-tools.api").go_to_source_definition(is_sync) |
| 47 | + end) |
49 | 48 |
|
50 |
| -create_command("TSToolsAddMissingImports", function(is_sync) |
51 |
| - require("typescript-tools.api").add_missing_imports(is_sync) |
52 |
| -end) |
| 49 | + create_command("TSToolsRemoveUnused", function(is_sync) |
| 50 | + require("typescript-tools.api").remove_unused(is_sync) |
| 51 | + end) |
53 | 52 |
|
54 |
| -create_command("TSToolsFixAll", function(is_sync) |
55 |
| - require("typescript-tools.api").fix_all(is_sync) |
56 |
| -end) |
| 53 | + create_command("TSToolsAddMissingImports", function(is_sync) |
| 54 | + require("typescript-tools.api").add_missing_imports(is_sync) |
| 55 | + end) |
57 | 56 |
|
58 |
| -create_command("TSToolsRenameFile", function(is_sync) |
59 |
| - require("typescript-tools.api").rename_file(is_sync) |
60 |
| -end) |
| 57 | + create_command("TSToolsFixAll", function(is_sync) |
| 58 | + require("typescript-tools.api").fix_all(is_sync) |
| 59 | + end) |
| 60 | + |
| 61 | + create_command("TSToolsRenameFile", function(is_sync) |
| 62 | + require("typescript-tools.api").rename_file(is_sync) |
| 63 | + end) |
| 64 | + |
| 65 | + create_command("TSToolsFileReferences", function(is_sync) |
| 66 | + require("typescript-tools.api").file_references(is_sync) |
| 67 | + end) |
| 68 | +end |
61 | 69 |
|
62 |
| -create_command("TSToolsFileReferences", function(is_sync) |
63 |
| - require("typescript-tools.api").file_references(is_sync) |
64 |
| -end) |
| 70 | +return M |
0 commit comments