Ver código fonte

Cleans up annotations a bit

main
Eric Amodio 5 anos atrás
pai
commit
00d3ee0c9e
4 arquivos alterados com 101 adições e 149 exclusões
  1. +78
    -127
      src/annotations/annotations.ts
  2. +11
    -8
      src/annotations/blameAnnotationProvider.ts
  3. +5
    -6
      src/annotations/recentChangesAnnotationProvider.ts
  4. +7
    -8
      src/hovers/lineHoverController.ts

+ 78
- 127
src/annotations/annotations.ts Ver arquivo

@ -17,13 +17,11 @@ import {
GitBlameCommit,
GitCommit,
GitDiffHunkLine,
GitRemote,
GitService,
GitUri
} from '../git/gitService';
import { Objects, Strings } from '../system';
import { toRgba } from '../webviews/apps/shared/colors';
import { ContactPresence } from '../vsls/vsls';
export interface ComputedHeatmap {
cold: boolean;
@ -61,55 +59,37 @@ export class Annotations {
decoration.renderOptions!.before!.borderColor = color;
}
private static getHeatmapColor(date: Date, heatmap: ComputedHeatmap) {
const baseColor = heatmap.cold ? heatmap.colors.cold : heatmap.colors.hot;
const age = heatmap.computeAge(date);
if (age === 0) return baseColor;
if (computedHeatmapColor === undefined || computedHeatmapColor.color !== baseColor) {
let rgba = toRgba(baseColor);
if (rgba == null) {
rgba = toRgba(heatmap.cold ? defaultHeatmapColdColor : defaultHeatmapHotColor)!;
static async changesHoverMessage(
commit: GitBlameCommit,
uri: GitUri,
editorLine: number
): Promise<MarkdownString | undefined> {
let ref;
if (commit.isUncommitted) {
if (uri.sha !== undefined && GitService.isUncommittedStaged(uri.sha)) {
ref = uri.sha;
}
const [r, g, b] = rgba;
computedHeatmapColor = {
color: baseColor,
rgb: `${r}, ${g}, ${b}`
};
}
else {
ref = commit.sha;
}
return `rgba(${computedHeatmapColor.rgb}, ${(1 - age / 10).toFixed(2)})`;
}
const line = editorLine + 1;
const commitLine = commit.lines.find(l => l.line === line) || commit.lines[0];
static getHoverMessage(
commit: GitCommit,
dateFormat: string | null,
presence: ContactPresence | undefined,
remotes: GitRemote[],
annotationType?: FileAnnotationType,
line: number = 0
): MarkdownString {
if (dateFormat === null) {
dateFormat = 'MMMM Do, YYYY h:mma';
let originalFileName = commit.originalFileName;
if (originalFileName === undefined) {
if (uri.fsPath !== commit.uri.fsPath) {
originalFileName = commit.fileName;
}
}
const markdown = new MarkdownString(
CommitFormatter.fromTemplate(Container.config.hovers.detailsMarkdownFormat, commit, {
annotationType: annotationType,
dateFormat: dateFormat,
line: line,
markdown: true,
presence: presence,
remotes: remotes
})
);
markdown.isTrusted = true;
return markdown;
const commitEditorLine = commitLine.originalLine - 1;
const hunkLine = await Container.git.getDiffForLine(uri, commitEditorLine, ref, undefined, originalFileName);
return this.changesHoverDiffMessage(commit, uri, hunkLine, commitEditorLine);
}
static getHoverDiffMessage(
static changesHoverDiffMessage(
commit: GitCommit,
uri: GitUri,
hunkLine: GitDiffHunkLine | undefined,
@ -156,57 +136,36 @@ export class Annotations {
return markdown;
}
private static getDiffFromHunkLine(hunkLine: GitDiffHunkLine): string {
if (Container.config.hovers.changesDiff === 'hunk') {
return `\`\`\`diff\n${hunkLine.hunk.diff}\n\`\`\``;
}
return `\`\`\`diff${hunkLine.previous === undefined ? '' : `\n-${hunkLine.previous.line}`}${
hunkLine.current === undefined ? '' : `\n+${hunkLine.current.line}`
}\n\`\`\``;
}
static async changesHover(
commit: GitBlameCommit,
static async detailsHoverMessage(
commit: GitCommit,
uri: GitUri,
editorLine: number,
uri: GitUri
): Promise<Partial<DecorationOptions>> {
let ref;
if (commit.isUncommitted) {
if (uri.sha !== undefined && GitService.isUncommittedStaged(uri.sha)) {
ref = uri.sha;
}
}
else {
ref = commit.sha;
}
const line = editorLine + 1;
const commitLine = commit.lines.find(l => l.line === line) || commit.lines[0];
let originalFileName = commit.originalFileName;
if (originalFileName === undefined) {
if (uri.fsPath !== commit.uri.fsPath) {
originalFileName = commit.fileName;
}
dateFormat: string | null,
annotationType?: FileAnnotationType
): Promise<MarkdownString> {
if (dateFormat === null) {
dateFormat = 'MMMM Do, YYYY h:mma';
}
const commitEditorLine = commitLine.originalLine - 1;
const hunkLine = await Container.git.getDiffForLine(uri, commitEditorLine, ref, undefined, originalFileName);
const message = this.getHoverDiffMessage(commit, uri, hunkLine, commitEditorLine);
const [presence, remotes] = await Promise.all([
Container.vsls.getContactPresence(commit.email),
Container.git.getRemotes(commit.repoPath)
]);
return {
hoverMessage: message
};
const markdown = new MarkdownString(
CommitFormatter.fromTemplate(Container.config.hovers.detailsMarkdownFormat, commit, {
annotationType: annotationType,
dateFormat: dateFormat,
line: editorLine,
markdown: true,
presence: presence,
remotes: remotes
})
);
markdown.isTrusted = true;
return markdown;
}
// static detailsHover(commit: GitCommit, dateFormat: string | null, hasRemote: boolean, annotationType?: FileAnnotationType, line: number = 0): DecorationOptions {
// const message = this.getHoverMessage(commit, dateFormat, hasRemote, annotationType);
// return {
// hoverMessage: message
// } as DecorationOptions;
// }
static gutter(
commit: GitCommit,
format: string,
@ -314,29 +273,6 @@ export class Annotations {
};
}
// static hover(commit: GitCommit, renderOptions: IRenderOptions, now: number): DecorationOptions {
// const decoration = {
// renderOptions: { before: { ...renderOptions } }
// } as DecorationOptions;
// this.applyHeatmap(decoration, commit.date, now);
// return decoration;
// }
// static hoverRenderOptions(heatmap: HeatmapConfig): IRenderOptions {
// if (!heatmap.enabled) return { before: undefined };
// return {
// borderStyle: 'solid',
// borderWidth: '0 0 0 2px',
// contentText: GlyphChars.ZeroWidthSpace,
// height: '100%',
// margin: '0 26px 0 0',
// textDecoration: 'none'
// } as IRenderOptions;
// }
static trailing(
commit: GitCommit,
format: string,
@ -363,20 +299,35 @@ export class Annotations {
};
}
// static withRange(decoration: DecorationOptions, start?: number, end?: number): DecorationOptions {
// let range = decoration.range;
// if (start !== undefined) {
// range = range.with({
// start: range.start.with({ character: start })
// });
// }
// if (end !== undefined) {
// range = range.with({
// end: range.end.with({ character: end })
// });
// }
// return { ...decoration, range: range };
// }
private static getDiffFromHunkLine(hunkLine: GitDiffHunkLine): string {
if (Container.config.hovers.changesDiff === 'hunk') {
return `\`\`\`diff\n${hunkLine.hunk.diff}\n\`\`\``;
}
return `\`\`\`diff${hunkLine.previous === undefined ? '' : `\n-${hunkLine.previous.line}`}${
hunkLine.current === undefined ? '' : `\n+${hunkLine.current.line}`
}\n\`\`\``;
}
private static getHeatmapColor(date: Date, heatmap: ComputedHeatmap) {
const baseColor = heatmap.cold ? heatmap.colors.cold : heatmap.colors.hot;
const age = heatmap.computeAge(date);
if (age === 0) return baseColor;
if (computedHeatmapColor === undefined || computedHeatmapColor.color !== baseColor) {
let rgba = toRgba(baseColor);
if (rgba == null) {
rgba = toRgba(heatmap.cold ? defaultHeatmapColdColor : defaultHeatmapHotColor)!;
}
const [r, g, b] = rgba;
computedHeatmapColor = {
color: baseColor,
rgb: `${r}, ${g}, ${b}`
};
}
return `rgba(${computedHeatmapColor.rgb}, ${(1 - age / 10).toFixed(2)})`;
}
}

+ 11
- 8
src/annotations/blameAnnotationProvider.ts Ver arquivo

@ -234,13 +234,12 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
const commitLine = commit.lines.find(l => l.line === line) || commit.lines[0];
editorLine = commitLine.originalLine - 1;
const message = Annotations.getHoverMessage(
const message = await Annotations.detailsHoverMessage(
logCommit || commit,
await GitUri.fromUri(document.uri),
editorLine,
Container.config.defaultDateFormat,
await Container.vsls.getContactPresence(commit.email),
await Container.git.getRemotes(commit.repoPath),
this.annotationType,
editorLine
this.annotationType
);
return new Hover(
message,
@ -256,11 +255,15 @@ export abstract class BlameAnnotationProviderBase extends AnnotationProviderBase
const commit = await this.getCommitForHover(position);
if (commit === undefined) return undefined;
const hover = await Annotations.changesHover(commit, position.line, await GitUri.fromUri(document.uri));
if (hover.hoverMessage === undefined) return undefined;
const message = await Annotations.changesHoverMessage(
commit,
await GitUri.fromUri(document.uri),
position.line
);
if (message === undefined) return undefined;
return new Hover(
hover.hoverMessage,
message,
document.validateRange(new Range(position.line, 0, position.line, Number.MAX_SAFE_INTEGER))
);
}

+ 5
- 6
src/annotations/recentChangesAnnotationProvider.ts Ver arquivo

@ -61,20 +61,19 @@ export class RecentChangesAnnotationProvider extends AnnotationProviderBase {
if (cfg.hovers.enabled && cfg.hovers.annotations.enabled) {
if (cfg.hovers.annotations.details) {
this.decorations.push({
hoverMessage: Annotations.getHoverMessage(
hoverMessage: await Annotations.detailsHoverMessage(
commit,
await GitUri.fromUri(this.editor.document.uri),
count,
dateFormat,
await Container.vsls.getContactPresence(commit.email),
await Container.git.getRemotes(commit.repoPath),
this.annotationType,
count
this.annotationType
),
range: range
});
}
if (cfg.hovers.annotations.changes) {
message = Annotations.getHoverDiffMessage(commit, this._uri, hunkLine, count);
message = Annotations.changesHoverDiffMessage(commit, this._uri, hunkLine, count);
if (message === undefined) continue;
}
}

+ 7
- 8
src/hovers/lineHoverController.ts Ver arquivo

@ -121,13 +121,12 @@ export class LineHoverController implements Disposable {
const trackedDocument = await Container.tracker.get(document);
if (trackedDocument === undefined) return undefined;
const message = Annotations.getHoverMessage(
const message = await Annotations.detailsHoverMessage(
logCommit || commit,
trackedDocument.uri,
editorLine,
Container.config.defaultDateFormat,
await Container.vsls.getContactPresence(commit.email),
await Container.git.getRemotes(commit.repoPath),
fileAnnotations,
editorLine
fileAnnotations
);
return new Hover(message, range);
}
@ -161,10 +160,10 @@ export class LineHoverController implements Disposable {
const trackedDocument = await Container.tracker.get(document);
if (trackedDocument === undefined) return undefined;
const hover = await Annotations.changesHover(commit, position.line, trackedDocument.uri);
if (hover.hoverMessage === undefined) return undefined;
const message = await Annotations.changesHoverMessage(commit, trackedDocument.uri, position.line);
if (message === undefined) return undefined;
return new Hover(hover.hoverMessage, range);
return new Hover(message, range);
}
private register(editor: TextEditor | undefined) {

Carregando…
Cancelar
Salvar