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