coc-git 2.7.2 → 2.7.4

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 +5 -1
  2. package/lib/index.js +81 -51
  3. package/package.json +22 -1
package/Readme.md CHANGED
@@ -30,7 +30,7 @@ In your vim/neovim, run command:
30
30
  - Git related lists, including `issues`, `gfiles`, `gstatus`, `commits`, `branches` & `bcommits`
31
31
  - Keymaps for git chunks, including `<Plug>(coc-git-chunkinfo)` `<Plug>(coc-git-nextchunk)` & `<Plug>(coc-git-prevchunk)` ,
32
32
  - Commands for chunks, including `git.chunkInfo` `git.chunkStage` `git.chunkUndo` and more.
33
- - Keymaps for git conflicts, including `<Plug>(coc-git-nextconflict)`, `<Plug>(coc-git-prevconflict)`, `<Plug>(coc-git-keepcurrent)`, `<Plug>(coc-git-keepincoming)` & `<Plug>(coc-git-keepboth)`.
33
+ - Keymaps & commands for git conflicts.
34
34
  - Completion support for semantic commit.
35
35
  - Completion support for GitHub/GitLab issues.
36
36
 
@@ -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),
@@ -5851,7 +5853,8 @@ var DocumentManager = class {
5851
5853
  conflict: {
5852
5854
  enabled: config.get("conflict.enabled", true),
5853
5855
  currentHlGroup: config.get("conflict.current.hlGroup", "DiffChange"),
5854
- incomingHlGroup: config.get("conflict.incoming.hlGroup", "DiffAdd")
5856
+ incomingHlGroup: config.get("conflict.incoming.hlGroup", "DiffAdd"),
5857
+ commonHlGroup: config.get("conflict.common.hlGroup", "DiffText")
5855
5858
  },
5856
5859
  floatConfig: config.get("floatConfig", {}),
5857
5860
  gstatus: {
@@ -5871,6 +5874,9 @@ var DocumentManager = class {
5871
5874
  get git() {
5872
5875
  return this.service.git;
5873
5876
  }
5877
+ get diffOptions() {
5878
+ return this.config.diffOptions;
5879
+ }
5874
5880
  async toggleGutters() {
5875
5881
  let enabled = this.enableGutters;
5876
5882
  let config = import_coc10.workspace.getConfiguration("git");
@@ -5978,7 +5984,7 @@ var DocumentManager = class {
5978
5984
  let root = await this.resolveGitRootFromBufferOrCwd(bufnr);
5979
5985
  let extra = this.config.pushArguments;
5980
5986
  if (!root) {
5981
- import_coc10.window.showMessage(`not belongs to git repository.`, "warning");
5987
+ import_coc10.window.showWarningMessage(`not belongs to git repository.`);
5982
5988
  return;
5983
5989
  }
5984
5990
  if (args && args.length) {
@@ -5989,12 +5995,12 @@ var DocumentManager = class {
5989
5995
  let output = await repo.safeRun(["remote"]);
5990
5996
  let remote = output.trim().split(/\r?\n/)[0];
5991
5997
  if (!remote) {
5992
- import_coc10.window.showMessage(`remote not found`, "warning");
5998
+ import_coc10.window.showWarningMessage(`remote not found`);
5993
5999
  return;
5994
6000
  }
5995
6001
  output = await repo.safeRun(["rev-parse", "--abbrev-ref", "HEAD"]);
5996
6002
  if (!output) {
5997
- import_coc10.window.showMessage(`current branch not found`, "warning");
6003
+ import_coc10.window.showWarningMessage(`current branch not found`);
5998
6004
  return;
5999
6005
  }
6000
6006
  await import_coc10.window.runTerminalCommand(`git push ${remote} ${output}${extra.length ? " " + extra.join(" ") : ""}`, root, true);
@@ -6002,7 +6008,7 @@ var DocumentManager = class {
6002
6008
  get buffer() {
6003
6009
  return import_coc10.workspace.nvim.call("bufnr", "%").then((bufnr) => {
6004
6010
  let buf = this.buffers.get(bufnr);
6005
- if (!buf) import_coc10.window.showMessage(`Cant't resolve git repository for current buffer.`, "warning");
6011
+ if (!buf) import_coc10.window.showWarningMessage(`Cant't resolve git repository for current buffer.`);
6006
6012
  return buf;
6007
6013
  });
6008
6014
  }
@@ -6013,7 +6019,7 @@ var DocumentManager = class {
6013
6019
  let bufnr = await import_coc10.workspace.nvim.call("bufnr", "%");
6014
6020
  let root = await this.resolveGitRootFromBufferOrCwd(bufnr);
6015
6021
  if (!root) {
6016
- import_coc10.window.showMessage(`not belongs to git repository.`, "warning");
6022
+ import_coc10.window.showWarningMessage(`not belongs to git repository.`);
6017
6023
  return null;
6018
6024
  }
6019
6025
  let repo = this.service.getRepoFromRoot(root);
@@ -6677,6 +6683,11 @@ register("zh_CN", zh_CN_default);
6677
6683
  // src/model/buffer.ts
6678
6684
  var import_url = require("url");
6679
6685
  var signGroup = "CocGit";
6686
+ var revPattern = "([0-9A-Za-z_.:/-]+)";
6687
+ var startPattern = new RegExp(`^<{7} (${revPattern})(:? .+)?$`);
6688
+ var sepPattern = new RegExp(`^={7}$`);
6689
+ var endPattern = new RegExp(`^>{7} (${revPattern})(:? .+)?$`);
6690
+ var commonPattern = /^\|{7}\smerged\scommon\sancestors/;
6680
6691
  var GitBuffer = class {
6681
6692
  constructor(doc, config, relpath, repo, git, channel, floatFactory) {
6682
6693
  this.doc = doc;
@@ -7064,7 +7075,7 @@ var GitBuffer = class {
7064
7075
  let info;
7065
7076
  for (let line of r.stdout.trim().split(/\r?\n/)) {
7066
7077
  line = line.trim();
7067
- if (line.startsWith("External file (--contents)")) {
7078
+ if (/^(author |committer )?External file \(--contents\)/.test(line)) {
7068
7079
  line = "Not committed yet.";
7069
7080
  }
7070
7081
  let ms = line.match(/^([A-Za-z0-9]+)\s(\d+)\s(\d+)\s(\d+)/);
@@ -7162,15 +7173,19 @@ var GitBuffer = class {
7162
7173
  if (conflict.start <= line && conflict.end >= line) {
7163
7174
  switch (part) {
7164
7175
  case 0 /* Current */:
7165
- await nvim.command(`${conflict.sep},${conflict.end}d`);
7166
- return nvim.command(`${conflict.start}d`);
7176
+ let start = conflict.common ? conflict.common : conflict.sep;
7177
+ await nvim.command(`${start},${conflict.end}d | ${conflict.start}d`);
7178
+ return;
7167
7179
  case 1 /* Incoming */:
7168
- await nvim.command(`${conflict.end}d`);
7169
- return nvim.command(`${conflict.start},${conflict.sep}d`);
7180
+ await nvim.command(`${conflict.end}d | ${conflict.start},${conflict.sep}d`);
7181
+ return;
7170
7182
  case 2 /* Both */:
7171
- await nvim.command(`${conflict.end}d`);
7172
- await nvim.command(`${conflict.sep}d`);
7173
- return nvim.command(`${conflict.start}d`);
7183
+ if (conflict.common) {
7184
+ await nvim.command(`${conflict.end}d | ${conflict.common},${conflict.sep}d | ${conflict.start}d`);
7185
+ } else {
7186
+ await nvim.command(`${conflict.end}d | ${conflict.sep}d | ${conflict.start}d`);
7187
+ }
7188
+ return;
7174
7189
  }
7175
7190
  }
7176
7191
  }
@@ -7250,7 +7265,7 @@ var GitBuffer = class {
7250
7265
  async showCommit() {
7251
7266
  let indexed = await this.repo.isIndexed(this.relpath);
7252
7267
  if (!indexed) {
7253
- import_coc13.window.showMessage(`"${this.relpath}" not indexed.`, "warning");
7268
+ import_coc13.window.showWarningMessage(`"${this.relpath}" not indexed.`);
7254
7269
  return;
7255
7270
  }
7256
7271
  let nvim = import_coc13.workspace.nvim;
@@ -7261,7 +7276,7 @@ var GitBuffer = class {
7261
7276
  if (!output.length) return;
7262
7277
  let commit = output.match(/^\S+/)[0];
7263
7278
  if (/^0+$/.test(commit)) {
7264
- import_coc13.window.showMessage("not committed yet!", "warning");
7279
+ import_coc13.window.showWarningMessage("not committed yet!");
7265
7280
  return;
7266
7281
  }
7267
7282
  let useFloating = this.config.showCommitInFloating;
@@ -7298,12 +7313,20 @@ var GitBuffer = class {
7298
7313
  if (!doc) return;
7299
7314
  let infos = this.currentSigns;
7300
7315
  if (!infos || infos.length == 0) {
7301
- import_coc13.window.showMessage("No changes", "warning");
7316
+ import_coc13.window.showWarningMessage("No changes");
7302
7317
  return;
7303
7318
  }
7304
7319
  let lnums = infos.map((o) => o.lnum);
7320
+ let foldContext = this.config.foldContext;
7321
+ let max = this.doc.lineCount;
7305
7322
  let ranges = [];
7306
7323
  let start = null;
7324
+ const addRange = (from, to) => {
7325
+ let s = plus(from, foldContext, max);
7326
+ let e = minus(to, foldContext, 0);
7327
+ if (e - s <= 0) return;
7328
+ ranges.push([s, e]);
7329
+ };
7307
7330
  for (let i = 1; i <= doc.lineCount; i++) {
7308
7331
  let fold = lnums.indexOf(i) == -1;
7309
7332
  if (fold && start == null) {
@@ -7311,11 +7334,11 @@ var GitBuffer = class {
7311
7334
  continue;
7312
7335
  }
7313
7336
  if (start != null && !fold) {
7314
- ranges.push([start, i - 1]);
7337
+ addRange(start, i - 1);
7315
7338
  start = null;
7316
7339
  }
7317
7340
  if (start != null && fold && i == doc.lineCount) {
7318
- ranges.push([start, i]);
7341
+ addRange(start, i);
7319
7342
  }
7320
7343
  }
7321
7344
  let enabled = this.foldEnabled;
@@ -7366,11 +7389,7 @@ var GitBuffer = class {
7366
7389
  }
7367
7390
  async parseConflicts() {
7368
7391
  if (!this.hasConflicts || !this.config.conflict.enabled) return;
7369
- const lines = this.doc.getLines();
7370
- const revPattern = "([0-9A-Za-z_.:/-]+)";
7371
- const startPattern = new RegExp(`^<{7} (${revPattern})(:? .+)?$`);
7372
- const sepPattern = new RegExp(`^={7}$`);
7373
- const endPattern = new RegExp(`^>{7} (${revPattern})(:? .+)?$`);
7392
+ const lines = this.doc.textDocument.lines;
7374
7393
  let conflicts = [];
7375
7394
  let conflict = null;
7376
7395
  let state = 0 /* Initial */;
@@ -7391,11 +7410,12 @@ var GitBuffer = class {
7391
7410
  }
7392
7411
  break;
7393
7412
  }
7413
+ case 2 /* MatchedCommon */:
7394
7414
  case 1 /* MatchedStart */: {
7395
- const match = line.match(sepPattern);
7415
+ let match = line.match(sepPattern);
7396
7416
  if (match) {
7397
7417
  conflict.sep = index + 1;
7398
- state = 2 /* MatchedSep */;
7418
+ state = 3 /* MatchedSep */;
7399
7419
  } else {
7400
7420
  const startMatch = line.match(startPattern);
7401
7421
  if (startMatch) {
@@ -7404,11 +7424,14 @@ var GitBuffer = class {
7404
7424
  } else if (line.match(endPattern)) {
7405
7425
  conflict = null;
7406
7426
  state = 0 /* Initial */;
7427
+ } else if (line.match(commonPattern)) {
7428
+ conflict.common = index + 1;
7429
+ state = 2 /* MatchedCommon */;
7407
7430
  }
7408
7431
  }
7409
7432
  break;
7410
7433
  }
7411
- case 2 /* MatchedSep */: {
7434
+ case 3 /* MatchedSep */: {
7412
7435
  const match = line.match(endPattern);
7413
7436
  if (match) {
7414
7437
  conflict.end = index + 1;
@@ -7440,23 +7463,20 @@ var GitBuffer = class {
7440
7463
  let buffer = this.doc.buffer;
7441
7464
  let currentHlGroup = this.config.conflict.currentHlGroup;
7442
7465
  let incomingHlGroup = this.config.conflict.incomingHlGroup;
7466
+ let commonHlGroup = this.config.conflict.commonHlGroup;
7443
7467
  let { nvim } = import_coc13.workspace;
7444
7468
  nvim.pauseNotification();
7445
7469
  buffer.clearNamespace(this.config.conflictSrcId, 0, -1);
7446
7470
  const srcId = this.config.conflictSrcId;
7447
7471
  conflicts.map((conflict) => {
7448
- buffer.addHighlight({
7449
- hlGroup: currentHlGroup,
7450
- line: conflict.start,
7451
- colStart: 0,
7452
- colEnd: 1e4,
7453
- srcId
7454
- });
7455
- for (let line = conflict.start - 1; line < conflict.sep - 1; line++) {
7456
- buffer.addHighlight({ hlGroup: currentHlGroup, line, srcId });
7457
- }
7458
- for (let line = conflict.end - 1; line >= conflict.sep; line--) {
7459
- buffer.addHighlight({ hlGroup: incomingHlGroup, line, srcId });
7472
+ let currEnd = conflict.common ? conflict.common - 1 : conflict.sep - 1;
7473
+ let currRange = import_coc13.Range.create(import_coc13.Position.create(conflict.start - 1, 0), import_coc13.Position.create(currEnd, 0));
7474
+ let incomingRange = import_coc13.Range.create(import_coc13.Position.create(conflict.sep, 0), import_coc13.Position.create(conflict.end, 0));
7475
+ buffer.highlightRanges(srcId, currentHlGroup, [currRange]);
7476
+ buffer.highlightRanges(srcId, incomingHlGroup, [incomingRange]);
7477
+ if (conflict.common) {
7478
+ let range = import_coc13.Range.create(import_coc13.Position.create(conflict.common - 1, 0), import_coc13.Position.create(conflict.sep - 1, 0));
7479
+ buffer.highlightRanges(srcId, commonHlGroup, [range]);
7460
7480
  }
7461
7481
  });
7462
7482
  nvim.resumeNotification(false, true);
@@ -7521,6 +7541,16 @@ var GitBuffer = class {
7521
7541
  this.currentSigns = void 0;
7522
7542
  }
7523
7543
  };
7544
+ function plus(val, count, max) {
7545
+ if (!count) return val;
7546
+ val = val + count;
7547
+ return Math.min(max, val);
7548
+ }
7549
+ function minus(val, count, min) {
7550
+ if (!count) return val;
7551
+ val = val - count;
7552
+ return Math.max(min, val);
7553
+ }
7524
7554
 
7525
7555
  // src/model/service.ts
7526
7556
  var import_path8 = __toESM(require("path"));
@@ -7873,10 +7903,10 @@ async function activate(context) {
7873
7903
  const { subscriptions } = context;
7874
7904
  let gitInfo;
7875
7905
  try {
7876
- let pathHint = config.get("command");
7906
+ let pathHint = config.get("command", "git");
7877
7907
  gitInfo = await findGit(pathHint, (path9) => context.logger.info(`Looking for git in: ${path9}`));
7878
7908
  } catch (e) {
7879
- import_coc16.window.showMessage("git command required for coc-git", "error");
7909
+ import_coc16.window.showErrorMessage("git command required for coc-git");
7880
7910
  return;
7881
7911
  }
7882
7912
  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.2",
3
+ "version": "2.7.4",
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": "",
@@ -415,6 +430,12 @@
415
430
  "scope": "application",
416
431
  "description": "Highlight group for the incoming version of a merge conflict."
417
432
  },
433
+ "git.conflict.common.hlGroup": {
434
+ "type": "string",
435
+ "default": "DiffText",
436
+ "scope": "application",
437
+ "description": "Highlight group for the merged common ancestors highlight group."
438
+ },
418
439
  "git.gstatus.saveBeforeOpen": {
419
440
  "type": "boolean",
420
441
  "default": "false",