Skip to content

Commit

Permalink
mrcrowl#117: config value for line annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
incidentist committed Dec 29, 2021
1 parent 22fe33f commit 00c5604
Showing 5 changed files with 43 additions and 5 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -38,6 +38,8 @@

- Rebase support.

- Show annotation for current line

# Feedback & Contributing

- Please report any bugs, suggestions or documentation requests via the [Github issues](https://github.com/mrcrowl/vscode-hg/issues) (_yes_, I see the irony).
@@ -135,6 +137,9 @@
`"cli"` — spawn a new `hg` process per command (default).
`"server"` — run a command server process  _i.e. `hg serve --cmdserve`_

`hg.annotationEnabled`
- Enables annotation decorations at end of lines

# Acknowledgements

[ajansveld](https://github.com/ajansveld), [hoffmael](https://github.com/hoffmael), [nioh-wiki](https://github.com/nioh-wiki), [joaomoreno](https://github.com/joaomoreno), [nsgundy](https://github.com/nsgundy)
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -975,6 +975,11 @@
"%config.pushPullScope.default%"
],
"default": "all"
},
"hg.lineAnnotationEnabled": {
"type": "boolean",
"description": "%config.lineAnnotationEnabled%",
"default": false
}
}
},
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
@@ -78,5 +78,6 @@
"config.pushPullScope.all": "All branches / bookmarks",
"config.pushPullScope.current": "Only the current branch / bookmark",
"config.pushPullScope.default": "Only the default branch / bookmarks on the default branch",
"config.useBookmarks": "Use bookmarks instead of branches"
"config.useBookmarks": "Use bookmarks instead of branches",
"config.lineAnnotationEnabled": "Show annotation at the end of the line"
}
31 changes: 27 additions & 4 deletions src/annotations.ts
Original file line number Diff line number Diff line change
@@ -15,10 +15,13 @@ import {
TextEditorSelectionChangeEvent,
TextDocument,
ThemeColor,
workspace,
ConfigurationChangeEvent,
} from "vscode";
import { Hg, ILineAnnotation } from "./hg";
import { Model } from "./model";
import { Repository } from "./repository";
import typedConfig from "./config";

const annotationDecoration: TextEditorDecorationType = window.createTextEditorDecorationType(
{
@@ -36,14 +39,35 @@ const annotationDecoration: TextEditorDecorationType = window.createTextEditorDe

export class LineTracker<T> extends Disposable {
private disposable: Disposable | undefined;
private configDisposable: Disposable;
private hg: Hg;
private model: Model;

constructor(hg: Hg, model: Model) {
super(() => this.dispose());
this.hg = hg;
this.model = model;
this.start();
this.configDisposable = Disposable.from(
workspace.onDidChangeConfiguration(
this.onConfigurationChanged,
this
)
);
this.applyConfiguration();
}

onConfigurationChanged(e: ConfigurationChangeEvent): void {
if (e.affectsConfiguration("hg")) {
this.applyConfiguration();
}
}

applyConfiguration(): void {
if (typedConfig.lineAnnotationEnabled) {
this.start();
} else {
this.stop();
}
}

async diffHeadAndEditorContents(
@@ -150,6 +174,7 @@ export class LineTracker<T> extends Disposable {

dispose(): void {
this.stop();
this.configDisposable.dispose();
}
start(): void {
this.disposable = Disposable.from(
@@ -160,9 +185,7 @@ export class LineTracker<T> extends Disposable {
);
}
stop(): void {
if (this.disposable) {
this.disposable.dispose();
}
this.disposable?.dispose();
this.disposable = undefined;
}
}
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -83,6 +83,10 @@ class Config {
this.pushPullScope
);
}

get lineAnnotationEnabled(): boolean {
return this.get("lineAnnotationEnabled", true);
}
}

const typedConfig = new Config();

0 comments on commit 00c5604

Please sign in to comment.