5243f2c1e9f3bb2aa5fdbcbf27247a6cde6b653268216f94b349ba6851236f09b4d61d26d60835a630ef99395b50c66289e9bc810b0779de9c7dd090a4f801 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  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. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  15. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  16. return new (P || (P = Promise))(function (resolve, reject) {
  17. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  18. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  19. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  20. step((generator = generator.apply(thisArg, _arguments || [])).next());
  21. });
  22. };
  23. import '../../common/languages/languageConfigurationRegistry.js';
  24. import './standaloneCodeEditorService.js';
  25. import './standaloneLayoutService.js';
  26. import '../../../platform/undoRedo/common/undoRedoService.js';
  27. import '../../common/services/languageFeatureDebounce.js';
  28. import * as strings from '../../../base/common/strings.js';
  29. import * as dom from '../../../base/browser/dom.js';
  30. import { StandardKeyboardEvent } from '../../../base/browser/keyboardEvent.js';
  31. import { Emitter } from '../../../base/common/event.js';
  32. import { SimpleKeybinding, createKeybinding } from '../../../base/common/keybindings.js';
  33. import { ImmortalReference, toDisposable, DisposableStore, Disposable, combinedDisposable } from '../../../base/common/lifecycle.js';
  34. import { OS, isLinux, isMacintosh } from '../../../base/common/platform.js';
  35. import Severity from '../../../base/common/severity.js';
  36. import { URI } from '../../../base/common/uri.js';
  37. import { IBulkEditService, ResourceTextEdit } from '../../browser/services/bulkEditService.js';
  38. import { isDiffEditorConfigurationKey, isEditorConfigurationKey } from '../../common/config/editorConfigurationSchema.js';
  39. import { EditOperation } from '../../common/core/editOperation.js';
  40. import { Position as Pos } from '../../common/core/position.js';
  41. import { Range } from '../../common/core/range.js';
  42. import { IModelService } from '../../common/services/model.js';
  43. import { ITextModelService } from '../../common/services/resolverService.js';
  44. import { ITextResourceConfigurationService, ITextResourcePropertiesService } from '../../common/services/textResourceConfiguration.js';
  45. import { CommandsRegistry, ICommandService } from '../../../platform/commands/common/commands.js';
  46. import { IConfigurationService } from '../../../platform/configuration/common/configuration.js';
  47. import { Configuration, ConfigurationModel, ConfigurationChangeEvent } from '../../../platform/configuration/common/configurationModels.js';
  48. import { IContextKeyService } from '../../../platform/contextkey/common/contextkey.js';
  49. import { IDialogService } from '../../../platform/dialogs/common/dialogs.js';
  50. import { createDecorator, IInstantiationService } from '../../../platform/instantiation/common/instantiation.js';
  51. import { AbstractKeybindingService } from '../../../platform/keybinding/common/abstractKeybindingService.js';
  52. import { IKeybindingService } from '../../../platform/keybinding/common/keybinding.js';
  53. import { KeybindingResolver } from '../../../platform/keybinding/common/keybindingResolver.js';
  54. import { KeybindingsRegistry } from '../../../platform/keybinding/common/keybindingsRegistry.js';
  55. import { ResolvedKeybindingItem } from '../../../platform/keybinding/common/resolvedKeybindingItem.js';
  56. import { USLayoutResolvedKeybinding } from '../../../platform/keybinding/common/usLayoutResolvedKeybinding.js';
  57. import { ILabelService } from '../../../platform/label/common/label.js';
  58. import { INotificationService, NoOpNotification } from '../../../platform/notification/common/notification.js';
  59. import { IEditorProgressService, IProgressService } from '../../../platform/progress/common/progress.js';
  60. import { ITelemetryService } from '../../../platform/telemetry/common/telemetry.js';
  61. import { IWorkspaceContextService, WorkspaceFolder } from '../../../platform/workspace/common/workspace.js';
  62. import { ILayoutService } from '../../../platform/layout/browser/layoutService.js';
  63. import { StandaloneServicesNLS } from '../../common/standaloneStrings.js';
  64. import { basename } from '../../../base/common/resources.js';
  65. import { ICodeEditorService } from '../../browser/services/codeEditorService.js';
  66. import { ConsoleLogger, ILogService, LogService } from '../../../platform/log/common/log.js';
  67. import { IWorkspaceTrustManagementService } from '../../../platform/workspace/common/workspaceTrust.js';
  68. import { IContextMenuService, IContextViewService } from '../../../platform/contextview/browser/contextView.js';
  69. import { ContextViewService } from '../../../platform/contextview/browser/contextViewService.js';
  70. import { LanguageService } from '../../common/services/languageService.js';
  71. import { ContextMenuService } from '../../../platform/contextview/browser/contextMenuService.js';
  72. import { IThemeService } from '../../../platform/theme/common/themeService.js';
  73. import { getSingletonServiceDescriptors, registerSingleton } from '../../../platform/instantiation/common/extensions.js';
  74. import { OpenerService } from '../../browser/services/openerService.js';
  75. import { IEditorWorkerService } from '../../common/services/editorWorker.js';
  76. import { EditorWorkerService } from '../../browser/services/editorWorkerService.js';
  77. import { ILanguageService } from '../../common/languages/language.js';
  78. import { MarkerDecorationsService } from '../../common/services/markerDecorationsService.js';
  79. import { IMarkerDecorationsService } from '../../common/services/markerDecorations.js';
  80. import { ModelService } from '../../common/services/modelService.js';
  81. import { StandaloneQuickInputService } from './quickInput/standaloneQuickInputService.js';
  82. import { StandaloneThemeService } from './standaloneThemeService.js';
  83. import { IStandaloneThemeService } from '../common/standaloneTheme.js';
  84. import { AccessibilityService } from '../../../platform/accessibility/browser/accessibilityService.js';
  85. import { IAccessibilityService } from '../../../platform/accessibility/common/accessibility.js';
  86. import { IMenuService } from '../../../platform/actions/common/actions.js';
  87. import { MenuService } from '../../../platform/actions/common/menuService.js';
  88. import { BrowserClipboardService } from '../../../platform/clipboard/browser/clipboardService.js';
  89. import { IClipboardService } from '../../../platform/clipboard/common/clipboardService.js';
  90. import { ContextKeyService } from '../../../platform/contextkey/browser/contextKeyService.js';
  91. import { SyncDescriptor } from '../../../platform/instantiation/common/descriptors.js';
  92. import { InstantiationService } from '../../../platform/instantiation/common/instantiationService.js';
  93. import { ServiceCollection } from '../../../platform/instantiation/common/serviceCollection.js';
  94. import { IListService, ListService } from '../../../platform/list/browser/listService.js';
  95. import { IMarkerService } from '../../../platform/markers/common/markers.js';
  96. import { MarkerService } from '../../../platform/markers/common/markerService.js';
  97. import { IOpenerService } from '../../../platform/opener/common/opener.js';
  98. import { IQuickInputService } from '../../../platform/quickinput/common/quickInput.js';
  99. import { IStorageService, InMemoryStorageService } from '../../../platform/storage/common/storage.js';
  100. import '../../common/services/languageFeaturesService.js';
  101. import { DefaultConfigurationModel } from '../../../platform/configuration/common/configurations.js';
  102. class SimpleModel {
  103. constructor(model) {
  104. this.disposed = false;
  105. this.model = model;
  106. this._onWillDispose = new Emitter();
  107. }
  108. get textEditorModel() {
  109. return this.model;
  110. }
  111. dispose() {
  112. this.disposed = true;
  113. this._onWillDispose.fire();
  114. }
  115. }
  116. let StandaloneTextModelService = class StandaloneTextModelService {
  117. constructor(modelService) {
  118. this.modelService = modelService;
  119. }
  120. createModelReference(resource) {
  121. const model = this.modelService.getModel(resource);
  122. if (!model) {
  123. return Promise.reject(new Error(`Model not found`));
  124. }
  125. return Promise.resolve(new ImmortalReference(new SimpleModel(model)));
  126. }
  127. };
  128. StandaloneTextModelService = __decorate([
  129. __param(0, IModelService)
  130. ], StandaloneTextModelService);
  131. class StandaloneEditorProgressService {
  132. show() {
  133. return StandaloneEditorProgressService.NULL_PROGRESS_RUNNER;
  134. }
  135. showWhile(promise, delay) {
  136. return __awaiter(this, void 0, void 0, function* () {
  137. yield promise;
  138. });
  139. }
  140. }
  141. StandaloneEditorProgressService.NULL_PROGRESS_RUNNER = {
  142. done: () => { },
  143. total: () => { },
  144. worked: () => { }
  145. };
  146. class StandaloneProgressService {
  147. withProgress(_options, task, onDidCancel) {
  148. return task({
  149. report: () => { },
  150. });
  151. }
  152. }
  153. class StandaloneDialogService {
  154. confirm(confirmation) {
  155. return this.doConfirm(confirmation).then(confirmed => {
  156. return {
  157. confirmed,
  158. checkboxChecked: false // unsupported
  159. };
  160. });
  161. }
  162. doConfirm(confirmation) {
  163. let messageText = confirmation.message;
  164. if (confirmation.detail) {
  165. messageText = messageText + '\n\n' + confirmation.detail;
  166. }
  167. return Promise.resolve(window.confirm(messageText));
  168. }
  169. show(severity, message, buttons, options) {
  170. return Promise.resolve({ choice: 0 });
  171. }
  172. }
  173. export class StandaloneNotificationService {
  174. info(message) {
  175. return this.notify({ severity: Severity.Info, message });
  176. }
  177. warn(message) {
  178. return this.notify({ severity: Severity.Warning, message });
  179. }
  180. error(error) {
  181. return this.notify({ severity: Severity.Error, message: error });
  182. }
  183. notify(notification) {
  184. switch (notification.severity) {
  185. case Severity.Error:
  186. console.error(notification.message);
  187. break;
  188. case Severity.Warning:
  189. console.warn(notification.message);
  190. break;
  191. default:
  192. console.log(notification.message);
  193. break;
  194. }
  195. return StandaloneNotificationService.NO_OP;
  196. }
  197. status(message, options) {
  198. return Disposable.None;
  199. }
  200. }
  201. StandaloneNotificationService.NO_OP = new NoOpNotification();
  202. let StandaloneCommandService = class StandaloneCommandService {
  203. constructor(instantiationService) {
  204. this._onWillExecuteCommand = new Emitter();
  205. this._onDidExecuteCommand = new Emitter();
  206. this.onWillExecuteCommand = this._onWillExecuteCommand.event;
  207. this.onDidExecuteCommand = this._onDidExecuteCommand.event;
  208. this._instantiationService = instantiationService;
  209. }
  210. executeCommand(id, ...args) {
  211. const command = CommandsRegistry.getCommand(id);
  212. if (!command) {
  213. return Promise.reject(new Error(`command '${id}' not found`));
  214. }
  215. try {
  216. this._onWillExecuteCommand.fire({ commandId: id, args });
  217. const result = this._instantiationService.invokeFunction.apply(this._instantiationService, [command.handler, ...args]);
  218. this._onDidExecuteCommand.fire({ commandId: id, args });
  219. return Promise.resolve(result);
  220. }
  221. catch (err) {
  222. return Promise.reject(err);
  223. }
  224. }
  225. };
  226. StandaloneCommandService = __decorate([
  227. __param(0, IInstantiationService)
  228. ], StandaloneCommandService);
  229. export { StandaloneCommandService };
  230. let StandaloneKeybindingService = class StandaloneKeybindingService extends AbstractKeybindingService {
  231. constructor(contextKeyService, commandService, telemetryService, notificationService, logService, codeEditorService) {
  232. super(contextKeyService, commandService, telemetryService, notificationService, logService);
  233. this._cachedResolver = null;
  234. this._dynamicKeybindings = [];
  235. this._domNodeListeners = [];
  236. const addContainer = (domNode) => {
  237. const disposables = new DisposableStore();
  238. // for standard keybindings
  239. disposables.add(dom.addDisposableListener(domNode, dom.EventType.KEY_DOWN, (e) => {
  240. const keyEvent = new StandardKeyboardEvent(e);
  241. const shouldPreventDefault = this._dispatch(keyEvent, keyEvent.target);
  242. if (shouldPreventDefault) {
  243. keyEvent.preventDefault();
  244. keyEvent.stopPropagation();
  245. }
  246. }));
  247. // for single modifier chord keybindings (e.g. shift shift)
  248. disposables.add(dom.addDisposableListener(domNode, dom.EventType.KEY_UP, (e) => {
  249. const keyEvent = new StandardKeyboardEvent(e);
  250. const shouldPreventDefault = this._singleModifierDispatch(keyEvent, keyEvent.target);
  251. if (shouldPreventDefault) {
  252. keyEvent.preventDefault();
  253. }
  254. }));
  255. this._domNodeListeners.push(new DomNodeListeners(domNode, disposables));
  256. };
  257. const removeContainer = (domNode) => {
  258. for (let i = 0; i < this._domNodeListeners.length; i++) {
  259. const domNodeListeners = this._domNodeListeners[i];
  260. if (domNodeListeners.domNode === domNode) {
  261. this._domNodeListeners.splice(i, 1);
  262. domNodeListeners.dispose();
  263. }
  264. }
  265. };
  266. const addCodeEditor = (codeEditor) => {
  267. if (codeEditor.getOption(56 /* EditorOption.inDiffEditor */)) {
  268. return;
  269. }
  270. addContainer(codeEditor.getContainerDomNode());
  271. };
  272. const removeCodeEditor = (codeEditor) => {
  273. if (codeEditor.getOption(56 /* EditorOption.inDiffEditor */)) {
  274. return;
  275. }
  276. removeContainer(codeEditor.getContainerDomNode());
  277. };
  278. this._register(codeEditorService.onCodeEditorAdd(addCodeEditor));
  279. this._register(codeEditorService.onCodeEditorRemove(removeCodeEditor));
  280. codeEditorService.listCodeEditors().forEach(addCodeEditor);
  281. const addDiffEditor = (diffEditor) => {
  282. addContainer(diffEditor.getContainerDomNode());
  283. };
  284. const removeDiffEditor = (diffEditor) => {
  285. removeContainer(diffEditor.getContainerDomNode());
  286. };
  287. this._register(codeEditorService.onDiffEditorAdd(addDiffEditor));
  288. this._register(codeEditorService.onDiffEditorRemove(removeDiffEditor));
  289. codeEditorService.listDiffEditors().forEach(addDiffEditor);
  290. }
  291. addDynamicKeybinding(command, keybinding, handler, when) {
  292. return combinedDisposable(CommandsRegistry.registerCommand(command, handler), this.addDynamicKeybindings([{
  293. keybinding,
  294. command,
  295. when
  296. }]));
  297. }
  298. addDynamicKeybindings(rules) {
  299. const entries = rules.map((rule) => {
  300. var _a, _b;
  301. const keybinding = createKeybinding(rule.keybinding, OS);
  302. return {
  303. keybinding: (_a = keybinding === null || keybinding === void 0 ? void 0 : keybinding.parts) !== null && _a !== void 0 ? _a : null,
  304. command: (_b = rule.command) !== null && _b !== void 0 ? _b : null,
  305. commandArgs: rule.commandArgs,
  306. when: rule.when,
  307. weight1: 1000,
  308. weight2: 0,
  309. extensionId: null,
  310. isBuiltinExtension: false
  311. };
  312. });
  313. this._dynamicKeybindings = this._dynamicKeybindings.concat(entries);
  314. this.updateResolver();
  315. return toDisposable(() => {
  316. // Search the first entry and remove them all since they will be contiguous
  317. for (let i = 0; i < this._dynamicKeybindings.length; i++) {
  318. if (this._dynamicKeybindings[i] === entries[0]) {
  319. this._dynamicKeybindings.splice(i, entries.length);
  320. this.updateResolver();
  321. return;
  322. }
  323. }
  324. });
  325. }
  326. updateResolver() {
  327. this._cachedResolver = null;
  328. this._onDidUpdateKeybindings.fire();
  329. }
  330. _getResolver() {
  331. if (!this._cachedResolver) {
  332. const defaults = this._toNormalizedKeybindingItems(KeybindingsRegistry.getDefaultKeybindings(), true);
  333. const overrides = this._toNormalizedKeybindingItems(this._dynamicKeybindings, false);
  334. this._cachedResolver = new KeybindingResolver(defaults, overrides, (str) => this._log(str));
  335. }
  336. return this._cachedResolver;
  337. }
  338. _documentHasFocus() {
  339. return document.hasFocus();
  340. }
  341. _toNormalizedKeybindingItems(items, isDefault) {
  342. const result = [];
  343. let resultLen = 0;
  344. for (const item of items) {
  345. const when = item.when || undefined;
  346. const keybinding = item.keybinding;
  347. if (!keybinding) {
  348. // This might be a removal keybinding item in user settings => accept it
  349. result[resultLen++] = new ResolvedKeybindingItem(undefined, item.command, item.commandArgs, when, isDefault, null, false);
  350. }
  351. else {
  352. const resolvedKeybindings = USLayoutResolvedKeybinding.resolveUserBinding(keybinding, OS);
  353. for (const resolvedKeybinding of resolvedKeybindings) {
  354. result[resultLen++] = new ResolvedKeybindingItem(resolvedKeybinding, item.command, item.commandArgs, when, isDefault, null, false);
  355. }
  356. }
  357. }
  358. return result;
  359. }
  360. resolveKeyboardEvent(keyboardEvent) {
  361. const keybinding = new SimpleKeybinding(keyboardEvent.ctrlKey, keyboardEvent.shiftKey, keyboardEvent.altKey, keyboardEvent.metaKey, keyboardEvent.keyCode).toChord();
  362. return new USLayoutResolvedKeybinding(keybinding, OS);
  363. }
  364. };
  365. StandaloneKeybindingService = __decorate([
  366. __param(0, IContextKeyService),
  367. __param(1, ICommandService),
  368. __param(2, ITelemetryService),
  369. __param(3, INotificationService),
  370. __param(4, ILogService),
  371. __param(5, ICodeEditorService)
  372. ], StandaloneKeybindingService);
  373. export { StandaloneKeybindingService };
  374. class DomNodeListeners extends Disposable {
  375. constructor(domNode, disposables) {
  376. super();
  377. this.domNode = domNode;
  378. this._register(disposables);
  379. }
  380. }
  381. function isConfigurationOverrides(thing) {
  382. return thing
  383. && typeof thing === 'object'
  384. && (!thing.overrideIdentifier || typeof thing.overrideIdentifier === 'string')
  385. && (!thing.resource || thing.resource instanceof URI);
  386. }
  387. export class StandaloneConfigurationService {
  388. constructor() {
  389. this._onDidChangeConfiguration = new Emitter();
  390. this.onDidChangeConfiguration = this._onDidChangeConfiguration.event;
  391. this._configuration = new Configuration(new DefaultConfigurationModel(), new ConfigurationModel(), new ConfigurationModel(), new ConfigurationModel());
  392. }
  393. getValue(arg1, arg2) {
  394. const section = typeof arg1 === 'string' ? arg1 : undefined;
  395. const overrides = isConfigurationOverrides(arg1) ? arg1 : isConfigurationOverrides(arg2) ? arg2 : {};
  396. return this._configuration.getValue(section, overrides, undefined);
  397. }
  398. updateValues(values) {
  399. const previous = { data: this._configuration.toData() };
  400. const changedKeys = [];
  401. for (const entry of values) {
  402. const [key, value] = entry;
  403. if (this.getValue(key) === value) {
  404. continue;
  405. }
  406. this._configuration.updateValue(key, value);
  407. changedKeys.push(key);
  408. }
  409. if (changedKeys.length > 0) {
  410. const configurationChangeEvent = new ConfigurationChangeEvent({ keys: changedKeys, overrides: [] }, previous, this._configuration);
  411. configurationChangeEvent.source = 8 /* ConfigurationTarget.MEMORY */;
  412. configurationChangeEvent.sourceConfig = null;
  413. this._onDidChangeConfiguration.fire(configurationChangeEvent);
  414. }
  415. return Promise.resolve();
  416. }
  417. updateValue(key, value, arg3, arg4) {
  418. return this.updateValues([[key, value]]);
  419. }
  420. inspect(key, options = {}) {
  421. return this._configuration.inspect(key, options, undefined);
  422. }
  423. }
  424. let StandaloneResourceConfigurationService = class StandaloneResourceConfigurationService {
  425. constructor(configurationService) {
  426. this.configurationService = configurationService;
  427. this._onDidChangeConfiguration = new Emitter();
  428. this.configurationService.onDidChangeConfiguration((e) => {
  429. this._onDidChangeConfiguration.fire({ affectedKeys: e.affectedKeys, affectsConfiguration: (resource, configuration) => e.affectsConfiguration(configuration) });
  430. });
  431. }
  432. getValue(resource, arg2, arg3) {
  433. const position = Pos.isIPosition(arg2) ? arg2 : null;
  434. const section = position ? (typeof arg3 === 'string' ? arg3 : undefined) : (typeof arg2 === 'string' ? arg2 : undefined);
  435. if (typeof section === 'undefined') {
  436. return this.configurationService.getValue();
  437. }
  438. return this.configurationService.getValue(section);
  439. }
  440. };
  441. StandaloneResourceConfigurationService = __decorate([
  442. __param(0, IConfigurationService)
  443. ], StandaloneResourceConfigurationService);
  444. let StandaloneResourcePropertiesService = class StandaloneResourcePropertiesService {
  445. constructor(configurationService) {
  446. this.configurationService = configurationService;
  447. }
  448. getEOL(resource, language) {
  449. const eol = this.configurationService.getValue('files.eol', { overrideIdentifier: language, resource });
  450. if (eol && typeof eol === 'string' && eol !== 'auto') {
  451. return eol;
  452. }
  453. return (isLinux || isMacintosh) ? '\n' : '\r\n';
  454. }
  455. };
  456. StandaloneResourcePropertiesService = __decorate([
  457. __param(0, IConfigurationService)
  458. ], StandaloneResourcePropertiesService);
  459. class StandaloneTelemetryService {
  460. publicLog(eventName, data) {
  461. return Promise.resolve(undefined);
  462. }
  463. publicLog2(eventName, data) {
  464. return this.publicLog(eventName, data);
  465. }
  466. }
  467. class StandaloneWorkspaceContextService {
  468. constructor() {
  469. const resource = URI.from({ scheme: StandaloneWorkspaceContextService.SCHEME, authority: 'model', path: '/' });
  470. this.workspace = { id: '4064f6ec-cb38-4ad0-af64-ee6467e63c82', folders: [new WorkspaceFolder({ uri: resource, name: '', index: 0 })] };
  471. }
  472. getWorkspace() {
  473. return this.workspace;
  474. }
  475. getWorkspaceFolder(resource) {
  476. return resource && resource.scheme === StandaloneWorkspaceContextService.SCHEME ? this.workspace.folders[0] : null;
  477. }
  478. }
  479. StandaloneWorkspaceContextService.SCHEME = 'inmemory';
  480. export function updateConfigurationService(configurationService, source, isDiffEditor) {
  481. if (!source) {
  482. return;
  483. }
  484. if (!(configurationService instanceof StandaloneConfigurationService)) {
  485. return;
  486. }
  487. const toUpdate = [];
  488. Object.keys(source).forEach((key) => {
  489. if (isEditorConfigurationKey(key)) {
  490. toUpdate.push([`editor.${key}`, source[key]]);
  491. }
  492. if (isDiffEditor && isDiffEditorConfigurationKey(key)) {
  493. toUpdate.push([`diffEditor.${key}`, source[key]]);
  494. }
  495. });
  496. if (toUpdate.length > 0) {
  497. configurationService.updateValues(toUpdate);
  498. }
  499. }
  500. let StandaloneBulkEditService = class StandaloneBulkEditService {
  501. constructor(_modelService) {
  502. this._modelService = _modelService;
  503. //
  504. }
  505. hasPreviewHandler() {
  506. return false;
  507. }
  508. apply(edits, _options) {
  509. return __awaiter(this, void 0, void 0, function* () {
  510. const textEdits = new Map();
  511. for (const edit of edits) {
  512. if (!(edit instanceof ResourceTextEdit)) {
  513. throw new Error('bad edit - only text edits are supported');
  514. }
  515. const model = this._modelService.getModel(edit.resource);
  516. if (!model) {
  517. throw new Error('bad edit - model not found');
  518. }
  519. if (typeof edit.versionId === 'number' && model.getVersionId() !== edit.versionId) {
  520. throw new Error('bad state - model changed in the meantime');
  521. }
  522. let array = textEdits.get(model);
  523. if (!array) {
  524. array = [];
  525. textEdits.set(model, array);
  526. }
  527. array.push(EditOperation.replaceMove(Range.lift(edit.textEdit.range), edit.textEdit.text));
  528. }
  529. let totalEdits = 0;
  530. let totalFiles = 0;
  531. for (const [model, edits] of textEdits) {
  532. model.pushStackElement();
  533. model.pushEditOperations([], edits, () => []);
  534. model.pushStackElement();
  535. totalFiles += 1;
  536. totalEdits += edits.length;
  537. }
  538. return {
  539. ariaSummary: strings.format(StandaloneServicesNLS.bulkEditServiceSummary, totalEdits, totalFiles)
  540. };
  541. });
  542. }
  543. };
  544. StandaloneBulkEditService = __decorate([
  545. __param(0, IModelService)
  546. ], StandaloneBulkEditService);
  547. class StandaloneUriLabelService {
  548. getUriLabel(resource, options) {
  549. if (resource.scheme === 'file') {
  550. return resource.fsPath;
  551. }
  552. return resource.path;
  553. }
  554. getUriBasenameLabel(resource) {
  555. return basename(resource);
  556. }
  557. }
  558. let StandaloneContextViewService = class StandaloneContextViewService extends ContextViewService {
  559. constructor(layoutService, _codeEditorService) {
  560. super(layoutService);
  561. this._codeEditorService = _codeEditorService;
  562. }
  563. showContextView(delegate, container, shadowRoot) {
  564. if (!container) {
  565. const codeEditor = this._codeEditorService.getFocusedCodeEditor() || this._codeEditorService.getActiveCodeEditor();
  566. if (codeEditor) {
  567. container = codeEditor.getContainerDomNode();
  568. }
  569. }
  570. return super.showContextView(delegate, container, shadowRoot);
  571. }
  572. };
  573. StandaloneContextViewService = __decorate([
  574. __param(0, ILayoutService),
  575. __param(1, ICodeEditorService)
  576. ], StandaloneContextViewService);
  577. class StandaloneWorkspaceTrustManagementService {
  578. constructor() {
  579. this._neverEmitter = new Emitter();
  580. this.onDidChangeTrust = this._neverEmitter.event;
  581. }
  582. isWorkspaceTrusted() {
  583. return true;
  584. }
  585. }
  586. class StandaloneLanguageService extends LanguageService {
  587. constructor() {
  588. super();
  589. }
  590. }
  591. class StandaloneLogService extends LogService {
  592. constructor() {
  593. super(new ConsoleLogger());
  594. }
  595. }
  596. let StandaloneContextMenuService = class StandaloneContextMenuService extends ContextMenuService {
  597. constructor(telemetryService, notificationService, contextViewService, keybindingService, themeService) {
  598. super(telemetryService, notificationService, contextViewService, keybindingService, themeService);
  599. this.configure({ blockMouse: false }); // we do not want that in the standalone editor
  600. }
  601. };
  602. StandaloneContextMenuService = __decorate([
  603. __param(0, ITelemetryService),
  604. __param(1, INotificationService),
  605. __param(2, IContextViewService),
  606. __param(3, IKeybindingService),
  607. __param(4, IThemeService)
  608. ], StandaloneContextMenuService);
  609. registerSingleton(IConfigurationService, StandaloneConfigurationService);
  610. registerSingleton(ITextResourceConfigurationService, StandaloneResourceConfigurationService);
  611. registerSingleton(ITextResourcePropertiesService, StandaloneResourcePropertiesService);
  612. registerSingleton(IWorkspaceContextService, StandaloneWorkspaceContextService);
  613. registerSingleton(ILabelService, StandaloneUriLabelService);
  614. registerSingleton(ITelemetryService, StandaloneTelemetryService);
  615. registerSingleton(IDialogService, StandaloneDialogService);
  616. registerSingleton(INotificationService, StandaloneNotificationService);
  617. registerSingleton(IMarkerService, MarkerService);
  618. registerSingleton(ILanguageService, StandaloneLanguageService);
  619. registerSingleton(IStandaloneThemeService, StandaloneThemeService);
  620. registerSingleton(ILogService, StandaloneLogService);
  621. registerSingleton(IModelService, ModelService);
  622. registerSingleton(IMarkerDecorationsService, MarkerDecorationsService);
  623. registerSingleton(IContextKeyService, ContextKeyService);
  624. registerSingleton(IProgressService, StandaloneProgressService);
  625. registerSingleton(IEditorProgressService, StandaloneEditorProgressService);
  626. registerSingleton(IStorageService, InMemoryStorageService);
  627. registerSingleton(IEditorWorkerService, EditorWorkerService);
  628. registerSingleton(IBulkEditService, StandaloneBulkEditService);
  629. registerSingleton(IWorkspaceTrustManagementService, StandaloneWorkspaceTrustManagementService);
  630. registerSingleton(ITextModelService, StandaloneTextModelService);
  631. registerSingleton(IAccessibilityService, AccessibilityService);
  632. registerSingleton(IListService, ListService);
  633. registerSingleton(ICommandService, StandaloneCommandService);
  634. registerSingleton(IKeybindingService, StandaloneKeybindingService);
  635. registerSingleton(IQuickInputService, StandaloneQuickInputService);
  636. registerSingleton(IContextViewService, StandaloneContextViewService);
  637. registerSingleton(IOpenerService, OpenerService);
  638. registerSingleton(IClipboardService, BrowserClipboardService);
  639. registerSingleton(IContextMenuService, StandaloneContextMenuService);
  640. registerSingleton(IMenuService, MenuService);
  641. /**
  642. * We don't want to eagerly instantiate services because embedders get a one time chance
  643. * to override services when they create the first editor.
  644. */
  645. export var StandaloneServices;
  646. (function (StandaloneServices) {
  647. const serviceCollection = new ServiceCollection();
  648. for (const [id, descriptor] of getSingletonServiceDescriptors()) {
  649. serviceCollection.set(id, descriptor);
  650. }
  651. const instantiationService = new InstantiationService(serviceCollection, true);
  652. serviceCollection.set(IInstantiationService, instantiationService);
  653. function get(serviceId) {
  654. const r = serviceCollection.get(serviceId);
  655. if (!r) {
  656. throw new Error('Missing service ' + serviceId);
  657. }
  658. if (r instanceof SyncDescriptor) {
  659. return instantiationService.invokeFunction((accessor) => accessor.get(serviceId));
  660. }
  661. else {
  662. return r;
  663. }
  664. }
  665. StandaloneServices.get = get;
  666. let initialized = false;
  667. function initialize(overrides) {
  668. if (initialized) {
  669. return instantiationService;
  670. }
  671. initialized = true;
  672. // Add singletons that were registered after this module loaded
  673. for (const [id, descriptor] of getSingletonServiceDescriptors()) {
  674. if (!serviceCollection.get(id)) {
  675. serviceCollection.set(id, descriptor);
  676. }
  677. }
  678. // Initialize the service collection with the overrides, but only if the
  679. // service was not instantiated in the meantime.
  680. for (const serviceId in overrides) {
  681. if (overrides.hasOwnProperty(serviceId)) {
  682. const serviceIdentifier = createDecorator(serviceId);
  683. const r = serviceCollection.get(serviceIdentifier);
  684. if (r instanceof SyncDescriptor) {
  685. serviceCollection.set(serviceIdentifier, overrides[serviceId]);
  686. }
  687. }
  688. }
  689. return instantiationService;
  690. }
  691. StandaloneServices.initialize = initialize;
  692. })(StandaloneServices || (StandaloneServices = {}));