-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_load.lua
More file actions
216 lines (184 loc) · 6.55 KB
/
test_load.lua
File metadata and controls
216 lines (184 loc) · 6.55 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
--[[
Test loader for notion.nvim local development
This script unloads any existing notion.nvim plugin and loads the local version
from the current directory for testing purposes.
Usage (within Neovim):
:luafile test_load.lua
or
:lua dofile('test_load.lua')
or
:lua require('test_load').reload()
Features:
- Unloads existing notion.nvim plugin completely
- Loads the local version from current directory
- Enables debug mode for detailed timing info
- Verifies all commands and modules are working
- Provides helpful usage information
--]]
local M = {}
-- Function to clear/unload existing plugin
local function unload_plugin()
-- Clear global plugin loaded flag
vim.g.loaded_notion_nvim = nil
-- Clear all notion-related modules from package.loaded
local modules_to_clear = {
'notion',
'notion.api',
'notion.config',
'notion.init',
'notion.telescope'
}
for _, module in ipairs(modules_to_clear) do
package.loaded[module] = nil
end
-- Clear user commands if they exist
local commands_to_clear = {
'Notion',
'NotionCreate',
'NotionEdit',
'NotionSync',
'NotionBrowser',
'NotionDelete'
}
for _, cmd in ipairs(commands_to_clear) do
pcall(vim.api.nvim_del_user_command, cmd)
end
print("✓ Unloaded existing notion.nvim plugin")
end
-- Function to load local plugin
local function load_local_plugin()
local current_dir = vim.fn.getcwd()
local lua_path = current_dir .. '/lua'
local plugin_path = current_dir .. '/plugin'
-- Force clear all notion modules first
for module_name, _ in pairs(package.loaded) do
if module_name:match('^notion') then
package.loaded[module_name] = nil
end
end
-- Directly load local files using dofile instead of require
local function load_local_module(module_path, module_name)
local file_path = lua_path .. '/' .. module_path
if vim.fn.filereadable(file_path) == 1 then
local chunk, err = loadfile(file_path)
if chunk then
local module = chunk()
package.loaded[module_name] = module
return module
else
error("Failed to load " .. file_path .. ": " .. tostring(err))
end
else
error("File not found: " .. file_path)
end
end
-- Load modules in dependency order
print("Loading local modules directly...")
-- Load config first
local config = load_local_module('notion/config.lua', 'notion.config')
print("✓ Loaded notion.config from local file")
-- Load api
local api = load_local_module('notion/api.lua', 'notion.api')
print("✓ Loaded notion.api from local file")
-- Load telescope module (if telescope is available)
local telescope_ok = pcall(require, 'telescope')
if telescope_ok then
local telescope_module = load_local_module('notion/telescope.lua', 'notion.telescope')
print("✓ Loaded notion.telescope from local file")
else
print("⚠ Telescope not installed, notion.telescope will not be available")
end
-- Load init/main
local init = load_local_module('notion/init.lua', 'notion.init')
local notion = load_local_module('notion.lua', 'notion')
print("✓ Loaded notion modules from local files")
-- Setup with default configuration for testing
notion.setup({
debug = true, -- Enable debug mode for testing
sync_debounce_ms = 500, -- Faster sync for testing
use_telescope = true, -- Force Telescope usage, will warn if unavailable
})
-- Load the plugin file that defines the main :Notion command
local plugin_file = plugin_path .. '/notion.lua'
if vim.fn.filereadable(plugin_file) == 1 then
local plugin_ok, plugin_err = pcall(dofile, plugin_file)
if not plugin_ok then
print("✗ Failed to load plugin file: " .. tostring(plugin_err))
return false
end
print("✓ Loaded plugin commands from: " .. plugin_path)
else
print("✗ Plugin file not found: " .. plugin_file)
return false
end
-- Verify we're using the local API
local api_module = package.loaded['notion.api']
if api_module and api_module.edit_page then
local debug_info = debug.getinfo(api_module.edit_page, 'S')
if debug_info and debug_info.source then
print("✓ Verified notion.api loaded from: " .. debug_info.source)
end
end
print("✓ Local notion.nvim plugin successfully loaded!")
return true
end
-- Function to verify plugin is loaded
local function verify_plugin()
-- Check if commands exist
local commands = {
'Notion',
'NotionCreate',
'NotionEdit',
'NotionSync',
'NotionBrowser',
'NotionDelete'
}
local missing_commands = {}
for _, cmd in ipairs(commands) do
local ok, cmd_list = pcall(vim.api.nvim_get_commands, { builtin = false })
local exists = ok and cmd_list and cmd_list[cmd] ~= nil
if not exists then
table.insert(missing_commands, cmd)
end
end
if #missing_commands > 0 then
print("✗ Missing commands: " .. table.concat(missing_commands, ', '))
return false
end
-- Check if modules are loaded
local modules = { 'notion', 'notion.api', 'notion.config' }
for _, module in ipairs(modules) do
if not package.loaded[module] then
print("✗ Module not loaded: " .. module)
return false
end
end
print("✓ All commands and modules verified")
return true
end
-- Main function
function M.reload()
print("=== Reloading notion.nvim for local testing ===")
unload_plugin()
if load_local_plugin() then
if verify_plugin() then
print("✓ Local notion.nvim successfully loaded and verified!")
print("")
print("Available commands:")
print(" :Notion create <title> - Create new page")
print(" :Notion edit [id] - Edit existing page")
print(" :Notion delete - Delete page")
print(" :NotionBrowser - Open in browser")
print(" :NotionSync - Manual sync")
print("")
print("Debug mode is enabled - you'll see detailed timing info.")
else
print("✗ Plugin verification failed")
end
else
print("✗ Failed to load local plugin")
end
end
-- Auto-run when file is loaded
M.reload()
return M