xref: /llvm-project/lldb/tools/lldb-dap/src-ts/extension.ts (revision ff5953804ea5b430710b07f1dae395bfcf6d35d0)
1import * as path from "path";
2import * as util from "util";
3import * as vscode from "vscode";
4
5import {
6  LLDBDapDescriptorFactory,
7  isExecutable,
8} from "./debug-adapter-factory";
9import { DisposableContext } from "./disposable-context";
10
11/**
12 * This class represents the extension and manages its life cycle. Other extensions
13 * using it as as library should use this class as the main entry point.
14 */
15export class LLDBDapExtension extends DisposableContext {
16  constructor() {
17    super();
18    this.pushSubscription(
19      vscode.debug.registerDebugAdapterDescriptorFactory(
20        "lldb-dap",
21        new LLDBDapDescriptorFactory(),
22      ),
23    );
24
25    this.pushSubscription(
26      vscode.workspace.onDidChangeConfiguration(async (event) => {
27        if (event.affectsConfiguration("lldb-dap.executable-path")) {
28          const dapPath = vscode.workspace
29            .getConfiguration("lldb-dap")
30            .get<string>("executable-path");
31
32          if (dapPath) {
33            if (await isExecutable(dapPath)) {
34              return;
35            }
36          }
37          LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath || "");
38        }
39      }),
40    );
41  }
42}
43
44/**
45 * This is the entry point when initialized by VS Code.
46 */
47export function activate(context: vscode.ExtensionContext) {
48  context.subscriptions.push(new LLDBDapExtension());
49}
50