-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[lldb-dap] Support finding the lldb-dap binary #118547
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,7 @@ | ||||||||
| import * as path from "path"; | ||||||||
| import * as util from "util"; | ||||||||
| import * as vscode from "vscode"; | ||||||||
|
|
||||||||
| import { LLDBDapOptions } from "./types"; | ||||||||
|
|
||||||||
| /** | ||||||||
|
|
@@ -8,15 +11,7 @@ import { LLDBDapOptions } from "./types"; | |||||||
| export class LLDBDapDescriptorFactory | ||||||||
| implements vscode.DebugAdapterDescriptorFactory | ||||||||
| { | ||||||||
| private lldbDapOptions: LLDBDapOptions; | ||||||||
|
|
||||||||
| constructor(lldbDapOptions: LLDBDapOptions) { | ||||||||
| this.lldbDapOptions = lldbDapOptions; | ||||||||
| } | ||||||||
|
|
||||||||
| static async isValidDebugAdapterPath( | ||||||||
| pathUri: vscode.Uri, | ||||||||
| ): Promise<Boolean> { | ||||||||
| static async isValidFile(pathUri: vscode.Uri): Promise<Boolean> { | ||||||||
| try { | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We may want to validate that the file is executable. It looks like the VS Code FS API doesn't have that info but we could use the node FS instead, something like: |
||||||||
| const fileStats = await vscode.workspace.fs.stat(pathUri); | ||||||||
| if (!(fileStats.type & vscode.FileType.File)) { | ||||||||
|
|
@@ -28,6 +23,70 @@ export class LLDBDapDescriptorFactory | |||||||
| return true; | ||||||||
| } | ||||||||
|
|
||||||||
| static async findDAPExecutable(): Promise<string | undefined> { | ||||||||
|
||||||||
| let executable = "lldb-dap"; | ||||||||
| if (process.platform === "win32") { | ||||||||
| executable = "lldb-dap.exe"; | ||||||||
| } | ||||||||
|
||||||||
|
|
||||||||
| // Prefer lldb-dap from Xcode on Darwin. | ||||||||
| if (process.platform === "darwin") { | ||||||||
| try { | ||||||||
| const exec = util.promisify(require("child_process").execFile); | ||||||||
|
||||||||
| let { stdout, stderr } = await exec("/usr/bin/xcrun", [ | ||||||||
| "-find", | ||||||||
| executable, | ||||||||
| ]); | ||||||||
| if (stdout) { | ||||||||
| return stdout.toString().trimEnd(); | ||||||||
| } | ||||||||
| } catch (error) {} | ||||||||
| } | ||||||||
|
|
||||||||
| // Find lldb-dap in the user's path. | ||||||||
| let env_path = | ||||||||
| process.env["PATH"] || | ||||||||
| (process.platform === "win32" ? process.env["Path"] : null); | ||||||||
|
||||||||
| process.env["PATH"] || | |
| (process.platform === "win32" ? process.env["Path"] : null); | |
| process.platform === "win32" ? process.env["Path"] : process.env["PATH"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this just be a function outside of the class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're also calling this from
extension.ts. I guess we could export the function but that doesn't seem much better than leaving it a static method?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is doing anything specific for
LLDBDapDescriptorFactoryand a top levelisValidExeorisExecutableis straight forward to reason vsLLDBDapDescriptorFactory.isValidFile.