Skip to content

Commit 6629c31

Browse files
committed
replace :SetupDefold command with lua imports if the user wants to do something the manual way, close #57
1 parent d2107ff commit 6629c31

2 files changed

Lines changed: 45 additions & 40 deletions

File tree

README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,18 @@ defold.setup(config)
216216
1. Install the plugin (see above)
217217
2. Install [Defold](https://defold.com/)
218218
3. Start Defold and open a project
219-
4. Open Neovim in the projects directory and run `:SetupDefold`
220-
5. Done, when you try to open files via Defold now they should open in a Neovim window.
219+
4. Open Neovim in the projects directory once (Defold must be running)
220+
5. Done, when you try to open files via Defold now they open in your current Neovim instance or in a new window if none could be found.
221+
222+
#### Manual Setup
223+
224+
If you have the auto setup for the Defold external editor disabled and/or you want to initialize this a different way, use:
225+
226+
`:lua require("defold").setup_default_editor()`
227+
228+
Similarly the Debugger can be initialized using
229+
230+
`:lua require("defold").setup_debugger()`
221231

222232
### Setup Debugging
223233

@@ -253,14 +263,16 @@ Here's how you can interact with Defold directly from Neovim:
253263
* **:DefoldFetch**
254264
This command fetches all Defold dependencies and creates annotations for the Lua LSP. Run with bang to force re-downloading the annotations.
255265

256-
* **:SetupDefold**
257-
This commands does the required setup for Defold to use Neovim as its external editor (this will be done by default unless disabled, see config above)
258-
259266
## Troubleshooting
260267

261268
Should you have problems, please open Neovim (preferably through Defold) and use the command `:checkhealth defold`, this should give you a short list of several checks that might help to identify
262269
the issue. If it didn't, please be sure to include the health check if you report the issue.
263270

271+
There are also logs available, you can find the paths inside `:checkhealth defold`.
272+
273+
- **System > Cache Dir**: The location of the plugin logs
274+
- **Sidecar > Sidecar Cache Dir**: The location of the sidecar (Neovim native extension) and bridge (Tool that calls Neovim instances)
275+
264276
## Special Thanks
265277

266278
- [astrochili/defold-annotations](https://github.com/astrochili/defold-annotations)

lua/defold/init.lua

Lines changed: 28 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -108,30 +108,6 @@ function M.setup(opts)
108108
end
109109
end
110110

111-
-- add setup defold command
112-
vim.api.nvim_create_user_command("SetupDefold", function()
113-
local project = require "defold.project"
114-
local port = project.editor_port()
115-
116-
if not port then
117-
log.error "Editor is not running, please make sure the editor for this project is running."
118-
return
119-
end
120-
121-
local sidecar = require "defold.sidecar"
122-
local ok, err = pcall(sidecar.set_default_editor, port, M.plugin_root(), M.config.launcher)
123-
if not ok then
124-
log.error(string.format("Could not set default editor because: %s", err))
125-
end
126-
127-
if M.config.debugger.enable then
128-
local debugger = require "defold.service.debugger"
129-
debugger.setup(M.config.debugger.custom_executable, M.config.debugger.custom_arguments)
130-
end
131-
132-
log.info "Defold setup successfully"
133-
end, { nargs = 0, desc = "Setup Defold to use Neovim as its default editor" })
134-
135111
-- register some filetypes
136112
vim.filetype.add(require("defold.config.filetype").minimal)
137113

@@ -176,20 +152,12 @@ function M.setup(opts)
176152
project.ensure_nvim_server(M.config.launcher.socket_type)
177153
end
178154

179-
local port = project.editor_port()
180-
181-
if M.config.defold.set_default_editor and port then
182-
local sidecar = require "defold.sidecar"
183-
local ok, err = pcall(sidecar.set_default_editor, port, M.plugin_root(), M.config.launcher)
184-
185-
if not ok then
186-
log.error(string.format("Could not set default editor because: %s", err))
187-
end
155+
if M.config.defold.set_default_editor then
156+
M.setup_default_editor()
188157
end
189158

190159
if M.config.debugger.enable then
191-
local debugger = require "defold.service.debugger"
192-
debugger.setup(M.config.debugger.custom_executable, M.config.debugger.custom_arguments)
160+
M.setup_debugger()
193161
end
194162

195163
if not M.config.force_plugin_enabled and not project.is_defold_project() then
@@ -326,4 +294,29 @@ function M.load_plugin()
326294
end
327295
end
328296

297+
---Sets Neovim as the default Defold editor
298+
function M.setup_default_editor()
299+
local project = require "defold.project"
300+
local log = require "defold.service.logger"
301+
302+
local port = project.editor_port()
303+
304+
if not port then
305+
return
306+
end
307+
308+
local sidecar = require "defold.sidecar"
309+
local ok, err = pcall(sidecar.set_default_editor, port, M.plugin_root(), M.config.launcher)
310+
311+
if not ok then
312+
log.error(string.format("Could not set default editor because: %s", err))
313+
end
314+
end
315+
316+
---Sets up MobDap as the debugger
317+
function M.setup_debugger()
318+
local debugger = require "defold.service.debugger"
319+
debugger.setup(M.config.debugger.custom_executable, M.config.debugger.custom_arguments)
320+
end
321+
329322
return M

0 commit comments

Comments
 (0)