550c4b4578e422a85f4e0acf6eb43cc947015c57addb35eee1ceffcea1dc4b2d0697b53699b1f244f794f9faddebb25019f966d8ae5f7f5c894898e012c007 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  6. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  7. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  8. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  9. return c > 3 && r && Object.defineProperty(target, key, r), r;
  10. };
  11. var __param = (this && this.__param) || function (paramIndex, decorator) {
  12. return function (target, key) { decorator(target, key, paramIndex); }
  13. };
  14. import { binarySearch } from '../../../../base/common/arrays.js';
  15. import { Emitter } from '../../../../base/common/event.js';
  16. import { DisposableStore } from '../../../../base/common/lifecycle.js';
  17. import { LinkedList } from '../../../../base/common/linkedList.js';
  18. import { compare } from '../../../../base/common/strings.js';
  19. import { URI } from '../../../../base/common/uri.js';
  20. import { Range } from '../../../common/core/range.js';
  21. import { registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
  22. import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
  23. import { IMarkerService, MarkerSeverity } from '../../../../platform/markers/common/markers.js';
  24. import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
  25. export class MarkerCoordinate {
  26. constructor(marker, index, total) {
  27. this.marker = marker;
  28. this.index = index;
  29. this.total = total;
  30. }
  31. }
  32. let MarkerList = class MarkerList {
  33. constructor(resourceFilter, _markerService, _configService) {
  34. this._markerService = _markerService;
  35. this._configService = _configService;
  36. this._onDidChange = new Emitter();
  37. this.onDidChange = this._onDidChange.event;
  38. this._dispoables = new DisposableStore();
  39. this._markers = [];
  40. this._nextIdx = -1;
  41. if (URI.isUri(resourceFilter)) {
  42. this._resourceFilter = uri => uri.toString() === resourceFilter.toString();
  43. }
  44. else if (resourceFilter) {
  45. this._resourceFilter = resourceFilter;
  46. }
  47. const compareOrder = this._configService.getValue('problems.sortOrder');
  48. const compareMarker = (a, b) => {
  49. let res = compare(a.resource.toString(), b.resource.toString());
  50. if (res === 0) {
  51. if (compareOrder === 'position') {
  52. res = Range.compareRangesUsingStarts(a, b) || MarkerSeverity.compare(a.severity, b.severity);
  53. }
  54. else {
  55. res = MarkerSeverity.compare(a.severity, b.severity) || Range.compareRangesUsingStarts(a, b);
  56. }
  57. }
  58. return res;
  59. };
  60. const updateMarker = () => {
  61. this._markers = this._markerService.read({
  62. resource: URI.isUri(resourceFilter) ? resourceFilter : undefined,
  63. severities: MarkerSeverity.Error | MarkerSeverity.Warning | MarkerSeverity.Info
  64. });
  65. if (typeof resourceFilter === 'function') {
  66. this._markers = this._markers.filter(m => this._resourceFilter(m.resource));
  67. }
  68. this._markers.sort(compareMarker);
  69. };
  70. updateMarker();
  71. this._dispoables.add(_markerService.onMarkerChanged(uris => {
  72. if (!this._resourceFilter || uris.some(uri => this._resourceFilter(uri))) {
  73. updateMarker();
  74. this._nextIdx = -1;
  75. this._onDidChange.fire();
  76. }
  77. }));
  78. }
  79. dispose() {
  80. this._dispoables.dispose();
  81. this._onDidChange.dispose();
  82. }
  83. matches(uri) {
  84. if (!this._resourceFilter && !uri) {
  85. return true;
  86. }
  87. if (!this._resourceFilter || !uri) {
  88. return false;
  89. }
  90. return this._resourceFilter(uri);
  91. }
  92. get selected() {
  93. const marker = this._markers[this._nextIdx];
  94. return marker && new MarkerCoordinate(marker, this._nextIdx + 1, this._markers.length);
  95. }
  96. _initIdx(model, position, fwd) {
  97. let found = false;
  98. let idx = this._markers.findIndex(marker => marker.resource.toString() === model.uri.toString());
  99. if (idx < 0) {
  100. idx = binarySearch(this._markers, { resource: model.uri }, (a, b) => compare(a.resource.toString(), b.resource.toString()));
  101. if (idx < 0) {
  102. idx = ~idx;
  103. }
  104. }
  105. for (let i = idx; i < this._markers.length; i++) {
  106. let range = Range.lift(this._markers[i]);
  107. if (range.isEmpty()) {
  108. const word = model.getWordAtPosition(range.getStartPosition());
  109. if (word) {
  110. range = new Range(range.startLineNumber, word.startColumn, range.startLineNumber, word.endColumn);
  111. }
  112. }
  113. if (position && (range.containsPosition(position) || position.isBeforeOrEqual(range.getStartPosition()))) {
  114. this._nextIdx = i;
  115. found = true;
  116. break;
  117. }
  118. if (this._markers[i].resource.toString() !== model.uri.toString()) {
  119. break;
  120. }
  121. }
  122. if (!found) {
  123. // after the last change
  124. this._nextIdx = fwd ? 0 : this._markers.length - 1;
  125. }
  126. if (this._nextIdx < 0) {
  127. this._nextIdx = this._markers.length - 1;
  128. }
  129. }
  130. resetIndex() {
  131. this._nextIdx = -1;
  132. }
  133. move(fwd, model, position) {
  134. if (this._markers.length === 0) {
  135. return false;
  136. }
  137. const oldIdx = this._nextIdx;
  138. if (this._nextIdx === -1) {
  139. this._initIdx(model, position, fwd);
  140. }
  141. else if (fwd) {
  142. this._nextIdx = (this._nextIdx + 1) % this._markers.length;
  143. }
  144. else if (!fwd) {
  145. this._nextIdx = (this._nextIdx - 1 + this._markers.length) % this._markers.length;
  146. }
  147. if (oldIdx !== this._nextIdx) {
  148. return true;
  149. }
  150. return false;
  151. }
  152. find(uri, position) {
  153. let idx = this._markers.findIndex(marker => marker.resource.toString() === uri.toString());
  154. if (idx < 0) {
  155. return undefined;
  156. }
  157. for (; idx < this._markers.length; idx++) {
  158. if (Range.containsPosition(this._markers[idx], position)) {
  159. return new MarkerCoordinate(this._markers[idx], idx + 1, this._markers.length);
  160. }
  161. }
  162. return undefined;
  163. }
  164. };
  165. MarkerList = __decorate([
  166. __param(1, IMarkerService),
  167. __param(2, IConfigurationService)
  168. ], MarkerList);
  169. export { MarkerList };
  170. export const IMarkerNavigationService = createDecorator('IMarkerNavigationService');
  171. let MarkerNavigationService = class MarkerNavigationService {
  172. constructor(_markerService, _configService) {
  173. this._markerService = _markerService;
  174. this._configService = _configService;
  175. this._provider = new LinkedList();
  176. }
  177. getMarkerList(resource) {
  178. for (const provider of this._provider) {
  179. const result = provider.getMarkerList(resource);
  180. if (result) {
  181. return result;
  182. }
  183. }
  184. // default
  185. return new MarkerList(resource, this._markerService, this._configService);
  186. }
  187. };
  188. MarkerNavigationService = __decorate([
  189. __param(0, IMarkerService),
  190. __param(1, IConfigurationService)
  191. ], MarkerNavigationService);
  192. registerSingleton(IMarkerNavigationService, MarkerNavigationService, true);