vscode-uri#Utils TypeScript Examples
The following examples show how to use
vscode-uri#Utils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: fileProvider.ts From macro-executor with MIT License | 6 votes |
public resolveReference(ref: string): string | undefined {
if (ref.startsWith('file:///')) {
return ref;
}
let absolutPath = ref;
if (!path.isAbsolute(ref)) {
absolutPath = Utils.resolvePath(URI.parse(this.workspaceFolder), ref).fsPath;
}
absolutPath = this.resolvePathCaseSensitive(absolutPath)
return absolutPath ? URI.file(absolutPath).toString() :undefined;
}
Example #2
Source File: dafnyInstallation.ts From ide-vscode with MIT License | 5 votes |
private async installFromSource() {
const installationPath = this.getCustomInstallationPath(os.arch());
await mkdirAsync(installationPath.fsPath, { recursive: true });
this.writeStatus(`Installing Dafny from source in ${installationPath.fsPath}.\n`);
const previousDirectory = processCwd();
processChdir(installationPath.fsPath);
try {
await this.execLog('brew install dotnet-sdk');
} catch(error: unknown) {
this.writeStatus('If you got `brew: command not found`, but brew is installed on your system, please add all brew commands to your ~/.zprofile, e.g. https://apple.stackexchange.com/a/430904 and reinstall Dafny.');
return false;
}
try {
const result = (await this.execLog('javac -version')).stdout;
if(!(/javac \d+\.\d+/.exec(result))) {
throw '';
}
} catch(error: unknown) {
const errorMsg = error === '' ? 'Javac not found' : `${error}`;
this.writeStatus(`${errorMsg}. Please install a valid JDK`
+ ' and ensure that the path containing javac is in the PATH environment variable. '
+ 'You can obtain a free open-source JDK 1.8 from here: '
+ 'https://aws.amazon.com/corretto/');
return false;
}
await this.execLog(`git clone --recurse-submodules ${LanguageServerConstants.DafnyGitUrl}`);
processChdir(Utils.joinPath(installationPath, 'dafny').fsPath);
await this.execLog('git fetch --all --tags');
await this.execLog(`git checkout v${getConfiguredVersion()}`);
await this.execLog('make exe');
const binaries = Utils.joinPath(installationPath, 'dafny', 'Binaries').fsPath;
processChdir(binaries);
await this.execLog('brew install wget');
const z3urlOsx = this.GetZ3DownloadUrlOSX();
const z3filenameOsx = this.GetZ3FileNameOSX();
await this.execLog(`wget ${z3urlOsx}`);
await this.execLog(`unzip ${z3filenameOsx}.zip`);
await this.execLog(`mv ${z3filenameOsx} z3`);
processChdir(this.getInstallationPath().fsPath);
await this.execLog(`cp -R ${binaries}/* ./dafny/`);
processChdir(previousDirectory);
return true;
}
Example #3
Source File: dafnyInstallation.ts From ide-vscode with MIT License | 5 votes |
private getZipPath(): Uri {
return Utils.joinPath(this.getInstallationPath(), ArchiveFileName);
}
Example #4
Source File: dafnyInstallation.ts From ide-vscode with MIT License | 5 votes |
private getInstallationPath(): Uri {
return Utils.joinPath(
this.context.extensionUri,
...LanguageServerConstants.GetResourceFolder(getConfiguredVersion())
);
}
Example #5
Source File: dafnyInstallation.ts From ide-vscode with MIT License | 5 votes |
private getCustomInstallationPath(typeArch: string): Uri {
return Utils.joinPath(
this.getInstallationPath(), 'custom', typeArch
);
}
Example #6
Source File: extension.ts From markmap-vscode with MIT License | 5 votes |
private resolveAssetPath(relPath: string) {
return Utils.joinPath(this.context.extensionUri, relPath);
}
Example #7
Source File: extension.ts From markmap-vscode with MIT License | 4 votes |
public async resolveCustomTextEditor(
document: TextDocument,
webviewPanel: WebviewPanel,
token: CancellationToken,
): Promise<void> {
webviewPanel.webview.options = {
enableScripts: true,
};
const jsUri = webviewPanel.webview.asWebviewUri(this.resolveAssetPath(LOCAL_ASSETS.js.app));
const cssUri = webviewPanel.webview.asWebviewUri(this.resolveAssetPath(LOCAL_ASSETS.css.app));
const toolbarJs = webviewPanel.webview.asWebviewUri(this.resolveAssetPath(LOCAL_ASSETS.js.toolbar));
const toolbarCss = webviewPanel.webview.asWebviewUri(this.resolveAssetPath(LOCAL_ASSETS.css.toolbar));
const baseJs: JSItem[] = [
webviewPanel.webview.asWebviewUri(this.resolveAssetPath(LOCAL_ASSETS.js.d3)),
webviewPanel.webview.asWebviewUri(this.resolveAssetPath(LOCAL_ASSETS.js.markmapView)),
].map(uri => ({ type: 'script', data: { src: uri.toString() } }));
let allAssets = transformer.getAssets();
allAssets = {
styles: [
...allAssets.styles || [],
{
type: 'stylesheet',
data: {
href: toolbarCss.toString(),
},
},
{
type: 'stylesheet',
data: {
href: cssUri.toString(),
},
},
],
scripts: [
...allAssets.scripts || [],
{
type: 'script',
data: {
src: toolbarJs.toString(),
},
},
{
type: 'script',
data: {
src: jsUri.toString(),
},
},
],
};
webviewPanel.webview.html = fillTemplate(undefined, allAssets, {
baseJs,
});
const updateCursor = () => {
const editor = vscodeWindow.activeTextEditor;
if (editor?.document === document) {
webviewPanel.webview.postMessage({
type: 'setCursor',
data: editor.selection.active.line,
});
}
};
let defaultOptions: IMarkmapJSONOptions;
let customCSS: string;
const updateOptions = () => {
const raw = workspace.getConfiguration('markmap').get<string>('defaultOptions');
try {
defaultOptions = raw && JSON.parse(raw);
} catch {
defaultOptions = null;
}
update();
};
const updateCSS = () => {
customCSS = workspace.getConfiguration('markmap').get<string>('customCSS');
webviewPanel.webview.postMessage({
type: 'setCSS',
data: customCSS,
});
};
const update = () => {
const md = document.getText();
const { root, frontmatter } = transformer.transform(md);
webviewPanel.webview.postMessage({
type: 'setData',
data: {
root,
jsonOptions: {
...defaultOptions,
...(frontmatter as any)?.markmap,
},
},
});
updateCursor();
};
const debouncedUpdateCursor = debounce(updateCursor, 300);
const debouncedUpdate = debounce(update, 300);
const messageHandlers: { [key: string]: (data?: any) => void } = {
refresh: update,
editAsText: () => {
vscodeWindow.showTextDocument(document, {
viewColumn: ViewColumn.Beside,
});
},
exportAsHtml: async () => {
const targetUri = await vscodeWindow.showSaveDialog({
saveLabel: 'Export',
filters: {
HTML: ['html'],
},
});
if (!targetUri) return;
const md = document.getText();
const { root, features, frontmatter } = transformer.transform(md);
const jsonOptions = {
...defaultOptions,
...(frontmatter as any)?.markmap,
};
const { embedAssets } = jsonOptions as { embedAssets?: boolean };
let assets = transformer.getUsedAssets(features);
assets = {
styles: [
...assets.styles || [],
embedAssets ? {
type: 'style',
data: await this.loadAsset(LOCAL_ASSETS.css.toolbar),
} : {
type: 'stylesheet',
data: {
href: TOOLBAR_CSS,
},
},
...customCSS ? [
{
type: 'style',
data: customCSS,
} as CSSItem,
] : [],
],
scripts: [
...assets.scripts || [],
{
type: 'script',
data: embedAssets ? {
textContent: await this.loadAsset(LOCAL_ASSETS.js.toolbar),
} : {
src: TOOLBAR_JS,
},
},
{
type: 'iife',
data: {
fn: (r: typeof renderToolbar) => {
setTimeout(r);
},
getParams: () => [renderToolbar],
},
},
],
};
const extra = {
jsonOptions,
} as Parameters<typeof fillTemplate>[2];
if (embedAssets) {
extra.baseJs = (await Promise.all([
this.loadAsset(LOCAL_ASSETS.js.d3),
this.loadAsset(LOCAL_ASSETS.js.markmapView),
])).map(textContent => ({
type: 'script',
data: {
textContent,
},
}));
}
const html = fillTemplate(root, assets, extra);
const encoder = new TextEncoder();
const data = encoder.encode(html);
try {
await workspace.fs.writeFile(targetUri, data);
} catch (e) {
vscodeWindow.showErrorMessage(`Cannot write file "${targetUri.toString()}"!`);
}
},
openFile(relPath: string) {
const filePath = Utils.joinPath(Utils.dirname(document.uri), relPath);
commands.executeCommand(
'vscode.open',
filePath,
);
},
};
// const logger = vscodeWindow.createOutputChannel('Markmap');
// messageHandlers.log = (data: string) => {
// logger.appendLine(data);
// };
webviewPanel.webview.onDidReceiveMessage(e => {
const handler = messageHandlers[e.type];
handler?.(e.data);
});
workspace.onDidChangeTextDocument(e => {
if (e.document === document) {
debouncedUpdate();
}
});
vscodeWindow.onDidChangeTextEditorSelection(() => {
debouncedUpdateCursor();
});
updateOptions();
updateCSS();
workspace.onDidChangeConfiguration(e => {
if (e.affectsConfiguration('markmap.defaultOptions')) updateOptions();
if (e.affectsConfiguration('markmap.customCSS')) updateCSS();
});
}