Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Preview Support #31

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

2016bgeyer
Copy link

  • Added support for automatically opening the ANSI Text preview when opening an ANSI file. This is now enabled by default
  • Added configuration options in extension settings allowing the user to control that behavior via autoPreview and autoPreviewToSide

Solves #26

@@ -3,7 +3,7 @@
"publisher": "iliazeus",
"displayName": "ANSI Colors",
"description": "ANSI color styling for text documents",
"version": "1.1.7",
"version": "1.1.8",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider it a minor-version-worthy change.

Suggested change
"version": "1.1.8",
"version": "1.2.0",

@@ -26,7 +26,9 @@
"colors",
"logs"
],
"activationEvents": [],
"activationEvents": [
"onStartupFinished"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I specifically do not want the extension activating on every startup. Is this activation event really needed?

"properties": {
"iliazeus.vscode-ansi.autoPreview": {
"type": "boolean",
"default": true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"default": true,
"default": false,

We should not break the existing behavior.

"iliazeus.vscode-ansi.autoPreviewToSide": {
"type": "boolean",
"default": false,
"description": "If Auto Preview is set to True: Automatically open the ANSI Text Preview to the side. Warning: This can cause undesirable behavior!"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain what this undesirable behavior is? Maybe we can fix it, or just don't include this specific option.

"dependencies": {}
}
"dependencies": {
"yarn": "^1.22.22"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repo assumes yarn is installed globally, same as npm in most (current) node projects. This explicit dependency should be removed.

const showPretty = async (forcePreview: boolean = false, options: TextDocumentShowOptions = { viewColumn: ViewColumn.Active}) => {
if (forcePreview || workspace.getConfiguration(`${extensionId}`).autoPreview) {
const editor = window.activeTextEditor
if (editor && editor.document && editor.document.languageId === 'ansi' && editor.document.uri.scheme === 'file') {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd change the logic from "only file scheme" to "every non-ours scheme". This will make it integrate better with other extensions, e.g. with the "view file at revision" feature of GitLens.

@@ -29,23 +30,25 @@ export async function activate(context: ExtensionContext): Promise<void> {
workspace.registerTextDocumentContentProvider(PrettyAnsiContentProvider.scheme, prettyAnsiContentProvider)
);

const showPretty = async (options?: TextDocumentShowOptions) => {
const actualUri = window.activeTextEditor?.document.uri;
const showPretty = async (forcePreview: boolean = false, options: TextDocumentShowOptions = { viewColumn: ViewColumn.Active}) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am against positional boolean parameters, because they are difficult to understand at call site (i.e. what does true in doThing(true) even mean?)

I'd change this to something more like showPretty({ viewColumn: ..., forcePreview: true }).

}

const providerUri = PrettyAnsiContentProvider.toProviderUri(actualUri);
const autoPreviewToSide = workspace.getConfiguration(`${extensionId}`).autoPreviewToSide;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const autoPreviewToSide = workspace.getConfiguration(`${extensionId}`).autoPreviewToSide;
const autoPreviewToSide = workspace.getConfiguration(extensionId).autoPreviewToSide;

This template literal is unnecessary.

Comment on lines +74 to +78
window.onDidChangeActiveTextEditor((textEditor: TextEditor | undefined) => {
showPretty();
});

showPretty();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why we need this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants