coc-git 2.7.1 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/Readme.md +4 -0
  2. package/lib/index.js +68 -41
  3. package/package.json +16 -1
package/Readme.md CHANGED
@@ -50,6 +50,10 @@ In your vim/neovim, run command:
50
50
 
51
51
  - `git.remoteName`: Remote name for fetch github issues., default: `"origin"`
52
52
 
53
+ - `git.diffOptions`: Options for git diff command, eg: `["--ignore-all-space"]`, default: `[]`
54
+
55
+ - `git.foldContext`: Line count to leave below and above the fold, default: `0`.
56
+
53
57
  - `git.browserRemoteName`: Remote name for browserOpen and copyUrl., default: `""`
54
58
 
55
59
  - `git.browserBranchName`: Branch name for browserOpen and copyUrl., default: `""`
package/lib/index.js CHANGED
@@ -4653,7 +4653,7 @@ function spawnCommand(cmd, args, cwd) {
4653
4653
  res += data.toString();
4654
4654
  });
4655
4655
  cp2.stderr.on("data", (data) => {
4656
- import_coc.window.showMessage(`"${cmd} ${args.join(" ")}" error: ${data.toString()}`, "error");
4656
+ import_coc.window.showErrorMessage(`"${cmd} ${args.join(" ")}" error: ${data.toString()}`);
4657
4657
  });
4658
4658
  cp2.on("close", (code) => {
4659
4659
  if (code != 0) {
@@ -4903,7 +4903,7 @@ var CommitsTask = class extends import_events.EventEmitter {
4903
4903
  };
4904
4904
  var Bcommits = class extends import_coc2.BasicList {
4905
4905
  constructor(nvim, manager) {
4906
- super(nvim);
4906
+ super();
4907
4907
  this.manager = manager;
4908
4908
  this.name = "bcommits";
4909
4909
  this.description = "Commits of current file.";
@@ -5158,7 +5158,7 @@ var CommitsTask2 = class extends import_events2.EventEmitter {
5158
5158
  };
5159
5159
  var Commits = class extends import_coc4.BasicList {
5160
5160
  constructor(nvim, manager) {
5161
- super(nvim);
5161
+ super();
5162
5162
  this.manager = manager;
5163
5163
  this.name = "commits";
5164
5164
  this.description = "Commits of current project.";
@@ -5251,7 +5251,7 @@ var Commits = class extends import_coc4.BasicList {
5251
5251
  } else {
5252
5252
  arg = `${list[1].data.commit} ${list[0].data.commit}`;
5253
5253
  }
5254
- let content = await runCommand(`git --no-pager diff --no-ext-diff ${arg}`, { cwd: list[0].data.root });
5254
+ let content = await runCommand(`git --no-pager diff --no-ext-diff ${this.manager.diffOptions.join(" ")} ${arg}`, { cwd: list[0].data.root });
5255
5255
  let lines = content.replace(/\n$/, "").split("\n");
5256
5256
  nvim.pauseNotification();
5257
5257
  nvim.command(`tabe [diff ${arg}]`, true);
@@ -5275,7 +5275,7 @@ var Commits = class extends import_coc4.BasicList {
5275
5275
  } else {
5276
5276
  arg = `${list[1].data.commit} ${list[0].data.commit}`;
5277
5277
  }
5278
- let content = await runCommand(`git --no-pager diff --no-ext-diff ${arg}`, { cwd: list[0].data.root });
5278
+ let content = await runCommand(`git --no-pager diff ${this.manager.diffOptions.join(" ")} --no-ext-diff ${arg}`, { cwd: list[0].data.root });
5279
5279
  let lines = content.replace(/\n$/, "").split("\n");
5280
5280
  let winid = context.listWindow.id;
5281
5281
  let mod = context.options.position == "tab" ? "below" : "above";
@@ -5330,7 +5330,7 @@ var import_coc5 = require("coc.nvim");
5330
5330
  var import_path2 = __toESM(require("path"));
5331
5331
  var Gfiles = class extends import_coc5.BasicList {
5332
5332
  constructor(nvim, manager) {
5333
- super(nvim);
5333
+ super();
5334
5334
  this.manager = manager;
5335
5335
  this.name = "gfiles";
5336
5336
  this.description = "view files on different branches (or commits, or tags)";
@@ -5366,7 +5366,7 @@ var Gfiles = class extends import_coc5.BasicList {
5366
5366
  this.addAction("preview", async (item, context) => {
5367
5367
  let { root, sha, filepath, branch } = item.data;
5368
5368
  if (!sha) return;
5369
- let content = await runCommand(`git --no-pager diff --no-ext-diff ${branch} -- ${shellescape(filepath)}`, { cwd: root });
5369
+ let content = await runCommand(`git --no-pager diff ${this.manager.diffOptions.join(" ")} --no-ext-diff ${branch} -- ${shellescape(filepath)}`, { cwd: root });
5370
5370
  let lines = content.replace(/\n$/, "").split("\n");
5371
5371
  await this.preview({
5372
5372
  lines,
@@ -5423,7 +5423,7 @@ var STATUS_MAP = {
5423
5423
  };
5424
5424
  var GStatus = class extends import_coc6.BasicList {
5425
5425
  constructor(nvim, manager) {
5426
- super(nvim);
5426
+ super();
5427
5427
  this.manager = manager;
5428
5428
  this.name = "gstatus";
5429
5429
  this.description = "Git status of current project";
@@ -5450,7 +5450,7 @@ var GStatus = class extends import_coc6.BasicList {
5450
5450
  try {
5451
5451
  await nvim.command(`G commit -v ${filesArg}`);
5452
5452
  } catch (e) {
5453
- import_coc6.window.showMessage(`G commit command failed, make sure fugitive installed.`, "error");
5453
+ import_coc6.window.showErrorMessage(`G commit command failed, make sure fugitive installed.`);
5454
5454
  }
5455
5455
  });
5456
5456
  this.addAction("reset", async (item) => {
@@ -5494,7 +5494,7 @@ var GStatus = class extends import_coc6.BasicList {
5494
5494
  }, context);
5495
5495
  return;
5496
5496
  }
5497
- let args = ["--no-pager", "diff", "--no-ext-diff"];
5497
+ let args = ["--no-pager", "diff", "--no-ext-diff", ...this.manager.diffOptions];
5498
5498
  if (index_symbol == "M" && tree_symbol != "M") {
5499
5499
  args.push("--cached");
5500
5500
  }
@@ -5817,6 +5817,8 @@ var DocumentManager = class {
5817
5817
  let obj = {
5818
5818
  remoteName: config.get("remoteName", "origin"),
5819
5819
  diffRevision: config.get("diffRevision", ""),
5820
+ foldContext: config.get("foldContext", 0),
5821
+ diffOptions: config.get("diffOptions", []),
5820
5822
  issueFormat: config.get("issueFormat", "#%i"),
5821
5823
  virtualTextPrefix: config.get("virtualTextPrefix", " "),
5822
5824
  addGBlameToVirtualText: config.get("addGBlameToVirtualText", false),
@@ -5871,6 +5873,9 @@ var DocumentManager = class {
5871
5873
  get git() {
5872
5874
  return this.service.git;
5873
5875
  }
5876
+ get diffOptions() {
5877
+ return this.config.diffOptions;
5878
+ }
5874
5879
  async toggleGutters() {
5875
5880
  let enabled = this.enableGutters;
5876
5881
  let config = import_coc10.workspace.getConfiguration("git");
@@ -5978,7 +5983,7 @@ var DocumentManager = class {
5978
5983
  let root = await this.resolveGitRootFromBufferOrCwd(bufnr);
5979
5984
  let extra = this.config.pushArguments;
5980
5985
  if (!root) {
5981
- import_coc10.window.showMessage(`not belongs to git repository.`, "warning");
5986
+ import_coc10.window.showWarningMessage(`not belongs to git repository.`);
5982
5987
  return;
5983
5988
  }
5984
5989
  if (args && args.length) {
@@ -5989,12 +5994,12 @@ var DocumentManager = class {
5989
5994
  let output = await repo.safeRun(["remote"]);
5990
5995
  let remote = output.trim().split(/\r?\n/)[0];
5991
5996
  if (!remote) {
5992
- import_coc10.window.showMessage(`remote not found`, "warning");
5997
+ import_coc10.window.showWarningMessage(`remote not found`);
5993
5998
  return;
5994
5999
  }
5995
6000
  output = await repo.safeRun(["rev-parse", "--abbrev-ref", "HEAD"]);
5996
6001
  if (!output) {
5997
- import_coc10.window.showMessage(`current branch not found`, "warning");
6002
+ import_coc10.window.showWarningMessage(`current branch not found`);
5998
6003
  return;
5999
6004
  }
6000
6005
  await import_coc10.window.runTerminalCommand(`git push ${remote} ${output}${extra.length ? " " + extra.join(" ") : ""}`, root, true);
@@ -6002,7 +6007,7 @@ var DocumentManager = class {
6002
6007
  get buffer() {
6003
6008
  return import_coc10.workspace.nvim.call("bufnr", "%").then((bufnr) => {
6004
6009
  let buf = this.buffers.get(bufnr);
6005
- if (!buf) import_coc10.window.showMessage(`Cant't resolve git repository for current buffer.`, "warning");
6010
+ if (!buf) import_coc10.window.showWarningMessage(`Cant't resolve git repository for current buffer.`);
6006
6011
  return buf;
6007
6012
  });
6008
6013
  }
@@ -6013,7 +6018,7 @@ var DocumentManager = class {
6013
6018
  let bufnr = await import_coc10.workspace.nvim.call("bufnr", "%");
6014
6019
  let root = await this.resolveGitRootFromBufferOrCwd(bufnr);
6015
6020
  if (!root) {
6016
- import_coc10.window.showMessage(`not belongs to git repository.`, "warning");
6021
+ import_coc10.window.showWarningMessage(`not belongs to git repository.`);
6017
6022
  return null;
6018
6023
  }
6019
6024
  let repo = this.service.getRepoFromRoot(root);
@@ -6763,7 +6768,7 @@ var GitBuffer = class {
6763
6768
  let line = await import_coc13.workspace.nvim.call("line", ".");
6764
6769
  let diff = this.getChunk(line);
6765
6770
  if (!diff) {
6766
- import_coc13.window.showMessage("Not positioned in git chunk", "error");
6771
+ import_coc13.window.showErrorMessage("Not positioned in git chunk");
6767
6772
  return;
6768
6773
  }
6769
6774
  let head;
@@ -7064,7 +7069,7 @@ var GitBuffer = class {
7064
7069
  let info;
7065
7070
  for (let line of r.stdout.trim().split(/\r?\n/)) {
7066
7071
  line = line.trim();
7067
- if (line.startsWith("External file (--contents)")) {
7072
+ if (/^(author |committer )?External file \(--contents\)/.test(line)) {
7068
7073
  line = "Not committed yet.";
7069
7074
  }
7070
7075
  let ms = line.match(/^([A-Za-z0-9]+)\s(\d+)\s(\d+)\s(\d+)/);
@@ -7103,7 +7108,7 @@ var GitBuffer = class {
7103
7108
  async diffCached() {
7104
7109
  let res = await this.repo.safeRun(["diff", "--cached"]);
7105
7110
  if (!res.trim()) {
7106
- import_coc13.window.showMessage("Empty diff");
7111
+ import_coc13.window.showWarningMessage("Empty diff");
7107
7112
  return;
7108
7113
  }
7109
7114
  let { nvim } = import_coc13.workspace;
@@ -7119,7 +7124,7 @@ var GitBuffer = class {
7119
7124
  async nextConflict() {
7120
7125
  let { nvim } = import_coc13.workspace;
7121
7126
  if (!this.conflicts.length) {
7122
- import_coc13.window.showMessage("No conflicts detected", "warning");
7127
+ import_coc13.window.showWarningMessage("No conflicts detected");
7123
7128
  return;
7124
7129
  }
7125
7130
  let line = await nvim.call("line", ".");
@@ -7136,7 +7141,7 @@ var GitBuffer = class {
7136
7141
  async prevConflict() {
7137
7142
  let { nvim } = import_coc13.workspace;
7138
7143
  if (!this.conflicts.length) {
7139
- import_coc13.window.showMessage("No conflicts detected", "warning");
7144
+ import_coc13.window.showWarningMessage("No conflicts detected", "warning");
7140
7145
  return;
7141
7146
  }
7142
7147
  let line = await nvim.call("line", ".");
@@ -7154,7 +7159,7 @@ var GitBuffer = class {
7154
7159
  const { nvim } = import_coc13.workspace;
7155
7160
  let conflicts = this.conflicts;
7156
7161
  if (!conflicts || conflicts.length == 0) {
7157
- import_coc13.window.showMessage("No conflicts detected");
7162
+ import_coc13.window.showWarningMessage("No conflicts detected");
7158
7163
  return;
7159
7164
  }
7160
7165
  let line = await nvim.call("line", ".");
@@ -7174,7 +7179,7 @@ var GitBuffer = class {
7174
7179
  }
7175
7180
  }
7176
7181
  }
7177
- import_coc13.window.showMessage("Not positioned on a conflict");
7182
+ import_coc13.window.showWarningMessage("Not positioned on a conflict");
7178
7183
  }
7179
7184
  async browser(action = "open", range, permalink = false) {
7180
7185
  let { nvim } = import_coc13.workspace;
@@ -7197,7 +7202,7 @@ var GitBuffer = class {
7197
7202
  }
7198
7203
  let output = await this.repo.safeRun(["remote"]);
7199
7204
  if (!output.trim()) {
7200
- import_coc13.window.showMessage(`No remote found`, "warning");
7205
+ import_coc13.window.showWarningMessage(`No remote found`);
7201
7206
  return;
7202
7207
  }
7203
7208
  let names = output.trim().split(/\r?\n/);
@@ -7206,7 +7211,7 @@ var GitBuffer = class {
7206
7211
  if (names.includes(browserRemoteName)) {
7207
7212
  names = [browserRemoteName];
7208
7213
  } else {
7209
- import_coc13.window.showMessage("Configured git.browserRemoteName missing from remote list", "warning");
7214
+ import_coc13.window.showWarningMessage("Configured git.browserRemoteName missing from remote list");
7210
7215
  return;
7211
7216
  }
7212
7217
  }
@@ -7231,16 +7236,17 @@ var GitBuffer = class {
7231
7236
  await import_coc13.workspace.openResource(urls[0]);
7232
7237
  } else {
7233
7238
  nvim.command(`let @+ = '${urls[0]}'`, true);
7234
- import_coc13.window.showMessage("Copied url to clipboard");
7239
+ import_coc13.window.showInformationMessage("Copied url to clipboard");
7235
7240
  }
7236
7241
  } else if (urls.length > 1) {
7237
- let idx = await import_coc13.window.showQuickpick(urls, "Select url:");
7238
- if (idx >= 0) {
7242
+ let url = await import_coc13.window.showQuickPick(urls, { canPickMany: false, title: "Pick remote url" });
7243
+ if (url) {
7239
7244
  if (action == "open") {
7240
- await import_coc13.workspace.openResource(urls[idx]);
7245
+ await import_coc13.workspace.openResource(url);
7241
7246
  } else {
7242
- nvim.command(`let @+ = '${urls[idx]}'`, true);
7243
- import_coc13.window.showMessage("Copied url to clipboard");
7247
+ nvim.command(`let @+ = '${url}'`, true);
7248
+ nvim.command(`let @* = '${url}'`, true);
7249
+ import_coc13.window.showInformationMessage("Copied url to clipboard");
7244
7250
  }
7245
7251
  }
7246
7252
  }
@@ -7249,7 +7255,7 @@ var GitBuffer = class {
7249
7255
  async showCommit() {
7250
7256
  let indexed = await this.repo.isIndexed(this.relpath);
7251
7257
  if (!indexed) {
7252
- import_coc13.window.showMessage(`"${this.relpath}" not indexed.`, "warning");
7258
+ import_coc13.window.showWarningMessage(`"${this.relpath}" not indexed.`);
7253
7259
  return;
7254
7260
  }
7255
7261
  let nvim = import_coc13.workspace.nvim;
@@ -7260,7 +7266,7 @@ var GitBuffer = class {
7260
7266
  if (!output.length) return;
7261
7267
  let commit = output.match(/^\S+/)[0];
7262
7268
  if (/^0+$/.test(commit)) {
7263
- import_coc13.window.showMessage("not committed yet!", "warning");
7269
+ import_coc13.window.showWarningMessage("not committed yet!");
7264
7270
  return;
7265
7271
  }
7266
7272
  let useFloating = this.config.showCommitInFloating;
@@ -7297,12 +7303,20 @@ var GitBuffer = class {
7297
7303
  if (!doc) return;
7298
7304
  let infos = this.currentSigns;
7299
7305
  if (!infos || infos.length == 0) {
7300
- import_coc13.window.showMessage("No changes", "warning");
7306
+ import_coc13.window.showWarningMessage("No changes");
7301
7307
  return;
7302
7308
  }
7303
7309
  let lnums = infos.map((o) => o.lnum);
7310
+ let foldContext = this.config.foldContext;
7311
+ let max = this.doc.lineCount;
7304
7312
  let ranges = [];
7305
7313
  let start = null;
7314
+ const addRange = (from, to) => {
7315
+ let s = plus(from, foldContext, max);
7316
+ let e = minus(to, foldContext, 0);
7317
+ if (e - s <= 0) return;
7318
+ ranges.push([s, e]);
7319
+ };
7306
7320
  for (let i = 1; i <= doc.lineCount; i++) {
7307
7321
  let fold = lnums.indexOf(i) == -1;
7308
7322
  if (fold && start == null) {
@@ -7310,11 +7324,11 @@ var GitBuffer = class {
7310
7324
  continue;
7311
7325
  }
7312
7326
  if (start != null && !fold) {
7313
- ranges.push([start, i - 1]);
7327
+ addRange(start, i - 1);
7314
7328
  start = null;
7315
7329
  }
7316
7330
  if (start != null && fold && i == doc.lineCount) {
7317
- ranges.push([start, i]);
7331
+ addRange(start, i);
7318
7332
  }
7319
7333
  }
7320
7334
  let enabled = this.foldEnabled;
@@ -7333,6 +7347,8 @@ var GitBuffer = class {
7333
7347
  nvim.call("setpos", [".", cursor], true);
7334
7348
  await nvim.resumeNotification();
7335
7349
  } else {
7350
+ console.log(33);
7351
+ console.log(ranges);
7336
7352
  this.foldEnabled = true;
7337
7353
  let [foldmethod, foldenable, foldlevel] = await nvim.eval("[&foldmethod,&foldenable,&foldlevel]");
7338
7354
  this.foldSettings = {
@@ -7366,7 +7382,7 @@ var GitBuffer = class {
7366
7382
  async parseConflicts() {
7367
7383
  if (!this.hasConflicts || !this.config.conflict.enabled) return;
7368
7384
  const lines = this.doc.getLines();
7369
- const revPattern = "([0-9A-Za-z_.:/]+)";
7385
+ const revPattern = "([0-9A-Za-z_.:/-]+)";
7370
7386
  const startPattern = new RegExp(`^<{7} (${revPattern})(:? .+)?$`);
7371
7387
  const sepPattern = new RegExp(`^={7}$`);
7372
7388
  const endPattern = new RegExp(`^>{7} (${revPattern})(:? .+)?$`);
@@ -7442,19 +7458,20 @@ var GitBuffer = class {
7442
7458
  let { nvim } = import_coc13.workspace;
7443
7459
  nvim.pauseNotification();
7444
7460
  buffer.clearNamespace(this.config.conflictSrcId, 0, -1);
7461
+ const srcId = this.config.conflictSrcId;
7445
7462
  conflicts.map((conflict) => {
7446
7463
  buffer.addHighlight({
7447
7464
  hlGroup: currentHlGroup,
7448
7465
  line: conflict.start,
7449
7466
  colStart: 0,
7450
7467
  colEnd: 1e4,
7451
- srcId: this.config.conflictSrcId
7468
+ srcId
7452
7469
  });
7453
7470
  for (let line = conflict.start - 1; line < conflict.sep - 1; line++) {
7454
- buffer.addHighlight({ hlGroup: currentHlGroup, line, srcId: this.config.conflictSrcId });
7471
+ buffer.addHighlight({ hlGroup: currentHlGroup, line, srcId });
7455
7472
  }
7456
7473
  for (let line = conflict.end - 1; line >= conflict.sep; line--) {
7457
- buffer.addHighlight({ hlGroup: incomingHlGroup, line, srcId: this.config.conflictSrcId });
7474
+ buffer.addHighlight({ hlGroup: incomingHlGroup, line, srcId });
7458
7475
  }
7459
7476
  });
7460
7477
  nvim.resumeNotification(false, true);
@@ -7519,6 +7536,16 @@ var GitBuffer = class {
7519
7536
  this.currentSigns = void 0;
7520
7537
  }
7521
7538
  };
7539
+ function plus(val, count, max) {
7540
+ if (!count) return val;
7541
+ val = val + count;
7542
+ return Math.min(max, val);
7543
+ }
7544
+ function minus(val, count, min) {
7545
+ if (!count) return val;
7546
+ val = val - count;
7547
+ return Math.max(min, val);
7548
+ }
7522
7549
 
7523
7550
  // src/model/service.ts
7524
7551
  var import_path8 = __toESM(require("path"));
@@ -7871,10 +7898,10 @@ async function activate(context) {
7871
7898
  const { subscriptions } = context;
7872
7899
  let gitInfo;
7873
7900
  try {
7874
- let pathHint = config.get("command");
7901
+ let pathHint = config.get("command", "git");
7875
7902
  gitInfo = await findGit(pathHint, (path9) => context.logger.info(`Looking for git in: ${path9}`));
7876
7903
  } catch (e) {
7877
- import_coc16.window.showMessage("git command required for coc-git", "error");
7904
+ import_coc16.window.showErrorMessage("git command required for coc-git");
7878
7905
  return;
7879
7906
  }
7880
7907
  const virtualTextSrcId = await import_coc16.workspace.nvim.createNamespace("coc-git-virtual");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coc-git",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "description": "Git extension for coc.nvim",
5
5
  "main": "lib/index.js",
6
6
  "publisher": "chemzqm",
@@ -95,6 +95,21 @@
95
95
  "scope": "window",
96
96
  "description": "Remote name for fetch github issues."
97
97
  },
98
+ "git.diffOptions": {
99
+ "type": "array",
100
+ "default": [],
101
+ "description": "Options for git diff command, eg: [\"--ignore-all-space\"]",
102
+ "scope": "window",
103
+ "items": {
104
+ "type": "string"
105
+ }
106
+ },
107
+ "git.foldContext": {
108
+ "type": "number",
109
+ "default": 0,
110
+ "scope": "window",
111
+ "description": "Line count to leave below and above the fold."
112
+ },
98
113
  "git.browserRemoteName": {
99
114
  "type": "string",
100
115
  "default": "",