| 8 | import { BaseContextProvider } from "../index.js"; |
| 9 | |
| 10 | class DebugLocalsProvider extends BaseContextProvider { |
| 11 | static description: ContextProviderDescription = { |
| 12 | title: "debugger", |
| 13 | displayTitle: "Debugger", |
| 14 | description: "Local variables", |
| 15 | type: "submenu", |
| 16 | renderInlineAs: "", |
| 17 | }; |
| 18 | |
| 19 | async getContextItems( |
| 20 | query: string, |
| 21 | extras: ContextProviderExtras, |
| 22 | ): Promise<ContextItem[]> { |
| 23 | // Assuming that the query is a number |
| 24 | const localVariables = await extras.ide.getDebugLocals(Number(query)); |
| 25 | const threadIndex = Number(query); |
| 26 | const thread = (await extras.ide.getAvailableThreads()).find( |
| 27 | (thread) => thread.id === threadIndex, |
| 28 | ); |
| 29 | const callStacksSources = await extras.ide.getTopLevelCallStackSources( |
| 30 | threadIndex, |
| 31 | this.options?.stackDepth || 3, |
| 32 | ); |
| 33 | const callStackContents = callStacksSources.reduce( |
| 34 | (acc, source, index) => |
| 35 | `${acc}\n\ncall stack ${index}\n\`\`\`\n${source}\n\`\`\``, |
| 36 | "", |
| 37 | ); |
| 38 | return [ |
| 39 | { |
| 40 | description: "The value, name and possibly type of the local variables", |
| 41 | content: |
| 42 | `This is a paused thread: ${thread?.name}\n` + |
| 43 | `Current local variable contents: \n${localVariables}.\n` + |
| 44 | `Current top level call stacks: ${callStackContents}`, |
| 45 | name: "Debugger", |
| 46 | }, |
| 47 | ]; |
| 48 | } |
| 49 | |
| 50 | async loadSubmenuItems( |
| 51 | args: LoadSubmenuItemsArgs, |
| 52 | ): Promise<ContextSubmenuItem[]> { |
| 53 | const threads = await args.ide.getAvailableThreads(); |
| 54 | |
| 55 | return threads.map((thread) => ({ |
| 56 | id: `${thread.id}`, |
| 57 | title: thread.name, |
| 58 | description: `${thread.id}`, |
| 59 | })); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | export default DebugLocalsProvider; |
nothing calls this directly
no outgoing calls
no test coverage detected