Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support register variable/command, add unit test #996

Closed
wants to merge 1 commit into from
Closed

support register variable/command, add unit test #996

wants to merge 1 commit into from

Conversation

AbaoFromCUG
Copy link

@AbaoFromCUG AbaoFromCUG commented Jul 27, 2023

Register command mechanism

Regarding to Command, vscode has a mechanism named Command, which can be used as Command Variable

If the predefined variables from above are not sufficient, you can use any VS Code command as a variable through the ${command:commandID} syntax.
A command variable is replaced with the (string) result from the command evaluation. The implementation of a command can range from a simple calculation with no UI, to some sophisticated functionality based on the UI features available via VS Code's extension API. If the command returns anything other than a string, then the variable replacement will not complete. Command variables must return a string.

For example, vscode-cmake-tools extension support lots of command variable, which can be used in launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            // Resolved by CMake Tools:
            "program": "${command:cmake.launchTargetPath}",
            "cwd": "${workspaceFolder}",
            "environment": [
                {
                    // add the directory where our target was built to the PATHs
                    // it gets resolved by CMake Tools:
                    "name": "PATH",
                    "value": "${env:PATH}:${command:cmake.getLaunchTargetDirectory}"
                }
            ]
        }
    ]
}

What did I do

I add API named dap.register_command(identifier, handler) to do something same to vscode.commands.registerCommand . Which can help extension developer to enhance ability of dap.

e.g.

require("dap").register_command("cmake.launchTargetPath", function()
   // run cmake build task, then return executable path
   // can be a asynchronous coroutine
   return coroutine.create(function()
         // fake cmake build step
         vim.defer_fn(function()
            coroutine.resume(co, "/path/to/exectutable")
          end, 2000)
  end)
end)

Some Unit Test Added

  • normal variable
  • env varialbe
  • register command
  • register asnyc command

@AbaoFromCUG
Copy link
Author

Closed with additional inject code via dap.expand_config_variables

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant