Skip to content

Commit

Permalink
📝 Feat: Add fold to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Nguyen-Hoang-Nam committed Aug 5, 2022
1 parent 55b0028 commit 5a4ac98
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 16 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,6 @@ You can check test tools [here](https://github.com/vim-test/vim-test)
- [ ] Support [template.nvim](https://github.com/glepnir/template.nvim)
- [x] Support [nvim-notify](https://github.com/rcarriga/nvim-notify)
- [ ] Support [Graphql](https://github.com/graphql/graphiql/tree/main/packages/graphql-language-service-cli)
- [x] Support [vscode-codicons](https://github.com/microsoft/vscode-codicons)

## Contributing

Expand Down
3 changes: 1 addition & 2 deletions lua/dashboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ function M.instance()
bufnr = api.nvim_get_current_buf()
end

local window = api.nvim_get_current_win()
api.nvim_win_set_buf(window, bufnr)
api.nvim_win_set_buf(api.nvim_get_current_win(), bufnr)

opt_local.wrap = false
opt_local.signcolumn = "no"
Expand Down
1 change: 1 addition & 0 deletions lua/setup/telescope/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ telescope.setup({
telescope.load_extension("fzf") -- Better fuzzy search result
telescope.load_extension("ui-select") -- Use for lsp action
telescope.load_extension("aerial")
telescope.load_extension("template")
28 changes: 28 additions & 0 deletions lua/telescope/_extensions/template.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- Credit https://github.com/glepnir/template.nvim/blob/main/lua/telescope/_extensions/find_template.lua
local telescope = require("telescope")
local finders = require("telescope.finders")
local pickers = require("telescope.pickers")
local make_entry = require("telescope.make_entry")
local conf = require("telescope.config").values

local temp_list = function()
return require("utils.templates").get_all_templates()
end

local find_template = function(opts)
opts = opts or {}
local results = temp_list()

pickers.new(opts, {
prompt_title = "templates",
results_title = "templates",
finder = finders.new_table({
results = results,
entry_maker = make_entry.gen_from_file(opts),
}),
previewer = conf.file_previewer(opts),
sorter = conf.file_sorter(opts),
}):find()
end

return telescope.register_extension({ exports = { find_template = find_template } })
11 changes: 11 additions & 0 deletions lua/templates/java/class.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local M = {}

M.template = [[
package {{_java_package_name_}};
public class {{_java_name}} {
{{_cursor_}}
}]]

return M
11 changes: 11 additions & 0 deletions lua/templates/java/enum.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local M = {}

M.template = [[
package {{_java_package_name_}};
public enum {{_java_name}} {
{{_cursor_}}
}]]

return M
11 changes: 11 additions & 0 deletions lua/templates/java/interface.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
local M = {}

M.template = [[
package {{_java_package_name_}};
public interface {{_java_name}} {
{{_cursor_}}
}]]

return M
15 changes: 15 additions & 0 deletions lua/templates/java/mongo_repository.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
local M = {}

M.template = [[
package {{_java_package_name_}};
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;
import org.springframework.stereotype.Repository;
public interface {{_java_name}} extends MongoRepository<{{_cursor_}}, String> {
}]]

return M
30 changes: 17 additions & 13 deletions lua/utils/templates.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
local M = {}

function M.file_supported(file_extension)
return file_extension == 'java' or file_extension == 'md'
return file_extension == "java" or file_extension == "md"
end

local function remove_extension(filename, file_extension)
local function java_name(filename, file_extension)
return string.sub(filename, 1, #filename - #file_extension - 1)
end

Expand All @@ -18,12 +18,12 @@ local function slice(tbl, s, e)
return new_tbl
end

local function java_group(path, filename)
local function java_package_name(path, filename)
local t = {}
local find_java = false
local position = 0
for str in string.gmatch(path, '([^/]+)') do
if str == 'java' then
for str in string.gmatch(path, "([^/]+)") do
if str == "java" then
find_java = true
position = #t + 1
end
Expand All @@ -35,24 +35,28 @@ local function java_group(path, filename)

if find_java then
local new_tbl = slice(t, position + 1, #t)
return table.concat(new_tbl, '.')
return table.concat(new_tbl, ".")
end

return t[#t]
end

function M.generate(file_extension, filename, path, file_type)
if file_extension == 'md' and filename == 'README.md' then
return require('languages.markdown').template[file_type]
elseif file_extension == 'java' then
local template = require('languages.java').template[file_type]
local name = remove_extension(filename, file_extension)
local group = java_group(path, filename)
if file_extension == "md" and filename == "README.md" then
return require("languages.markdown").template[file_type]
elseif file_extension == "java" then
local template = require("languages.java").template[file_type]
local name = java_name(filename, file_extension)
local group = java_package_name(path, filename)

return string.format(template, group, name)
else
return ''
return ""
end
end

function M.get_all_templates()
return {}
end

return M

0 comments on commit 5a4ac98

Please sign in to comment.