|
1 | 1 | local M = {} |
2 | | -local settings = require("jc.settings") |
3 | 2 | local lsp = require("jc.lsp") |
4 | | - |
5 | | -local function ask_for(name, default) |
6 | | - local default_result = settings.read_project("debug-" .. name, default) |
7 | | - local result = vim.fn.input("Debug " .. name .. " (" .. default_result .. "): ") |
8 | | - if #result == 0 then |
9 | | - result = default_result |
10 | | - elseif result ~= default_result then |
11 | | - settings.write_project("debug-" .. name, result) |
12 | | - end |
13 | | - return result |
14 | | -end |
| 3 | +local ui = require("jc.ui") |
15 | 4 |
|
16 | 5 | local function resolve_main_class(callback) |
17 | 6 | lsp.executeCommand({ command = "vscode.java.resolveMainClass" }, function(response) |
@@ -50,71 +39,76 @@ function M.debug_launch() |
50 | 39 | else |
51 | 40 | classpaths = classpaths[2] |
52 | 41 | end |
53 | | - lsp.executeCommand({ command = "vscode.java.startDebugSession" }, function(response) |
54 | | - vim.fn["vimspector#LaunchWithConfigurations"]({ |
55 | | - attach = { |
56 | | - adapter = { |
57 | | - name = "vscode-java", |
58 | | - port = response, |
59 | | - }, |
60 | | - configuration = { |
61 | | - request = "launch", |
62 | | - mainClass = main_class, |
63 | | - args = ask_for("arguments", ""), |
64 | | - classPaths = classpaths, |
65 | | - console = "integratedTerminal", |
66 | | - }, |
67 | | - breakpoints = { |
68 | | - exception = { |
69 | | - caught = "N", |
70 | | - uncaught = "N", |
| 42 | + ui.ask_for("arguments", "", function(arguments) |
| 43 | + lsp.executeCommand({ command = "vscode.java.startDebugSession" }, function(response) |
| 44 | + vim.fn["vimspector#LaunchWithConfigurations"]({ |
| 45 | + attach = { |
| 46 | + adapter = { |
| 47 | + name = "vscode-java", |
| 48 | + port = response, |
| 49 | + }, |
| 50 | + configuration = { |
| 51 | + request = "launch", |
| 52 | + mainClass = main_class, |
| 53 | + args = arguments, |
| 54 | + classPaths = classpaths, |
| 55 | + console = "integratedTerminal", |
| 56 | + }, |
| 57 | + breakpoints = { |
| 58 | + exception = { |
| 59 | + caught = "N", |
| 60 | + uncaught = "N", |
| 61 | + }, |
71 | 62 | }, |
72 | 63 | }, |
73 | | - }, |
74 | | - }) |
| 64 | + }) |
| 65 | + end) |
75 | 66 | end) |
76 | 67 | end) |
77 | 68 | end) |
78 | 69 | end |
79 | 70 |
|
80 | 71 | function M.debug_attach() |
81 | | - lsp.executeCommand({ command = "vscode.java.startDebugSession" }, function(response) |
82 | | - if type(response) == "number" then |
83 | | - vim.fn["vimspector#LaunchWithConfigurations"]({ |
84 | | - attach = { |
85 | | - adapter = { |
86 | | - name = "vscode-java", |
87 | | - port = response, |
88 | | - }, |
89 | | - configuration = { |
90 | | - request = "attach", |
91 | | - host = ask_for("host", "127.0.0.1"), |
92 | | - port = ask_for("port", "9000"), |
93 | | - }, |
94 | | - breakpoints = { |
95 | | - exception = { |
96 | | - caught = "N", |
97 | | - uncaught = "N", |
| 72 | + ui.ask_for("host", "127.0.0.1", function(host) |
| 73 | + ui.ask_for("port", "9000", function(port) |
| 74 | + lsp.executeCommand({ command = "vscode.java.startDebugSession" }, function(response) |
| 75 | + if type(response) == "number" then |
| 76 | + vim.fn["vimspector#LaunchWithConfigurations"]({ |
| 77 | + attach = { |
| 78 | + adapter = { |
| 79 | + name = "vscode-java", |
| 80 | + port = response, |
| 81 | + }, |
| 82 | + configuration = { |
| 83 | + request = "attach", |
| 84 | + host = host, |
| 85 | + port = port, |
| 86 | + }, |
| 87 | + breakpoints = { |
| 88 | + exception = { |
| 89 | + caught = "N", |
| 90 | + uncaught = "N", |
| 91 | + }, |
| 92 | + }, |
98 | 93 | }, |
99 | | - }, |
100 | | - }, |
101 | | - }) |
102 | | - else |
103 | | - vim.notify(vim.inspect(response), vim.log.levels.WARN) |
104 | | - end |
| 94 | + }) |
| 95 | + else |
| 96 | + vim.notify(vim.inspect(response), vim.log.levels.WARN) |
| 97 | + end |
| 98 | + end) |
| 99 | + end) |
105 | 100 | end) |
106 | 101 | end |
107 | 102 |
|
108 | 103 | function M.debug_choose_configuration() |
109 | | - local prompt = "Choose vimspector configuration:\n" |
110 | 104 | local configs = vim.fn["vimspector#GetConfigurations"]() |
111 | | - for i, config in ipairs(configs) do |
112 | | - prompt = prompt .. i .. ". " .. config .. "\n" |
113 | | - end |
114 | | - prompt = prompt .. "Your choice: " |
115 | | - local choice = tonumber(vim.fn.input(prompt)) |
116 | | - lsp.executeCommand({ command = "vscode.java.startDebugSession" }, function(response) |
117 | | - vim.fn["vimspector#LaunchWithSettings"]({ configuration = configs[choice], AdapterPort = response }) |
| 105 | + vim.ui.select(configs, { prompt = "Choose vimspector configuration:" }, function(choice) |
| 106 | + if not choice then |
| 107 | + return |
| 108 | + end |
| 109 | + lsp.executeCommand({ command = "vscode.java.startDebugSession" }, function(response) |
| 110 | + vim.fn["vimspector#LaunchWithSettings"]({ configuration = choice, AdapterPort = response }) |
| 111 | + end) |
118 | 112 | end) |
119 | 113 | end |
120 | 114 |
|
|
0 commit comments