refactor to use no magic numbers
This commit is contained in:
		
							parent
							
								
									479cb6e4d9
								
							
						
					
					
						commit
						87fe216eeb
					
				
							
								
								
									
										2
									
								
								init.lua
								
								
								
								
							
							
						
						
									
										2
									
								
								init.lua
								
								
								
								
							| 
						 | 
					@ -973,7 +973,7 @@ require('lazy').setup({
 | 
				
			||||||
  --  Here are some example plugins that I've included in the Kickstart repository.
 | 
					  --  Here are some example plugins that I've included in the Kickstart repository.
 | 
				
			||||||
  --  Uncomment any of the lines below to enable them (you will need to restart nvim).
 | 
					  --  Uncomment any of the lines below to enable them (you will need to restart nvim).
 | 
				
			||||||
  --
 | 
					  --
 | 
				
			||||||
  -- require 'kickstart.plugins.debug',
 | 
					  require 'kickstart.plugins.debug',
 | 
				
			||||||
  -- require 'kickstart.plugins.indent_line',
 | 
					  -- require 'kickstart.plugins.indent_line',
 | 
				
			||||||
  -- require 'kickstart.plugins.lint',
 | 
					  -- require 'kickstart.plugins.lint',
 | 
				
			||||||
  -- require 'kickstart.plugins.autopairs',
 | 
					  -- require 'kickstart.plugins.autopairs',
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,8 +64,9 @@ return {
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      '<leader>B',
 | 
					      '<leader>B',
 | 
				
			||||||
      function()
 | 
					      function()
 | 
				
			||||||
 | 
					        require 'dap.protocol'
 | 
				
			||||||
        local dap = require 'dap'
 | 
					        local dap = require 'dap'
 | 
				
			||||||
        -- Search for an existing breakpoing on this line in this buffer
 | 
					        -- Search for an existing breakpoint on this line in this buffer
 | 
				
			||||||
        ---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder
 | 
					        ---@return dap.SourceBreakpoint bp that was either found, or an empty placeholder
 | 
				
			||||||
        local function find_bp()
 | 
					        local function find_bp()
 | 
				
			||||||
          local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()]
 | 
					          local buf_bps = require('dap.breakpoints').get(vim.fn.bufnr())[vim.fn.bufnr()]
 | 
				
			||||||
| 
						 | 
					@ -83,30 +84,38 @@ return {
 | 
				
			||||||
        -- Elicit customization via a UI prompt
 | 
					        -- Elicit customization via a UI prompt
 | 
				
			||||||
        ---@param bp dap.SourceBreakpoint a breakpoint
 | 
					        ---@param bp dap.SourceBreakpoint a breakpoint
 | 
				
			||||||
        local function customize_bp(bp)
 | 
					        local function customize_bp(bp)
 | 
				
			||||||
          local fields = {
 | 
					          local props = {
 | 
				
			||||||
            ('Condition: (%s)\n'):format(bp.condition),
 | 
					            ['Condition'] = {
 | 
				
			||||||
            ('Hit Condition: (%s)\n'):format(bp.hitCondition),
 | 
					              value = bp.condition,
 | 
				
			||||||
            ('Log Message: (%s)\n'):format(bp.logMessage),
 | 
					              setter = function(v)
 | 
				
			||||||
          }
 | 
					                bp.condition = v
 | 
				
			||||||
          vim.ui.select(fields, {
 | 
					              end,
 | 
				
			||||||
            prompt = 'Edit breakpoint',
 | 
					            },
 | 
				
			||||||
          }, function(choice)
 | 
					            ['Hit Condition'] = {
 | 
				
			||||||
            if choice == fields[1] then
 | 
					              value = bp.hitCondition,
 | 
				
			||||||
              bp.condition = vim.fn.input {
 | 
					              setter = function(v)
 | 
				
			||||||
                prompt = 'Condition: ',
 | 
					                bp.hitCondition = v
 | 
				
			||||||
                default = bp.condition,
 | 
					              end,
 | 
				
			||||||
              }
 | 
					            },
 | 
				
			||||||
            elseif choice == fields[2] then
 | 
					            ['Log Message'] = {
 | 
				
			||||||
              bp.hitCondition = vim.fn.input {
 | 
					              value = bp.logMessage,
 | 
				
			||||||
                prompt = 'Hit Condition: ',
 | 
					              setter = function(v)
 | 
				
			||||||
                default = bp.hitCondition,
 | 
					                bp.logMessage = v
 | 
				
			||||||
              }
 | 
					              end,
 | 
				
			||||||
            elseif choice == fields[3] then
 | 
					            },
 | 
				
			||||||
              bp.logMessage = vim.fn.input {
 | 
					 | 
				
			||||||
                prompt = 'Log Message: ',
 | 
					 | 
				
			||||||
                default = bp.logMessage,
 | 
					 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					          local menu_options = {}
 | 
				
			||||||
 | 
					          for k, v in pairs(props) do
 | 
				
			||||||
 | 
					            table.insert(menu_options, ('%s: %s'):format(k, v.value))
 | 
				
			||||||
          end
 | 
					          end
 | 
				
			||||||
 | 
					          vim.ui.select(menu_options, {
 | 
				
			||||||
 | 
					            prompt = 'Edit Breakpoint',
 | 
				
			||||||
 | 
					          }, function(choice)
 | 
				
			||||||
 | 
					            local prompt = (tostring(choice)):gsub(':.*', '')
 | 
				
			||||||
 | 
					            props[prompt].setter(vim.fn.input {
 | 
				
			||||||
 | 
					              prompt = ('[%s] '):format(prompt),
 | 
				
			||||||
 | 
					              default = props[prompt].value,
 | 
				
			||||||
 | 
					            })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
 | 
					            -- Set breakpoint for current line, with customizations (see h:dap.set_breakpoint())
 | 
				
			||||||
            dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage)
 | 
					            dap.set_breakpoint(bp.condition, bp.hitCondition, bp.logMessage)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue