1f8686caf83564fbdab4d3e0908fa7ee575023588117ae009c0b5550d488411fd111b1bb23de5a399e3073bfa2b243ecbfd19793531a661775d502f3242916 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. export class EditorSettingMigration {
  6. constructor(key, migrate) {
  7. this.key = key;
  8. this.migrate = migrate;
  9. }
  10. apply(options) {
  11. const value = EditorSettingMigration._read(options, this.key);
  12. const read = (key) => EditorSettingMigration._read(options, key);
  13. const write = (key, value) => EditorSettingMigration._write(options, key, value);
  14. this.migrate(value, read, write);
  15. }
  16. static _read(source, key) {
  17. if (typeof source === 'undefined') {
  18. return undefined;
  19. }
  20. const firstDotIndex = key.indexOf('.');
  21. if (firstDotIndex >= 0) {
  22. const firstSegment = key.substring(0, firstDotIndex);
  23. return this._read(source[firstSegment], key.substring(firstDotIndex + 1));
  24. }
  25. return source[key];
  26. }
  27. static _write(target, key, value) {
  28. const firstDotIndex = key.indexOf('.');
  29. if (firstDotIndex >= 0) {
  30. const firstSegment = key.substring(0, firstDotIndex);
  31. target[firstSegment] = target[firstSegment] || {};
  32. this._write(target[firstSegment], key.substring(firstDotIndex + 1), value);
  33. return;
  34. }
  35. target[key] = value;
  36. }
  37. }
  38. EditorSettingMigration.items = [];
  39. function registerEditorSettingMigration(key, migrate) {
  40. EditorSettingMigration.items.push(new EditorSettingMigration(key, migrate));
  41. }
  42. function registerSimpleEditorSettingMigration(key, values) {
  43. registerEditorSettingMigration(key, (value, read, write) => {
  44. if (typeof value !== 'undefined') {
  45. for (const [oldValue, newValue] of values) {
  46. if (value === oldValue) {
  47. write(key, newValue);
  48. return;
  49. }
  50. }
  51. }
  52. });
  53. }
  54. /**
  55. * Compatibility with old options
  56. */
  57. export function migrateOptions(options) {
  58. EditorSettingMigration.items.forEach(migration => migration.apply(options));
  59. }
  60. registerSimpleEditorSettingMigration('wordWrap', [[true, 'on'], [false, 'off']]);
  61. registerSimpleEditorSettingMigration('lineNumbers', [[true, 'on'], [false, 'off']]);
  62. registerSimpleEditorSettingMigration('cursorBlinking', [['visible', 'solid']]);
  63. registerSimpleEditorSettingMigration('renderWhitespace', [[true, 'boundary'], [false, 'none']]);
  64. registerSimpleEditorSettingMigration('renderLineHighlight', [[true, 'line'], [false, 'none']]);
  65. registerSimpleEditorSettingMigration('acceptSuggestionOnEnter', [[true, 'on'], [false, 'off']]);
  66. registerSimpleEditorSettingMigration('tabCompletion', [[false, 'off'], [true, 'onlySnippets']]);
  67. registerSimpleEditorSettingMigration('hover', [[true, { enabled: true }], [false, { enabled: false }]]);
  68. registerSimpleEditorSettingMigration('parameterHints', [[true, { enabled: true }], [false, { enabled: false }]]);
  69. registerSimpleEditorSettingMigration('autoIndent', [[false, 'advanced'], [true, 'full']]);
  70. registerSimpleEditorSettingMigration('matchBrackets', [[true, 'always'], [false, 'never']]);
  71. registerEditorSettingMigration('autoClosingBrackets', (value, read, write) => {
  72. if (value === false) {
  73. write('autoClosingBrackets', 'never');
  74. if (typeof read('autoClosingQuotes') === 'undefined') {
  75. write('autoClosingQuotes', 'never');
  76. }
  77. if (typeof read('autoSurround') === 'undefined') {
  78. write('autoSurround', 'never');
  79. }
  80. }
  81. });
  82. registerEditorSettingMigration('renderIndentGuides', (value, read, write) => {
  83. if (typeof value !== 'undefined') {
  84. write('renderIndentGuides', undefined);
  85. if (typeof read('guides.indentation') === 'undefined') {
  86. write('guides.indentation', !!value);
  87. }
  88. }
  89. });
  90. registerEditorSettingMigration('highlightActiveIndentGuide', (value, read, write) => {
  91. if (typeof value !== 'undefined') {
  92. write('highlightActiveIndentGuide', undefined);
  93. if (typeof read('guides.highlightActiveIndentation') === 'undefined') {
  94. write('guides.highlightActiveIndentation', !!value);
  95. }
  96. }
  97. });
  98. const suggestFilteredTypesMapping = {
  99. method: 'showMethods',
  100. function: 'showFunctions',
  101. constructor: 'showConstructors',
  102. deprecated: 'showDeprecated',
  103. field: 'showFields',
  104. variable: 'showVariables',
  105. class: 'showClasses',
  106. struct: 'showStructs',
  107. interface: 'showInterfaces',
  108. module: 'showModules',
  109. property: 'showProperties',
  110. event: 'showEvents',
  111. operator: 'showOperators',
  112. unit: 'showUnits',
  113. value: 'showValues',
  114. constant: 'showConstants',
  115. enum: 'showEnums',
  116. enumMember: 'showEnumMembers',
  117. keyword: 'showKeywords',
  118. text: 'showWords',
  119. color: 'showColors',
  120. file: 'showFiles',
  121. reference: 'showReferences',
  122. folder: 'showFolders',
  123. typeParameter: 'showTypeParameters',
  124. snippet: 'showSnippets',
  125. };
  126. registerEditorSettingMigration('suggest.filteredTypes', (value, read, write) => {
  127. if (value && typeof value === 'object') {
  128. for (const entry of Object.entries(suggestFilteredTypesMapping)) {
  129. const v = value[entry[0]];
  130. if (v === false) {
  131. if (typeof read(`suggest.${entry[1]}`) === 'undefined') {
  132. write(`suggest.${entry[1]}`, false);
  133. }
  134. }
  135. }
  136. write('suggest.filteredTypes', undefined);
  137. }
  138. });
  139. registerEditorSettingMigration('quickSuggestions', (input, read, write) => {
  140. if (typeof input === 'boolean') {
  141. const value = input ? 'on' : 'off';
  142. const newValue = { comments: value, strings: value, other: value };
  143. write('quickSuggestions', newValue);
  144. }
  145. });