-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add custom template in 'New Script' wizard
Signed-off-by: Fred Bricon <[email protected]>
- Loading branch information
Showing
10 changed files
with
214 additions
and
26 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,15 @@ | ||
import path = require("path"); | ||
import { ExtensionContext, Uri } from "vscode"; | ||
|
||
export namespace Assets { | ||
|
||
let extensionPath: string; | ||
|
||
export function initialize(extensionContext: ExtensionContext) { | ||
extensionPath = extensionContext.extensionPath; | ||
} | ||
|
||
export function get(assetName: string): Uri { | ||
return Uri.file(path.join(extensionPath, 'assets', assetName)); | ||
} | ||
} |
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,35 @@ | ||
import { ConfigurationTarget, workspace, WorkspaceConfiguration } from "vscode"; | ||
|
||
export namespace JBangConfig { | ||
|
||
export const SHOW_TEMPLATE_DESC = 'wizard.templates.showDescriptions'; | ||
export const HOME = 'home'; | ||
|
||
export function isShowTemplateDescriptions(): boolean { | ||
return getJBangConfiguration().get<boolean>(SHOW_TEMPLATE_DESC, true); | ||
} | ||
|
||
export function getJBangHome(): string|undefined { | ||
return (getJBangConfiguration().get(HOME) as string|undefined)?.trim(); | ||
} | ||
|
||
export function getJBangConfiguration(): WorkspaceConfiguration { | ||
return workspace.getConfiguration('jbang'); | ||
} | ||
|
||
export function setShowTemplateDescriptions(value: boolean): Thenable<void> { | ||
return setJBangConfig(SHOW_TEMPLATE_DESC, value); | ||
} | ||
|
||
export function setJBangConfig<T>(configName: string, value: T): Thenable<void> { | ||
const info = getJBangConfiguration().inspect(configName); | ||
let scope = ConfigurationTarget.Global; | ||
if (info?.workspaceValue !== undefined) { | ||
scope = ConfigurationTarget.Workspace | ||
} else if (info?.workspaceFolderValue !== undefined) { | ||
scope = ConfigurationTarget.WorkspaceFolder; | ||
} | ||
return getJBangConfiguration().update(configName, value, scope); | ||
} | ||
} | ||
|
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,7 +1,27 @@ | ||
import path = require('path'); | ||
import * as os from 'os'; | ||
import { workspace, WorkspaceConfiguration } from 'vscode'; | ||
import { JBangConfig } from './JBangConfig'; | ||
|
||
function isWin():boolean { | ||
return /^win/.test(process.platform); | ||
} | ||
|
||
export function jbang():string { | ||
return isWin()?"jbang.cmd":"jbang"; | ||
let home = JBangConfig.getJBangHome(); | ||
let dir = ""; | ||
if (home) { | ||
if (home.startsWith('~')) { | ||
home = path.resolve(os.homedir() , home.substring(2, home.length)); | ||
} | ||
dir = path.resolve(home, 'bin'); | ||
} | ||
const jbangExec = (isWin()?"jbang.cmd":"jbang"); | ||
const fullPath = path.resolve(dir, jbangExec); | ||
console.log("Using JBang from "+fullPath); | ||
return fullPath; | ||
} | ||
|
||
export function getJBangConfiguration(): WorkspaceConfiguration { | ||
return workspace.getConfiguration('jbang'); | ||
} |
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