-
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.
Merge pull request #17 from Shresht7:issue14
Add commands to generate version numbers. Fixes #14
- Loading branch information
Showing
7 changed files
with
136 additions
and
19 deletions.
There are no files selected for viewing
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,46 @@ | ||
// Library | ||
import * as vscode from 'vscode'; | ||
|
||
// Helpers | ||
import { bg3, editor } from '../helpers'; | ||
|
||
/** Convert Int64 version number to string format or vice-versa */ | ||
export async function convertVersionNumber() { | ||
|
||
// Prompt the user for the version number | ||
const v = await vscode.window.showInputBox({ | ||
title: "Version", | ||
prompt: "Version Number", | ||
placeHolder: 'Example: 1.0.0.0 or 36028797018963968', | ||
|
||
// Pre-fill the value with the currently selected text | ||
value: editor.getSelection(), | ||
|
||
// Perform validation on the input value | ||
validateInput: (value) => { | ||
if (value.includes(".")) { // String version format (1.0.0.0) | ||
if (!(/\d+\.\d+\.\d+\.\d+/.test(value))) { // Try parsing major.minor.revision.build | ||
return "Invalid Version Number! Format: {Major}.{Minor}.{Revision}.{Build}"; | ||
} | ||
} else { // BigInt format (36028797018963968) | ||
try { | ||
BigInt(value); // Try parsing as BigInt ... | ||
} catch (e) { // ... if that fails, the input is invalid as it doesn't match either format | ||
return "Invalid Version Number! Example: 1.0.0.0 or 36028797018963968"; | ||
} | ||
} | ||
} | ||
}); | ||
|
||
// Return early if the input is empty | ||
if (!v) { return; } | ||
|
||
// Convert the version from one format to the other | ||
const result = v.includes(".") | ||
? new bg3.Version(v).toInt64().toString() | ||
: new bg3.Version(BigInt(v)).toString(); | ||
|
||
// Insert the version at the cursor selection | ||
editor.insertAtSelection(result); | ||
|
||
} |
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 |
---|---|---|
@@ -1,21 +1,23 @@ | ||
// Library | ||
import * as vscode from 'vscode'; | ||
import * as constants from '../constants'; | ||
|
||
// ======== | ||
// COMMANDS | ||
// ======== | ||
|
||
import { generateUUID } from "./generateUUID"; | ||
import { generateHandle } from './generateHandle'; | ||
import { convertVersionNumber } from './convertVersionNumber'; | ||
|
||
/** Enumeration of the command IDs */ | ||
enum Command { | ||
GenerateUUID = "bg3-modding.generateUUID", | ||
GenerateHandle = "bg3-modding.generateHandle", | ||
/** Registers the command to VS Code */ | ||
function registerCommand(command: (...args: any[]) => any): vscode.Disposable { | ||
return vscode.commands.registerCommand(`${constants.EXTENSION_ID}.${command.name}`, command); | ||
} | ||
|
||
/** An array of disposables for the registered commands */ | ||
export const commands: vscode.Disposable[] = [ | ||
vscode.commands.registerCommand(Command.GenerateUUID, generateUUID), | ||
vscode.commands.registerCommand(Command.GenerateHandle, generateHandle) | ||
registerCommand(generateUUID), | ||
registerCommand(generateHandle), | ||
registerCommand(convertVersionNumber), | ||
]; |
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,6 @@ | ||
// ========= | ||
// CONSTANTS | ||
// ========= | ||
|
||
/** ID of the extension. Must match the `package.json` */ | ||
export const EXTENSION_ID = "bg3-modding"; |
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