[mlir][int-range] Limit xor int range inference to i1 (#116968)
[llvm-project.git] / lldb / tools / lldb-dap / src-ts / extension.ts
blob36d3dfba18c142186156f8e623274b414091fc81
1 import * as vscode from "vscode";
2 import { LLDBDapOptions } from "./types";
3 import { DisposableContext } from "./disposable-context";
4 import { LLDBDapDescriptorFactory } from "./debug-adapter-factory";
6 /**
7  * This creates the configurations for this project if used as a standalone
8  * extension.
9  */
10 function createDefaultLLDBDapOptions(): LLDBDapOptions {
11   return {
12     debuggerType: "lldb-dap",
13     async createDapExecutableCommand(
14       session: vscode.DebugSession,
15       packageJSONExecutable: vscode.DebugAdapterExecutable | undefined,
16     ): Promise<vscode.DebugAdapterExecutable | undefined> {
17       const config = vscode.workspace.getConfiguration(
18         "lldb-dap",
19         session.workspaceFolder,
20       );
21       const path = config.get<string>("executable-path");
22       const log_path = config.get<string>("log-path");
24       let env: { [key: string]: string } = {};
25       if (log_path) {
26         env["LLDBDAP_LOG"] = log_path;
27       }
28       const configEnvironment = config.get<{ [key: string]: string }>("environment") || {};
29       if (path) {
30         const dbgOptions = {
31           env: {
32             ...configEnvironment,
33             ...env,
34           }
35         };
36         return new vscode.DebugAdapterExecutable(path, [], dbgOptions);
37       } else if (packageJSONExecutable) {
38         return new vscode.DebugAdapterExecutable(
39           packageJSONExecutable.command,
40           packageJSONExecutable.args,
41           {
42             ...packageJSONExecutable.options,
43             env: {
44               ...packageJSONExecutable.options?.env,
45               ...configEnvironment,
46               ...env,
47             },
48           },
49         );
50       } else {
51         return undefined;
52       }
53     },
54   };
57 /**
58  * This class represents the extension and manages its life cycle. Other extensions
59  * using it as as library should use this class as the main entry point.
60  */
61 export class LLDBDapExtension extends DisposableContext {
62   private lldbDapOptions: LLDBDapOptions;
64   constructor(lldbDapOptions: LLDBDapOptions) {
65     super();
66     this.lldbDapOptions = lldbDapOptions;
68     this.pushSubscription(
69       vscode.debug.registerDebugAdapterDescriptorFactory(
70         this.lldbDapOptions.debuggerType,
71         new LLDBDapDescriptorFactory(this.lldbDapOptions),
72       ),
73     );
75     this.pushSubscription(
76       vscode.workspace.onDidChangeConfiguration(async (event) => {
77         if (event.affectsConfiguration("lldb-dap.executable-path")) {
78           const dapPath = vscode.workspace
79             .getConfiguration("lldb-dap")
80             .get<string>("executable-path");
82           if (dapPath) {
83             const fileUri = vscode.Uri.file(dapPath);
84             if (
85               await LLDBDapDescriptorFactory.isValidDebugAdapterPath(fileUri)
86             ) {
87               return;
88             }
89           }
90           LLDBDapDescriptorFactory.showLLDBDapNotFoundMessage(dapPath || "");
91         }
92       }),
93     );
94   }
97 /**
98  * This is the entry point when initialized by VS Code.
99  */
100 export function activate(context: vscode.ExtensionContext) {
101   context.subscriptions.push(
102     new LLDBDapExtension(createDefaultLLDBDapOptions()),
103   );