Applies to :
PowerDocs for Linux
PowerDocs for Windows
Class `Env`
The Env class (accessed via context.env) provides host environment integration and utility functions for extensions, including external URL launching, system clipboard manipulation, and diagnostic logging into PowerDocs logs.
Properties
Env does not expose public properties.
Methods
openUrl(url)
Opens a URL in the user's default system web browser. Cross-platform support is provided for Linux (xdg-open), macOS (open), and Windows.
Parameters
url(string): The destination URL (e.g.'https://google.com').
setClipboard(text)
Copies the specified string to the operating system clipboard.
Parameters
text(string): The text to copy.
log(message) / logInfo(message)
Writes an informational diagnostic message to the application log stream (Serilog).
Parameters
message(any): The message or object to log.
logWarn(message)
Writes a warning message to the application log stream.
Parameters
message(any): The warning message to log.
logError(message)
Writes an error message to the application log stream.
Parameters
message(any): The error message to log.
Examples
1. Clipboard Copy Action with Diagnostic Logging
export function activate(context) {
context.editor.registerSelectionAction({
id: 'copy-markdown-link',
title: 'Copy as Markdown Link',
icon: 'Link',
execute: (selection) => {
const text = selection.text.trim();
const mdLink = `[${text}](https://example.com/search?q=${encodeURIComponent(text)})`;
context.env.setClipboard(mdLink);
context.env.log(`Copied Markdown link to clipboard for: ${text}`);
}
});
}
2. Opening Documentation URL
export function activate(context) {
context.editor.registerSelectionAction({
id: 'lookup-docs',
title: 'Open in DevDocs',
icon: 'Book',
execute: (selection) => {
const query = encodeURIComponent(selection.text.trim());
context.env.openUrl(`https://devdocs.io/#q=${query}`);
}
});
}