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

Fixes #113 add hook to pretty print code to show in diff in atlascode #114

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

marcellourbani
Copy link

@marcellourbani marcellourbani commented Feb 13, 2025

Fixes / implements #113

@marcellourbani marcellourbani changed the title Issue113 add hook to pretty print code to show in diff in atlascode Fixes #113 add hook to pretty print code to show in diff in atlascode Feb 17, 2025
@bwieger-atlassian-com
Copy link
Collaborator

Reviewing

Copy link
Collaborator

@bwieger-atlassian-com bwieger-atlassian-com left a comment

Choose a reason for hiding this comment

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

@marcellourbani great to see this PR. I may have missed something, but it doesn't look quite complete.

@@ -26,3 +26,15 @@ export const AuthInfoVersionKey = 'authInfoVersion';

export const ATLASCODE_TEST_USER_EMAIL = 'axontest2025@gmail.com';
export const ATLASCODE_TEST_HOST = 'axontest2025.atlassian.net';
export enum CommandContext {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see where this is used.

Copy link
Author

Choose a reason for hiding this comment

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

Same thing you did in commandContext.ts, I'll refactor.

in normalize.ts:

function setCommandContext(key: CommandContext | string, value: any) {
    return commands.executeCommand('setContext', key, value);
}

{
"command": "atlascode.bb.togglediffNormalize",
"group": "navigation",
"when": "isInDiffEditor && resourceScheme == atlascode.bbpr && atlascode:IsNormalizerEnabled"
Copy link
Collaborator

Choose a reason for hiding this comment

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

How is atlascode:IsNormalizerEnabled being set?

Copy link
Author

Choose a reason for hiding this comment

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

in enableDiffNormalize, in normalize.ts:

const enableDiffNormalize = (e?: TextEditor) => {
    const relevant = e?.document.uri.scheme === 'atlascode.bbpr';
    const active = relevant && normalizers.some((n) => n.isRelevant(e.document.uri));
    setCommandContext(CommandContext.IsNormalizerEnabled, active);
};

normalizers are populated by calling the extension API, like in vscode-abaplint:

  if (ext.exports?.registerCodeNormalizer) {
    const norm = getAbapCodeNormalizer(client);
    integrationIsActive = (u) => u.scheme === ATLASCODEDIFF && norm.isRelevant(u);
    ext.exports.registerCodeNormalizer(norm);
  }

Copy link
Author

Choose a reason for hiding this comment

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

It's set in enableDiffNormalize (see normalize.ts):

const enableDiffNormalize = (e?: TextEditor) => {
    const relevant = e?.document.uri.scheme === 'atlascode.bbpr';
    const active = relevant && normalizers.some((n) => n.isRelevant(e.document.uri));
    setCommandContext(CommandContext.IsNormalizerEnabled, active);
};

this only happens if a normalizer is registered, as for instance vscode-abaplint

  if (ext.exports?.registerCodeNormalizer) {
    const norm = getAbapCodeNormalizer(client);
    integrationIsActive = (u) => u.scheme === ATLASCODEDIFF && norm.isRelevant(u);
    ext.exports.registerCodeNormalizer(norm);
  }

Copy link
Author

Choose a reason for hiding this comment

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

To explain better, I created a public repo with a PR here:
image
becomes:
image

abaplint always has the normalizer, but with this can be enabled by default, as normalization is run by bitbucket

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