Skip to content

Commit

Permalink
add base of definition module
Browse files Browse the repository at this point in the history
  • Loading branch information
jinzhongjia committed Aug 12, 2023
1 parent 68aa666 commit 585dcbf
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lua/LspUI/_meta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
--- @field command_enable boolean? whether enable command for `hover`
--- @field key_binding { prev: string?, next: string?, quit: string? }? keybind for `hover`

--- @class LspUI_definition_config
--- @field enable boolean? whether enable `definition` module
--- @field command_enable boolean? whether enable command for `definition`

--- @class LspUI_config config for LspUI
--- @field rename LspUI_rename_config? `rename` module
--- @field lightbulb LspUI_lightbulb_config? `lightbulb` module
--- @field code_action LspUI_code_action_config? `code_action` module
--- @field diagnostic LspUI_diagnostic_config? `diagnostic` module
--- @field hover LspUI_hover_config? `hover` module
--- @field definition LspUI_definition_config? `definition` module
1 change: 1 addition & 0 deletions lua/LspUI/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ M.api = {
rename = modules.code_action.run,
diagnostic = modules.diagnostic.run,
hover = modules.hover.run,
definition = modules.definition.run,
}

return M
7 changes: 7 additions & 0 deletions lua/LspUI/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ local default_hover_config = {
},
}

--- @type LspUI_definition_config
local default_definition_config = {
enable = true,
command_enable = true,
}

-- default config
--- @type LspUI_config
local default_config = {
Expand All @@ -57,6 +63,7 @@ local default_config = {
code_action = default_code_action_config,
diagnostic = default_diagnostic_config,
hover = default_hover_config,
definition = default_definition_config,
}

-- Prevent plugins from being initialized multiple times
Expand Down
31 changes: 31 additions & 0 deletions lua/LspUI/definition/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
local config = require("LspUI.config")
local command = require("LspUI.command")
local lib_notify = require("LspUI.lib.notify")
local M = {}
-- whether this module is initialized
local is_initialized = false

M.init = function()
if not config.options.definition.enable then
return
end

if is_initialized then
return
end

is_initialized = true

if config.options.definition.command_enable then
command.register_command("definition", M.run, {})
end
end

M.run = function()
if not config.options.definition.enable then
lib_notify.Info("definition is not enabled!")
return
end
end

return M
3 changes: 3 additions & 0 deletions lua/LspUI/definition/util.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
local M = {}

return M
1 change: 1 addition & 0 deletions lua/LspUI/modules.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ return {
code_action = require("LspUI.code_action"),
diagnostic = require("LspUI.diagnostic"),
hover = require("LspUI.hover"),
definition = require("LspUI.definition"),
}

0 comments on commit 585dcbf

Please sign in to comment.