summaryrefslogtreecommitdiff
path: root/vim/.config/nvim/lua/godot.lua
blob: 327ed330e3a66f6c8d231e60e2893a98e1387d71 (plain)
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
local function connect_to_godot_server()
  -- Check if project.godot exists in current directory
  local project_file = vim.fn.getcwd() .. "/project.godot"
  if vim.fn.filereadable(project_file) == 1 then
    local pipe_path = vim.fn.getcwd() .. "/nvim_server.pipe"

    -- Create the pipe if it doesn't exist, then connect
    local success = vim.fn.serverstart(pipe_path)
    if success then
      print("Connected to Godot server via " .. pipe_path)
    else
      print("Failed to create/connect to Godot server pipe: " .. pipe_path)
    end

    local dap = require("dap")

    dap.adapters.godot = {
      type = 'server',
      host = '127.0.0.1',
      port = 6006,
    }

    dap.configurations.gdscript = {
      {
        type = 'godot',
        request = 'launch',
        name = 'Launch scene',
        project = '${workspaceFolder}',
        launch_scene = true,
      },
    }

    dap.configurations.cs = {
      {
        type = 'godot',
        request = 'launch',
        name = 'Launch scene',
        project = '${workspaceFolder}',
        launch_scene = true,
      },
    }
  end
end

-- Auto-connect when Neovim starts
vim.api.nvim_create_autocmd("VimEnter", {
  callback = connect_to_godot_server,
  desc = "Auto-connect to Godot server if project.godot exists"
})

-- Optional: Also check when changing directories
vim.api.nvim_create_autocmd("DirChanged", {
  callback = connect_to_godot_server,
  desc = "Auto-connect to Godot server when changing to Godot project directory"
})

-- Optional: Command to manually connect
vim.api.nvim_create_user_command("GodotConnect", connect_to_godot_server, {
  desc = "Manually connect to Godot server"
})