Skip to content

Commit

Permalink
refactor!: modularize and remove old dap config
Browse files Browse the repository at this point in the history
details:
- remove non-working dap config
- move some code around
- do not start a new terminal with each new `:e` on the same session
  • Loading branch information
TheLeoP committed May 28, 2024
1 parent a0d253f commit bba2146
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 145 deletions.
24 changes: 24 additions & 0 deletions lua/powershell/config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
local api = vim.api
local fs = vim.fs
local base_handlers = require "powershell.handlers"

local M = {}

---@type powershell.config
M.default_config = {
capabilities = vim.lsp.protocol.make_client_capabilities(),
bundle_path = "",
init_options = vim.empty_dict() --[[@as table]],
settings = vim.empty_dict() --[[@as table]],
shell = "pwsh",
handlers = base_handlers,
root_dir = function(buf)
local current_file_dir = fs.dirname(api.nvim_buf_get_name(buf))
return fs.dirname(fs.find({ ".git" }, { upward = true, path = current_file_dir })[1]) or current_file_dir
end,
}

---@type powershell.config
M.config = nil

return M
66 changes: 66 additions & 0 deletions lua/powershell/dap.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
local api = vim.api
local util = require "powershell.util"

local M = {}

-- TODO: modify to allow multiple different seession_files
local temp_path = vim.fn.stdpath "cache"
local session_file_path = ("%s/powershell_es.temp_session.json"):format(temp_path)
session_file_path = vim.fs.normalize(session_file_path)
local log_file_path = ("%s/powershell_es.temp.log"):format(temp_path)
log_file_path = vim.fs.normalize(log_file_path)
vim.fn.delete(session_file_path)

---@param bundle_path string
---@return string[]
local function make_args(bundle_path)
local file = ("%s/PowerShellEditorServices/Start-EditorServices.ps1"):format(bundle_path)
file = vim.fs.normalize(file)
--stylua: ignore
return {
"-NoLogo",
"-NoProfile",
"-NonInteractive",
"-File", file,
"-HostName", "nvim",
"-HostProfileId", "Neovim",
"-HostVersion", "1.0.0",
"-LogPath", log_file_path,
-- TODO: make this configurable
"-LogLevel", "Normal",
"-BundledModulesPath", ("%s"):format(bundle_path),
"-DebugServiceOnly",
"-DebugServicePipeName", "${pipe}",
-- TODO: wait for response on https://github.com/PowerShell/PowerShellEditorServices/issues/2164
-- "-EnableConsoleRepl",
"-SessionDetailsPath", session_file_path,
}
end

function M.setup()
local dap = require "dap"
local config = require("powershell.config").config

-- TODO: this is broken on windows until https://github.com/mfussenegger/nvim-dap/issues/1230
dap.adapters.powershell_no_term = function(on_config)
on_config {
type = "pipe",
pipe = "${pipe}",
executable = {
command = config.shell,
args = make_args(config.bundle_path),
detached = false,
},
}
end
dap.configurations.ps1 = {
{
name = "PowerShell: Launch Current File (no term)",
type = "powershell_no_term",
request = "launch",
script = "${file}",
},
}
end

return M
Loading

0 comments on commit bba2146

Please sign in to comment.