-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,413 additions
and
267 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as vscode from "vscode"; | ||
import { TextDecoder } from "node:util"; | ||
|
||
export type OpcodeDefinition = { | ||
parameters: string; | ||
description: string; | ||
output: string; | ||
example: string; | ||
concurrency: boolean; | ||
}; | ||
|
||
export type OpcodeIndex = Record<string, OpcodeDefinition>; | ||
|
||
/** | ||
* Load opcode documentation from the bundled extension files. | ||
* @param context The vscode extension context. | ||
* @returns The opcode documentation. | ||
*/ | ||
export async function loadOpcodeDocumentation(context: vscode.ExtensionContext): Promise<OpcodeIndex> { | ||
const filepath = vscode.Uri.joinPath(context.extensionUri, "snippets", "amalgam.snippets.json"); | ||
const data = await vscode.workspace.fs.readFile(filepath); | ||
const decoder = new TextDecoder("utf-8"); | ||
try { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const document: Record<string, any> = JSON.parse(decoder.decode(data)); | ||
return Object.entries(document).reduce((map, [key, value]) => { | ||
if (value.description) { | ||
const [parameters, description] = value.description.split(" || ", 2); | ||
map[key] = { | ||
...value.$doc, | ||
parameters, | ||
description, | ||
}; | ||
} | ||
return map; | ||
}, {}); | ||
} catch (reason) { | ||
console.warn("Failed to read Amalgam snippets"); | ||
} | ||
return {}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters