|
1 | | -local api = vim.api |
2 | | -local util = require "powershell.util" |
3 | | - |
4 | | -local M = {} |
5 | | - |
6 | | --- TODO: modify to allow multiple different seession_files |
7 | | -local temp_path = vim.fn.stdpath "cache" |
8 | | -local session_file_path = ("%s/powershell_es.temp_session.json"):format(temp_path) |
9 | | -session_file_path = vim.fs.normalize(session_file_path) |
10 | | -local log_file_path = ("%s/powershell_es.temp.log"):format(temp_path) |
11 | | -log_file_path = vim.fs.normalize(log_file_path) |
12 | | -vim.fn.delete(session_file_path) |
13 | | - |
14 | | ----@param bundle_path string |
15 | | ----@return string[] |
16 | | -local function make_cmd(bundle_path, shell) |
17 | | - local file = ("%s/PowerShellEditorServices/Start-EditorServices.ps1"):format(bundle_path) |
18 | | - file = vim.fs.normalize(file) |
19 | | - --stylua: ignore |
20 | | - return { |
21 | | - shell, |
22 | | - "-NoLogo", |
23 | | - "-NoProfile", |
24 | | - "-NonInteractive", |
25 | | - "-File", file, |
26 | | - "-HostName", "nvim", |
27 | | - "-HostProfileId", "Neovim", |
28 | | - "-HostVersion", "1.0.0", |
29 | | - "-LogPath", log_file_path, |
30 | | - -- TODO: make this configurable |
31 | | - "-LogLevel", "Normal", |
32 | | - "-BundledModulesPath", ("%s"):format(bundle_path), |
33 | | - "-DebugServiceOnly", |
34 | | - -- TODO: wait for response on https://github.com/PowerShell/PowerShellEditorServices/issues/2164 |
35 | | - -- "-EnableConsoleRepl", |
36 | | - "-SessionDetailsPath", session_file_path, |
37 | | - } |
38 | | -end |
39 | | - |
40 | | -function M.setup() |
41 | | - local dap = require "dap" |
42 | | - local config = require("powershell.config").config |
43 | | - |
44 | | - dap.adapters.ps1 = function(on_config) |
45 | | - local cmd = make_cmd(config.bundle_path, config.shell) |
46 | | - vim.system(cmd) |
47 | | - util.wait_for_session_file(session_file_path, function(current_session_details, error_msg) |
48 | | - if error_msg then return vim.notify(error_msg, vim.log.levels.ERROR) end |
49 | | - |
50 | | - on_config { |
51 | | - type = "pipe", |
52 | | - pipe = current_session_details.debugServicePipeName, |
53 | | - } |
54 | | - end) |
55 | | - end |
56 | | - dap.configurations.ps1 = { |
57 | | - { |
58 | | - name = "PowerShell: Launch Current File", |
59 | | - type = "ps1", |
60 | | - request = "launch", |
61 | | - script = "${file}", |
62 | | - }, |
63 | | - { |
64 | | - name = "PowerShell: Launch Script", |
65 | | - type = "ps1", |
66 | | - request = "launch", |
67 | | - script = function() |
68 | | - return coroutine.create(function(co) |
69 | | - vim.ui.input({ |
70 | | - prompt = 'Enter path or command to execute, for example: "${workspaceFolder}/src/foo.ps1" or "Invoke-Pester"', |
71 | | - completion = "file", |
72 | | - }, function(selected) coroutine.resume(co, selected) end) |
73 | | - end) |
74 | | - end, |
75 | | - }, |
76 | | - { |
77 | | - name = "PowerShell: Attach to PowerShell Host Process", |
78 | | - type = "ps1", |
79 | | - request = "attach", |
80 | | - processId = "${command:pickProcess}", |
81 | | - }, |
82 | | - } |
83 | | -end |
84 | | - |
85 | | -return M |
| 1 | +local api = vim.api |
| 2 | +local util = require "powershell.util" |
| 3 | + |
| 4 | +local M = {} |
| 5 | + |
| 6 | +-- TODO: modify to allow multiple different seession_files |
| 7 | +local temp_path = vim.fn.stdpath "cache" |
| 8 | +local session_file_path = ("%s/powershell_es.temp_session.json"):format(temp_path) |
| 9 | +session_file_path = vim.fs.normalize(session_file_path) |
| 10 | +local log_file_path = ("%s/powershell_es.temp.log"):format(temp_path) |
| 11 | +log_file_path = vim.fs.normalize(log_file_path) |
| 12 | +vim.fn.delete(session_file_path) |
| 13 | + |
| 14 | +---@param bundle_path string |
| 15 | +---@return string[] |
| 16 | +local function make_cmd(bundle_path, shell) |
| 17 | + local file = ("%s/PowerShellEditorServices/Start-EditorServices.ps1"):format(bundle_path) |
| 18 | + file = vim.fs.normalize(file) |
| 19 | + --stylua: ignore |
| 20 | + return { |
| 21 | + shell, |
| 22 | + "-NoLogo", |
| 23 | + "-NoProfile", |
| 24 | + "-NonInteractive", |
| 25 | + "-File", file, |
| 26 | + "-HostName", "nvim", |
| 27 | + "-HostProfileId", "Neovim", |
| 28 | + "-HostVersion", "1.0.0", |
| 29 | + "-LogPath", log_file_path, |
| 30 | + -- TODO: make this configurable |
| 31 | + "-LogLevel", "Normal", |
| 32 | + "-BundledModulesPath", ("%s"):format(bundle_path), |
| 33 | + "-DebugServiceOnly", |
| 34 | + -- TODO: wait for response on https://github.com/PowerShell/PowerShellEditorServices/issues/2164 |
| 35 | + -- "-EnableConsoleRepl", |
| 36 | + "-SessionDetailsPath", session_file_path, |
| 37 | + } |
| 38 | +end |
| 39 | + |
| 40 | +function M.setup() |
| 41 | + local dap = require "dap" |
| 42 | + local config = require("powershell.config").config |
| 43 | + |
| 44 | + dap.adapters.ps1 = function(on_config) |
| 45 | + local cmd = make_cmd(config.bundle_path, config.shell) |
| 46 | + vim.system(cmd) |
| 47 | + util.wait_for_session_file(session_file_path, function(current_session_details, error_msg) |
| 48 | + if error_msg then return vim.notify(error_msg, vim.log.levels.ERROR) end |
| 49 | + |
| 50 | + on_config { |
| 51 | + type = "pipe", |
| 52 | + pipe = current_session_details.debugServicePipeName, |
| 53 | + } |
| 54 | + end) |
| 55 | + end |
| 56 | + dap.configurations.ps1 = { |
| 57 | + { |
| 58 | + name = "PowerShell: Launch Current File", |
| 59 | + type = "ps1", |
| 60 | + request = "launch", |
| 61 | + script = "${file}", |
| 62 | + }, |
| 63 | + { |
| 64 | + name = "PowerShell: Launch Script", |
| 65 | + type = "ps1", |
| 66 | + request = "launch", |
| 67 | + script = function() |
| 68 | + return coroutine.create(function(co) |
| 69 | + vim.ui.input({ |
| 70 | + prompt = 'Enter path or command to execute, for example: "${workspaceFolder}/src/foo.ps1" or "Invoke-Pester"', |
| 71 | + completion = "file", |
| 72 | + }, function(selected) coroutine.resume(co, selected) end) |
| 73 | + end) |
| 74 | + end, |
| 75 | + }, |
| 76 | + { |
| 77 | + name = "PowerShell: Attach to PowerShell Host Process", |
| 78 | + type = "ps1", |
| 79 | + request = "attach", |
| 80 | + processId = "${command:pickProcess}", |
| 81 | + }, |
| 82 | + } |
| 83 | +end |
| 84 | + |
| 85 | +return M |
0 commit comments