Skip to content

Commit

Permalink
feat(user_commands):commands functional
Browse files Browse the repository at this point in the history
  • Loading branch information
redoxahmii committed Jun 15, 2024
1 parent a9b74a7 commit 50dece3
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lua/json-to-types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ M.setup = function(args)
end

M.convertTypes = function(type)
return module.write_types(type)
if type then
return module.write_types(type)
end
end
M.convertTypesBuffer = function(type)
return module.write_types_buffer(type)
if type then
return module.write_types_buffer(type)
end
end

return M
1 change: 0 additions & 1 deletion lua/json-to-types/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ end

M.types_output_buffer = function(file_name, target_language)
local types_output_file, filetype = utils.executeTypesCommand(file_name, target_language)
vim.notify(filetype)
local file = io.open(types_output_file, "r")
if file then
local types = file:read("*a")
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "json-to-types.nvim",
"version": "1.0.0",
"description": "A plugin to convert JSON objects to typescript types",
"description": "A plugin to convert JSON objects to types",
"main": "index.js",
"type": "module",
"directories": {
Expand Down
101 changes: 98 additions & 3 deletions plugin/json-to-types.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,99 @@
vim.api.nvim_create_user_command("ConvertJSONtoTS", require("json-to-types").convertTypes("javascript"), {})
vim.api.nvim_create_user_command("ConvertJSONtoTSBuffer", require("json-to-types").convertTypesBuffer, {})
local json_to_types = require("json-to-types")
-- BUG: debug the error being thrown
vim.api.nvim_create_user_command("ConvertJSONtoLang", function(args)
if args.args == "" then
vim.notify("Please provide a language name", vim.log.levels.ERROR)
return
end
if not json_to_types.convertTypes then
vim.notify("convertTypes function not found", vim.log.levels.ERROR)
return
end
json_to_types.convertTypes(args.args)
end, {
nargs = 1,
complete = function()
return {
"cjson",
"c++",
"cr",
"cs",
"dart",
"elixir",
"elm",
"flow",
"go",
"haskell",
"java",
"js",
"javascript-prop-types",
"kotlin",
"objc",
"php",
"pike",
"py",
"rs",
"scala3",
"Smithy",
"swift",
"typescript",
"typescript-zod",
"typescript-effect-schema",
"javascript",
"cpp",
"csharp",
"rust",
"python",
"ruby",
}
end,
})

-- INFO: This autocmd creates a keymap for the json filetype.
vim.api.nvim_create_user_command("ConvertJSONtoLangBuffer", function(args)
if args.args == "" then
vim.notify("Please provide a language name", vim.log.levels.ERROR)
return
end
if not json_to_types.convertTypesBuffer then
vim.notify("convertTypesBuffer function not found", vim.log.levels.ERROR)
return
end
json_to_types.convertTypesBuffer(args.args)
end, {
nargs = 1,
complete = function()
return {
"cjson",
"c++",
"cr",
"cs",
"dart",
"elixir",
"elm",
"flow",
"go",
"haskell",
"java",
"js",
"javascript-prop-types",
"kotlin",
"objc",
"php",
"pike",
"py",
"rs",
"scala3",
"Smithy",
"swift",
"typescript",
"typescript-zod",
"typescript-effect-schema",
"javascript",
"cpp",
"csharp",
"rust",
"python",
"ruby",
}
end,
})

0 comments on commit 50dece3

Please sign in to comment.