@theia/core 1.34.0-next.7 → 1.34.1

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 (230) hide show
  1. package/README.md +6 -6
  2. package/i18n/nls.cs.json +26 -100
  3. package/i18n/nls.de.json +26 -100
  4. package/i18n/nls.es.json +26 -100
  5. package/i18n/nls.fr.json +26 -100
  6. package/i18n/nls.hu.json +26 -100
  7. package/i18n/nls.it.json +26 -100
  8. package/i18n/nls.ja.json +26 -100
  9. package/i18n/nls.json +26 -100
  10. package/i18n/nls.pl.json +26 -100
  11. package/i18n/nls.pt-br.json +26 -100
  12. package/i18n/nls.pt-pt.json +26 -100
  13. package/i18n/nls.ru.json +26 -100
  14. package/i18n/nls.zh-cn.json +26 -100
  15. package/lib/browser/about-dialog.js +1 -1
  16. package/lib/browser/about-dialog.js.map +1 -1
  17. package/lib/browser/common-frontend-contribution.js +1 -1
  18. package/lib/browser/common-frontend-contribution.js.map +1 -1
  19. package/lib/browser/core-preferences.d.ts.map +1 -1
  20. package/lib/browser/core-preferences.js +5 -6
  21. package/lib/browser/core-preferences.js.map +1 -1
  22. package/lib/browser/dialogs.js +1 -1
  23. package/lib/browser/dialogs.js.map +1 -1
  24. package/lib/browser/frontend-application.d.ts.map +1 -1
  25. package/lib/browser/frontend-application.js +12 -3
  26. package/lib/browser/frontend-application.js.map +1 -1
  27. package/lib/browser/i18n/language-quick-pick-service.js +2 -2
  28. package/lib/browser/i18n/language-quick-pick-service.js.map +1 -1
  29. package/lib/browser/label-parser.d.ts +1 -1
  30. package/lib/browser/label-parser.d.ts.map +1 -1
  31. package/lib/browser/label-parser.js +2 -1
  32. package/lib/browser/label-parser.js.map +1 -1
  33. package/lib/browser/label-provider.d.ts.map +1 -1
  34. package/lib/browser/label-provider.js +2 -3
  35. package/lib/browser/label-provider.js.map +1 -1
  36. package/lib/browser/navigatable-types.d.ts +1 -2
  37. package/lib/browser/navigatable-types.d.ts.map +1 -1
  38. package/lib/browser/navigatable-types.js +3 -2
  39. package/lib/browser/navigatable-types.js.map +1 -1
  40. package/lib/browser/preferences/injectable-preference-proxy.d.ts.map +1 -1
  41. package/lib/browser/preferences/injectable-preference-proxy.js +1 -1
  42. package/lib/browser/preferences/injectable-preference-proxy.js.map +1 -1
  43. package/lib/browser/preferences/preference-contribution.js +2 -1
  44. package/lib/browser/preferences/preference-contribution.js.map +1 -1
  45. package/lib/browser/preferences/preference-language-override-service.js +1 -1
  46. package/lib/browser/preferences/preference-language-override-service.js.map +1 -1
  47. package/lib/browser/preferences/preference-provider.d.ts.map +1 -1
  48. package/lib/browser/preferences/preference-provider.js +3 -7
  49. package/lib/browser/preferences/preference-provider.js.map +1 -1
  50. package/lib/browser/preferences/preference-proxy.d.ts.map +1 -1
  51. package/lib/browser/preferences/preference-proxy.js +3 -1
  52. package/lib/browser/preferences/preference-proxy.js.map +1 -1
  53. package/lib/browser/saveable.d.ts.map +1 -1
  54. package/lib/browser/saveable.js +3 -2
  55. package/lib/browser/saveable.js.map +1 -1
  56. package/lib/browser/shell/application-shell.d.ts +12 -0
  57. package/lib/browser/shell/application-shell.d.ts.map +1 -1
  58. package/lib/browser/shell/application-shell.js +74 -4
  59. package/lib/browser/shell/application-shell.js.map +1 -1
  60. package/lib/browser/shell/shell-layout-restorer.d.ts +1 -1
  61. package/lib/browser/shell/shell-layout-restorer.d.ts.map +1 -1
  62. package/lib/browser/shell/shell-layout-restorer.js +5 -10
  63. package/lib/browser/shell/shell-layout-restorer.js.map +1 -1
  64. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.d.ts +1 -1
  65. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.d.ts.map +1 -1
  66. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.js +6 -10
  67. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.js.map +1 -1
  68. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.js +1 -1
  69. package/lib/browser/shell/tab-bar-toolbar/tab-bar-toolbar.js.map +1 -1
  70. package/lib/browser/source-tree/tree-source.d.ts +1 -3
  71. package/lib/browser/source-tree/tree-source.d.ts.map +1 -1
  72. package/lib/browser/source-tree/tree-source.js +4 -5
  73. package/lib/browser/source-tree/tree-source.js.map +1 -1
  74. package/lib/browser/status-bar/status-bar.js +1 -1
  75. package/lib/browser/status-bar/status-bar.js.map +1 -1
  76. package/lib/browser/tree/tree-selection.d.ts.map +1 -1
  77. package/lib/browser/tree/tree-selection.js +2 -1
  78. package/lib/browser/tree/tree-selection.js.map +1 -1
  79. package/lib/browser/tree/tree-widget.d.ts +1 -0
  80. package/lib/browser/tree/tree-widget.d.ts.map +1 -1
  81. package/lib/browser/tree/tree-widget.js +5 -2
  82. package/lib/browser/tree/tree-widget.js.map +1 -1
  83. package/lib/browser/tree/tree.d.ts +1 -1
  84. package/lib/browser/tree/tree.d.ts.map +1 -1
  85. package/lib/browser/tree/tree.js +3 -2
  86. package/lib/browser/tree/tree.js.map +1 -1
  87. package/lib/browser/view-container.js +2 -2
  88. package/lib/browser/view-container.js.map +1 -1
  89. package/lib/browser/widgets/select-component.d.ts +1 -0
  90. package/lib/browser/widgets/select-component.d.ts.map +1 -1
  91. package/lib/browser/widgets/select-component.js +8 -3
  92. package/lib/browser/widgets/select-component.js.map +1 -1
  93. package/lib/browser/widgets/widget.d.ts.map +1 -1
  94. package/lib/browser/widgets/widget.js +1 -1
  95. package/lib/browser/widgets/widget.js.map +1 -1
  96. package/lib/common/array-utils.d.ts +49 -0
  97. package/lib/common/array-utils.d.ts.map +1 -0
  98. package/lib/common/array-utils.js +98 -0
  99. package/lib/common/array-utils.js.map +1 -0
  100. package/lib/common/cancellation.d.ts.map +1 -1
  101. package/lib/common/cancellation.js +4 -4
  102. package/lib/common/cancellation.js.map +1 -1
  103. package/lib/common/command.d.ts.map +1 -1
  104. package/lib/common/command.js +2 -1
  105. package/lib/common/command.js.map +1 -1
  106. package/lib/common/disposable.d.ts.map +1 -1
  107. package/lib/common/disposable.js +4 -3
  108. package/lib/common/disposable.js.map +1 -1
  109. package/lib/common/index.d.ts +20 -19
  110. package/lib/common/index.d.ts.map +1 -1
  111. package/lib/common/index.js +23 -20
  112. package/lib/common/index.js.map +1 -1
  113. package/lib/common/keybinding.d.ts.map +1 -1
  114. package/lib/common/keybinding.js +18 -2
  115. package/lib/common/keybinding.js.map +1 -1
  116. package/lib/common/keys.d.ts.map +1 -1
  117. package/lib/common/keys.js +2 -1
  118. package/lib/common/keys.js.map +1 -1
  119. package/lib/common/lsp-types.d.ts.map +1 -1
  120. package/lib/common/lsp-types.js +5 -6
  121. package/lib/common/lsp-types.js.map +1 -1
  122. package/lib/common/markdown-rendering/markdown-string.d.ts.map +1 -1
  123. package/lib/common/markdown-rendering/markdown-string.js +2 -2
  124. package/lib/common/markdown-rendering/markdown-string.js.map +1 -1
  125. package/lib/common/menu/menu-types.d.ts.map +1 -1
  126. package/lib/common/menu/menu-types.js +2 -1
  127. package/lib/common/menu/menu-types.js.map +1 -1
  128. package/lib/common/message-service-protocol.d.ts +1 -1
  129. package/lib/common/message-service-protocol.d.ts.map +1 -1
  130. package/lib/common/message-service-protocol.js +2 -1
  131. package/lib/common/message-service-protocol.js.map +1 -1
  132. package/lib/common/objects.d.ts.map +1 -1
  133. package/lib/common/objects.js +5 -5
  134. package/lib/common/objects.js.map +1 -1
  135. package/lib/common/preferences/preference-schema.d.ts.map +1 -1
  136. package/lib/common/preferences/preference-schema.js +4 -3
  137. package/lib/common/preferences/preference-schema.js.map +1 -1
  138. package/lib/common/prioritizeable.d.ts +17 -0
  139. package/lib/common/prioritizeable.d.ts.map +1 -0
  140. package/lib/common/prioritizeable.js +56 -0
  141. package/lib/common/prioritizeable.js.map +1 -0
  142. package/lib/common/promise-util.d.ts.map +1 -1
  143. package/lib/common/promise-util.js +2 -1
  144. package/lib/common/promise-util.js.map +1 -1
  145. package/lib/common/selection.d.ts.map +1 -1
  146. package/lib/common/selection.js +2 -1
  147. package/lib/common/selection.js.map +1 -1
  148. package/lib/common/types.d.ts +29 -73
  149. package/lib/common/types.d.ts.map +1 -1
  150. package/lib/common/types.js +53 -110
  151. package/lib/common/types.js.map +1 -1
  152. package/lib/common/uri-command-handler.d.ts.map +1 -1
  153. package/lib/common/uri-command-handler.js +2 -1
  154. package/lib/common/uri-command-handler.js.map +1 -1
  155. package/lib/common/uri.d.ts +1 -0
  156. package/lib/common/uri.d.ts.map +1 -1
  157. package/lib/common/uri.js +3 -0
  158. package/lib/common/uri.js.map +1 -1
  159. package/lib/common/view-column.d.ts +18 -0
  160. package/lib/common/view-column.d.ts.map +1 -0
  161. package/lib/common/view-column.js +37 -0
  162. package/lib/common/view-column.js.map +1 -0
  163. package/lib/electron-node/token/electron-token-validator.d.ts +1 -1
  164. package/lib/electron-node/token/electron-token-validator.d.ts.map +1 -1
  165. package/lib/electron-node/token/electron-token-validator.js +4 -5
  166. package/lib/electron-node/token/electron-token-validator.js.map +1 -1
  167. package/lib/node/backend-application.d.ts +1 -0
  168. package/lib/node/backend-application.d.ts.map +1 -1
  169. package/lib/node/backend-application.js +9 -6
  170. package/lib/node/backend-application.js.map +1 -1
  171. package/lib/node/i18n/localization-contribution.d.ts.map +1 -1
  172. package/lib/node/i18n/localization-contribution.js +2 -2
  173. package/lib/node/i18n/localization-contribution.js.map +1 -1
  174. package/package.json +6 -6
  175. package/shared/reflect-metadata/index.d.ts +1 -0
  176. package/shared/reflect-metadata/index.js +1 -0
  177. package/src/browser/about-dialog.tsx +1 -1
  178. package/src/browser/common-frontend-contribution.ts +1 -1
  179. package/src/browser/core-preferences.ts +5 -6
  180. package/src/browser/dialogs.ts +1 -1
  181. package/src/browser/frontend-application.ts +12 -4
  182. package/src/browser/i18n/language-quick-pick-service.ts +2 -2
  183. package/src/browser/label-parser.ts +3 -2
  184. package/src/browser/label-provider.ts +2 -3
  185. package/src/browser/navigatable-types.ts +6 -7
  186. package/src/browser/preferences/injectable-preference-proxy.ts +5 -3
  187. package/src/browser/preferences/preference-contribution.ts +2 -2
  188. package/src/browser/preferences/preference-language-override-service.ts +2 -2
  189. package/src/browser/preferences/preference-provider.ts +4 -8
  190. package/src/browser/preferences/preference-proxy.ts +2 -2
  191. package/src/browser/saveable.ts +3 -2
  192. package/src/browser/shell/application-shell.ts +83 -5
  193. package/src/browser/shell/shell-layout-restorer.ts +6 -11
  194. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar-types.ts +6 -11
  195. package/src/browser/shell/tab-bar-toolbar/tab-bar-toolbar.tsx +1 -1
  196. package/src/browser/source-tree/tree-source.ts +2 -4
  197. package/src/browser/status-bar/status-bar.tsx +1 -1
  198. package/src/browser/style/dialog.css +3 -2
  199. package/src/browser/style/index.css +0 -1
  200. package/src/browser/style/select-component.css +1 -0
  201. package/src/browser/tree/tree-selection.ts +2 -2
  202. package/src/browser/tree/tree-widget.tsx +5 -3
  203. package/src/browser/tree/tree.ts +3 -3
  204. package/src/browser/view-container.ts +3 -3
  205. package/src/browser/widgets/select-component.tsx +7 -3
  206. package/src/browser/widgets/widget.ts +2 -2
  207. package/src/common/array-utils.ts +109 -0
  208. package/src/common/cancellation.ts +4 -4
  209. package/src/common/command.ts +2 -1
  210. package/src/common/disposable.ts +3 -1
  211. package/src/common/i18n/nls.metadata.json +18565 -14326
  212. package/src/common/index.ts +20 -19
  213. package/src/common/keybinding.ts +5 -2
  214. package/src/common/keys.ts +2 -1
  215. package/src/common/lsp-types.ts +5 -6
  216. package/src/common/markdown-rendering/markdown-string.ts +2 -2
  217. package/src/common/menu/menu-types.ts +2 -1
  218. package/src/common/message-service-protocol.ts +2 -1
  219. package/src/common/objects.ts +7 -6
  220. package/src/common/preferences/preference-schema.ts +4 -3
  221. package/src/common/prioritizeable.ts +58 -0
  222. package/src/common/promise-util.ts +2 -1
  223. package/src/common/selection.ts +2 -1
  224. package/src/common/types.ts +57 -137
  225. package/src/common/uri-command-handler.ts +2 -2
  226. package/src/common/uri.ts +4 -0
  227. package/src/common/view-column.ts +33 -0
  228. package/src/electron-node/token/electron-token-validator.ts +5 -7
  229. package/src/node/backend-application.ts +10 -6
  230. package/src/node/i18n/localization-contribution.ts +3 -3
@@ -14,35 +14,36 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- export * from './types';
18
- export * from './disposable';
19
- export * from './reference';
20
- export * from './event';
17
+ export { environment } from '@theia/application-package/lib/environment';
18
+ export * from './application-error';
21
19
  export * from './cancellation';
22
20
  export * from './command';
23
- export * from './menu';
24
- export * from './selection-service';
25
- export * from './objects';
26
- export * from './os';
27
- export * from './resource';
21
+ export * from './contribution-filter';
28
22
  export * from './contribution-provider';
29
- export * from './path';
23
+ export * from './disposable';
24
+ export * from './event';
30
25
  export * from './logger';
31
- export * from './messaging';
26
+ export * from './lsp-types';
27
+ export * from './menu';
32
28
  export * from './message-rpc';
33
29
  export * from './message-service';
34
30
  export * from './message-service-protocol';
31
+ export * from './messaging';
32
+ export * from './nls';
33
+ export * from './numbers';
34
+ export * from './objects';
35
+ export * from './os';
36
+ export * from './path';
37
+ export * from './performance';
35
38
  export * from './progress-service';
36
39
  export * from './progress-service-protocol';
37
40
  export * from './quick-pick-service';
41
+ export * from './reference';
42
+ export * from './resource';
38
43
  export * from './selection';
44
+ export * from './selection-service';
39
45
  export * from './strings';
40
- export * from './application-error';
41
- export * from './lsp-types';
42
- export * from './contribution-filter';
43
- export * from './nls';
44
- export * from './numbers';
45
- export * from './performance';
46
+ export * from './types';
47
+ export { default as URI } from './uri';
48
+ export * from './view-column';
46
49
 
47
- import { environment } from '@theia/application-package/lib/environment';
48
- export { environment };
@@ -13,6 +13,9 @@
13
13
  //
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
+
17
+ import { isObject } from './types';
18
+
16
19
  /**
17
20
  * A Keybinding binds a specific key sequence ({@link Keybinding#keybinding}) to trigger a command ({@link Keybinding#command}). A Keybinding optionally may
18
21
  * define a "when clause" ({@link Keybinding#when}) to specify in which context it becomes active.
@@ -102,7 +105,7 @@ export namespace Keybinding {
102
105
 
103
106
  /* Determine whether object is a KeyBinding */
104
107
  export function is(arg: unknown): arg is Keybinding {
105
- return !!arg && typeof arg === 'object' && 'command' in arg && 'keybinding' in arg;
108
+ return isObject(arg) && 'command' in arg && 'keybinding' in arg;
106
109
  }
107
110
  }
108
111
 
@@ -118,6 +121,6 @@ export interface RawKeybinding extends Omit<Keybinding, 'keybinding'> {
118
121
 
119
122
  export namespace RawKeybinding {
120
123
  export function is(candidate: unknown): candidate is RawKeybinding {
121
- return typeof candidate === 'object' && !!candidate && 'command' in candidate && 'key' in candidate;
124
+ return isObject(candidate) && 'command' in candidate && 'key' in candidate;
122
125
  }
123
126
  }
@@ -15,6 +15,7 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { isOSX } from './os';
18
+ import { isObject } from './types';
18
19
 
19
20
  export type KeySequence = KeyCode[];
20
21
  export namespace KeySequence {
@@ -489,7 +490,7 @@ export namespace SpecialCases {
489
490
  export namespace Key {
490
491
 
491
492
  export function isKey(arg: unknown): arg is Key {
492
- return !!arg && typeof arg === 'object' && 'code' in arg && 'keyCode' in arg;
493
+ return isObject(arg) && 'code' in arg && 'keyCode' in arg;
493
494
  }
494
495
 
495
496
  export function getKey(arg: string | number): Key | undefined {
@@ -15,6 +15,7 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { Range } from 'vscode-languageserver-protocol';
18
+ import { isNumber, isObject, isString, isUndefined } from './types';
18
19
 
19
20
  export interface TextDocumentContentChangeDelta {
20
21
  readonly range: Range;
@@ -24,12 +25,10 @@ export interface TextDocumentContentChangeDelta {
24
25
  export namespace TextDocumentContentChangeDelta {
25
26
 
26
27
  export function is(arg: unknown): arg is TextDocumentContentChangeDelta {
27
- const changeDelta = arg as TextDocumentContentChangeDelta;
28
- return !!changeDelta
29
- && typeof changeDelta === 'object'
30
- && typeof changeDelta.text === 'string'
31
- && (typeof changeDelta.rangeLength === 'number' || typeof changeDelta.rangeLength === 'undefined')
32
- && Range.is(changeDelta.range);
28
+ return isObject<TextDocumentContentChangeDelta>(arg)
29
+ && isString(arg.text)
30
+ && (isNumber(arg.rangeLength) || isUndefined(arg.rangeLength))
31
+ && Range.is(arg.range);
33
32
  }
34
33
 
35
34
  }
@@ -17,6 +17,7 @@
17
17
  import { escapeRegExpCharacters } from '../strings';
18
18
  import { UriComponents } from '../uri';
19
19
  import { escapeIcons } from './icon-utilities';
20
+ import { isObject, isString } from '../types';
20
21
 
21
22
  export interface MarkdownString {
22
23
  readonly value: string;
@@ -37,8 +38,7 @@ export namespace MarkdownString {
37
38
  * @returns whether the candidate satisfies the interface of a markdown string
38
39
  */
39
40
  export function is(candidate: unknown): candidate is MarkdownString {
40
- const maybeMarkdownString = candidate as MarkdownString;
41
- return typeof maybeMarkdownString === 'object' && !!maybeMarkdownString && typeof maybeMarkdownString.value === 'string';
41
+ return isObject<MarkdownString>(candidate) && isString(candidate.value);
42
42
  }
43
43
  }
44
44
 
@@ -15,6 +15,7 @@
15
15
  // *****************************************************************************
16
16
 
17
17
  import { Disposable } from '../disposable';
18
+ import { isObject } from '../types';
18
19
 
19
20
  export type MenuPath = string[];
20
21
  export const MAIN_MENU_BAR: MenuPath = ['menubar'];
@@ -86,7 +87,7 @@ export interface MenuAction extends MenuNodeRenderingData, Pick<MenuNodeMetadata
86
87
  export namespace MenuAction {
87
88
  /* Determine whether object is a MenuAction */
88
89
  export function is(arg: unknown): arg is MenuAction {
89
- return !!arg && typeof arg === 'object' && 'commandId' in arg;
90
+ return isObject(arg) && 'commandId' in arg;
90
91
  }
91
92
  }
92
93
 
@@ -16,6 +16,7 @@
16
16
 
17
17
  import { injectable } from 'inversify';
18
18
  import { CancellationToken } from './cancellation';
19
+ import { nls } from './nls';
19
20
 
20
21
  export const messageServicePath = '/services/messageService';
21
22
 
@@ -52,7 +53,7 @@ export interface ProgressMessage extends Message {
52
53
  readonly options?: ProgressMessageOptions;
53
54
  }
54
55
  export namespace ProgressMessage {
55
- export const Cancel = 'Cancel';
56
+ export const Cancel = nls.localizeByDefault('Cancel');
56
57
  export function isCancelable(message: ProgressMessage): boolean {
57
58
  return !!message.options?.cancelable;
58
59
  }
@@ -14,8 +14,10 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
+ import { isObject } from './types';
18
+
17
19
  export function deepClone<T>(obj: T): T {
18
- if (!obj || typeof obj !== 'object') {
20
+ if (!isObject(obj)) {
19
21
  return obj;
20
22
  }
21
23
  if (obj instanceof RegExp) {
@@ -24,9 +26,8 @@ export function deepClone<T>(obj: T): T {
24
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
27
  const result: any = Array.isArray(obj) ? [] : {};
26
28
  Object.keys(obj).forEach((key: string) => {
27
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
28
- const prop = (<any>obj)[key];
29
- if (prop && typeof prop === 'object') {
29
+ const prop = obj[key];
30
+ if (isObject(prop)) {
30
31
  result[key] = deepClone(prop);
31
32
  } else {
32
33
  result[key] = prop;
@@ -36,7 +37,7 @@ export function deepClone<T>(obj: T): T {
36
37
  }
37
38
 
38
39
  export function deepFreeze<T>(obj: T): T {
39
- if (!obj || typeof obj !== 'object') {
40
+ if (!isObject(obj)) {
40
41
  return obj;
41
42
  }
42
43
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -47,7 +48,7 @@ export function deepFreeze<T>(obj: T): T {
47
48
  for (const key in objectToFreeze) {
48
49
  if (_hasOwnProperty.call(objectToFreeze, key)) {
49
50
  const prop = objectToFreeze[key];
50
- if (typeof prop === 'object' && !Object.isFrozen(prop)) {
51
+ if (isObject(prop) && !Object.isFrozen(prop)) {
51
52
  stack.push(prop);
52
53
  }
53
54
  }
@@ -19,6 +19,7 @@
19
19
  import { JSONValue } from '@phosphor/coreutils';
20
20
  import { IJSONSchema } from '../json-schema';
21
21
  import { PreferenceScope } from './preference-scope';
22
+ import { isObject, isString } from '../types';
22
23
 
23
24
  export interface PreferenceSchema {
24
25
  [name: string]: any,
@@ -28,7 +29,7 @@ export interface PreferenceSchema {
28
29
  }
29
30
  export namespace PreferenceSchema {
30
31
  export function is(obj: unknown): obj is PreferenceSchema {
31
- return !!obj && typeof obj === 'object' && ('properties' in obj) && PreferenceSchemaProperties.is((obj as PreferenceSchema).properties);
32
+ return isObject<PreferenceSchema>(obj) && PreferenceSchemaProperties.is(obj.properties);
32
33
  }
33
34
  export function getDefaultScope(schema: PreferenceSchema): PreferenceScope {
34
35
  let defaultScope: PreferenceScope = PreferenceScope.Workspace;
@@ -46,7 +47,7 @@ export interface PreferenceSchemaProperties {
46
47
  }
47
48
  export namespace PreferenceSchemaProperties {
48
49
  export function is(obj: unknown): obj is PreferenceSchemaProperties {
49
- return !!obj && typeof obj === 'object';
50
+ return isObject(obj);
50
51
  }
51
52
  }
52
53
 
@@ -86,7 +87,7 @@ export namespace PreferenceDataProperty {
86
87
  export function fromPreferenceSchemaProperty(schemaProps: PreferenceSchemaProperty, defaultScope: PreferenceScope = PreferenceScope.Workspace): PreferenceDataProperty {
87
88
  if (!schemaProps.scope) {
88
89
  schemaProps.scope = defaultScope;
89
- } else if (typeof schemaProps.scope === 'string') {
90
+ } else if (isString(schemaProps.scope)) {
90
91
  return Object.assign(schemaProps, { scope: PreferenceScope.fromString(schemaProps.scope) || defaultScope });
91
92
  }
92
93
  return <PreferenceDataProperty>schemaProps;
@@ -0,0 +1,58 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2023 Ericsson and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import type { MaybeArray, MaybePromise } from './types';
18
+
19
+ export interface Prioritizeable<T> {
20
+ readonly priority: number;
21
+ readonly value: T;
22
+ }
23
+ export namespace Prioritizeable {
24
+ export type GetPriority<T> = (value: T) => MaybePromise<number>;
25
+ export type GetPrioritySync<T> = (value: T) => number;
26
+ export async function toPrioritizeable<T>(rawValue: MaybePromise<T>, getPriority: GetPriority<T>): Promise<Prioritizeable<T>>;
27
+ export async function toPrioritizeable<T>(rawValue: MaybePromise<T>[], getPriority: GetPriority<T>): Promise<Prioritizeable<T>[]>;
28
+ export async function toPrioritizeable<T>(rawValue: MaybeArray<MaybePromise<T>>, getPriority: GetPriority<T>): Promise<MaybeArray<Prioritizeable<T>>> {
29
+ if (rawValue instanceof Array) {
30
+ return Promise.all(
31
+ rawValue.map(v => toPrioritizeable(v, getPriority))
32
+ );
33
+ }
34
+ const value = await rawValue;
35
+ const priority = await getPriority(value);
36
+ return { priority, value };
37
+ }
38
+ export function toPrioritizeableSync<T>(rawValue: T[], getPriority: GetPrioritySync<T>): Prioritizeable<T>[] {
39
+ return rawValue.map(v => ({
40
+ value: v,
41
+ priority: getPriority(v)
42
+ }));
43
+ }
44
+ export function prioritizeAllSync<T>(values: T[], getPriority: GetPrioritySync<T>): Prioritizeable<T>[] {
45
+ const prioritizeable = toPrioritizeableSync(values, getPriority);
46
+ return prioritizeable.filter(isValid).sort(compare);
47
+ }
48
+ export async function prioritizeAll<T>(values: MaybePromise<T>[], getPriority: GetPriority<T>): Promise<Prioritizeable<T>[]> {
49
+ const prioritizeable = await toPrioritizeable(values, getPriority);
50
+ return prioritizeable.filter(isValid).sort(compare);
51
+ }
52
+ export function isValid<T>(p: Prioritizeable<T>): boolean {
53
+ return p.priority > 0;
54
+ }
55
+ export function compare<T>(p: Prioritizeable<T>, p2: Prioritizeable<T>): number {
56
+ return p2.priority - p.priority;
57
+ }
58
+ }
@@ -17,6 +17,7 @@
17
17
  import { Disposable } from './disposable';
18
18
  import { Event } from './event';
19
19
  import { CancellationToken, CancellationError, cancelled } from './cancellation';
20
+ import { isFunction, isObject } from './types';
20
21
 
21
22
  /**
22
23
  * Simple implementation of the deferred pattern.
@@ -126,5 +127,5 @@ export function waitForEvent<T>(event: Event<T>, ms: number, thisArg?: any, disp
126
127
  }
127
128
 
128
129
  export function isThenable<T>(obj: unknown): obj is Promise<T> {
129
- return typeof obj === 'object' && !!obj && typeof (obj as Promise<unknown>).then === 'function';
130
+ return isObject<Promise<unknown>>(obj) && isFunction(obj.then);
130
131
  }
@@ -14,6 +14,7 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
+ import { isObject } from './types';
17
18
  import URI from './uri';
18
19
 
19
20
  export interface UriSelection {
@@ -23,7 +24,7 @@ export interface UriSelection {
23
24
  export namespace UriSelection {
24
25
 
25
26
  export function is(arg: unknown): arg is UriSelection {
26
- return !!arg && typeof arg === 'object' && ('uri' in arg) && (arg as UriSelection).uri instanceof URI;
27
+ return isObject<UriSelection>(arg) && arg.uri instanceof URI;
27
28
  }
28
29
 
29
30
  export function getUri(selection: unknown): URI | undefined {
@@ -14,161 +14,81 @@
14
14
  // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
15
  // *****************************************************************************
16
16
 
17
- export type Mutable<T> = { -readonly [P in keyof T]: T[P] };
18
- export type MaybeNull<T> = { [P in keyof T]: T[P] | null };
19
- export type MaybeUndefined<T> = { [P in keyof T]: T[P] | undefined };
20
-
21
- /**
22
- * Creates a shallow copy with all ownkeys of the original object that are `null` made `undefined`
23
- */
24
- export function nullToUndefined<T>(nullable: MaybeNull<T>): MaybeUndefined<T> {
25
- const undefinable = { ...nullable } as MaybeUndefined<T>;
26
- for (const key in nullable) {
27
- // eslint-disable-next-line no-null/no-null
28
- if (nullable[key] === null && Object.prototype.hasOwnProperty.call(nullable, key)) {
29
- undefinable[key] = undefined;
30
- }
31
- }
32
- return undefinable;
33
- }
17
+ export { ArrayUtils } from './array-utils';
18
+ export { Prioritizeable } from './prioritizeable';
34
19
 
35
- export type Deferred<T> = {
36
- [P in keyof T]: Promise<T[P]>
37
- };
20
+ export type Deferred<T> = { [P in keyof T]: Promise<T[P]> };
21
+ export type MaybeArray<T> = T | T[];
22
+ export type MaybeNull<T> = { [P in keyof T]: T[P] | null };
23
+ export type MaybePromise<T> = T | PromiseLike<T>;
24
+ export type MaybeUndefined<T> = { [P in keyof T]?: T[P] | undefined };
25
+ export type Mutable<T> = { -readonly [P in keyof T]: T[P] };
38
26
  export type RecursivePartial<T> = {
39
- [P in keyof T]?: T[P] extends Array<infer I>
40
- ? Array<RecursivePartial<I>>
27
+ [P in keyof T]?: T[P] extends (infer I)[]
28
+ ? RecursivePartial<I>[]
41
29
  : RecursivePartial<T[P]>;
42
30
  };
43
- export type MaybeArray<T> = T | T[];
44
- export type MaybePromise<T> = T | PromiseLike<T>;
45
31
 
46
- export interface Prioritizeable<T> {
47
- readonly priority: number;
48
- readonly value: T;
49
- }
50
- export namespace Prioritizeable {
51
- export type GetPriority<T> = (value: T) => MaybePromise<number>;
52
- export type GetPrioritySync<T> = (value: T) => number;
53
- export async function toPrioritizeable<T>(rawValue: MaybePromise<T>, getPriority: GetPriority<T>): Promise<Prioritizeable<T>>;
54
- export async function toPrioritizeable<T>(rawValue: MaybePromise<T>[], getPriority: GetPriority<T>): Promise<Prioritizeable<T>[]>;
55
- export async function toPrioritizeable<T>(rawValue: MaybeArray<MaybePromise<T>>, getPriority: GetPriority<T>): Promise<MaybeArray<Prioritizeable<T>>> {
56
- if (rawValue instanceof Array) {
57
- return Promise.all(
58
- rawValue.map(v => toPrioritizeable(v, getPriority))
59
- );
60
- }
61
- const value = await rawValue;
62
- const priority = await getPriority(value);
63
- return { priority, value };
64
- }
65
- export function toPrioritizeableSync<T>(rawValue: T[], getPriority: GetPrioritySync<T>): Prioritizeable<T>[] {
66
- return rawValue.map(v => ({
67
- value: v,
68
- priority: getPriority(v)
69
- }));
70
- }
71
- export function prioritizeAllSync<T>(values: T[], getPriority: GetPrioritySync<T>): Prioritizeable<T>[] {
72
- const prioritizeable = toPrioritizeableSync(values, getPriority);
73
- return prioritizeable.filter(isValid).sort(compare);
74
- }
75
- export async function prioritizeAll<T>(values: MaybePromise<T>[], getPriority: GetPriority<T>): Promise<Prioritizeable<T>[]> {
76
- const prioritizeable = await toPrioritizeable(values, getPriority);
77
- return prioritizeable.filter(isValid).sort(compare);
78
- }
79
- export function isValid<T>(p: Prioritizeable<T>): boolean {
80
- return p.priority > 0;
81
- }
82
- export function compare<T>(p: Prioritizeable<T>, p2: Prioritizeable<T>): number {
83
- return p2.priority - p.priority;
84
- }
32
+ export function isBoolean(value: unknown): value is boolean {
33
+ return value === true || value === false;
85
34
  }
86
35
 
87
- export namespace ArrayUtils {
88
- export interface Head<T> extends Array<T> {
89
- head(): T;
90
- }
91
-
92
- export interface Tail<T> extends Array<T> {
93
- tail(): T;
94
- }
95
-
96
- export interface Children<T> extends Array<T> {
97
- children(): Tail<T>
98
- }
36
+ export function isString(value: unknown): value is string {
37
+ return typeof value === 'string' || value instanceof String;
38
+ }
99
39
 
100
- export const TailImpl = {
101
- tail<T>(this: Array<T>): T {
102
- return this[this.length - 1];
103
- },
104
- };
40
+ export function isNumber(value: unknown): value is number {
41
+ return typeof value === 'number' || value instanceof Number;
42
+ }
105
43
 
106
- export const HeadAndChildrenImpl = {
107
- head<T>(this: Array<T>): T {
108
- return this[0];
109
- },
44
+ export function isError(value: unknown): value is Error {
45
+ return value instanceof Error;
46
+ }
110
47
 
111
- children<T>(this: Array<T>): Tail<T> {
112
- return Object.assign(this.slice(1), TailImpl);
113
- }
114
- };
48
+ export function isErrorLike(value: unknown): value is Error {
49
+ return isObject(value) && isString(value.name) && isString(value.message) && (isUndefined(value.stack) || isString(value.stack));
50
+ }
115
51
 
116
- export interface HeadAndTail<T> extends Head<T>, Tail<T>, Children<T> { }
52
+ // eslint-disable-next-line space-before-function-paren
53
+ export function isFunction<T extends (...args: unknown[]) => unknown>(value: unknown): value is T {
54
+ return typeof value === 'function';
55
+ }
117
56
 
118
- export function asTail<T>(array: Array<T>): Tail<T> {
119
- return Object.assign(array, TailImpl);
120
- }
57
+ export function isObject<T = Record<string | number | symbol, unknown>>(value: unknown): value is T {
58
+ // eslint-disable-next-line no-null/no-null
59
+ return typeof value === 'object' && value !== null;
60
+ }
121
61
 
122
- export function asHeadAndTail<T>(array: Array<T>): HeadAndTail<T> {
123
- return Object.assign(array, HeadAndChildrenImpl, TailImpl);
124
- }
62
+ export function isUndefined(value: unknown): value is undefined {
63
+ return typeof value === 'undefined';
64
+ }
125
65
 
126
- export enum Sort {
127
- LeftBeforeRight = -1,
128
- RightBeforeLeft = 1,
129
- Equal = 0,
130
- }
66
+ /**
67
+ * @param value value to check.
68
+ * @param every optional predicate ran on every element of the array.
69
+ * @param thisArg value to substitute `this` with when invoking in the predicate.
70
+ * @returns whether or not `value` is an array.
71
+ */
72
+ export function isArray<T>(value: unknown, every?: (value: unknown) => unknown, thisArg?: unknown): value is T[] {
73
+ return Array.isArray(value) && (!isFunction(every) || value.every(every, thisArg));
74
+ }
131
75
 
132
- // Copied from https://github.com/microsoft/vscode/blob/9c29becfad5f68270b9b23efeafb147722c5feba/src/vs/base/common/arrays.ts
133
- /**
134
- * Performs a binary search algorithm over a sorted collection. Useful for cases
135
- * when we need to perform a binary search over something that isn't actually an
136
- * array, and converting data to an array would defeat the use of binary search
137
- * in the first place.
138
- *
139
- * @param length The collection length.
140
- * @param compareToKey A function that takes an index of an element in the
141
- * collection and returns zero if the value at this index is equal to the
142
- * search key, a negative number if the value precedes the search key in the
143
- * sorting order, or a positive number if the search key precedes the value.
144
- * @return A non-negative index of an element, if found. If not found, the
145
- * result is -(n+1) (or ~n, using bitwise notation), where n is the index
146
- * where the key should be inserted to maintain the sorting order.
147
- */
148
- export function binarySearch2(length: number, compareToKey: (index: number) => number): number {
149
- let low = 0;
150
- let high = length - 1;
76
+ export function isStringArray(value: unknown): value is string[] {
77
+ return isArray(value, isString);
78
+ }
151
79
 
152
- while (low <= high) {
153
- const mid = ((low + high) / 2) | 0;
154
- const comp = compareToKey(mid);
155
- if (comp < 0) {
156
- low = mid + 1;
157
- } else if (comp > 0) {
158
- high = mid - 1;
159
- } else {
160
- return mid;
161
- }
80
+ /**
81
+ * Creates a shallow copy with all ownkeys of the original object that are `null` made `undefined`
82
+ */
83
+ export function nullToUndefined<T>(nullable: MaybeNull<T>): MaybeUndefined<T> {
84
+ const undefinable = { ...nullable } as MaybeUndefined<T>;
85
+ for (const key in nullable) {
86
+ // eslint-disable-next-line no-null/no-null
87
+ if (nullable[key] === null && Object.prototype.hasOwnProperty.call(nullable, key)) {
88
+ undefinable[key] = undefined;
162
89
  }
163
- return -(low + 1);
164
- }
165
-
166
- /**
167
- * @returns New array with all falsy values removed. The original array IS NOT modified.
168
- */
169
- export function coalesce<T>(array: ReadonlyArray<T | undefined | null>): T[] {
170
- return <T[]>array.filter(e => !!e);
171
90
  }
91
+ return undefinable;
172
92
  }
173
93
 
174
94
  /**
@@ -20,7 +20,7 @@ import { SelectionService } from '../common/selection-service';
20
20
  import { UriSelection } from '../common/selection';
21
21
  import { CommandHandler } from './command';
22
22
  import URI from './uri';
23
- import { MaybeArray } from './types';
23
+ import { isArray, MaybeArray } from './types';
24
24
 
25
25
  export interface UriCommandHandler<T extends MaybeArray<URI>> extends CommandHandler {
26
26
 
@@ -59,7 +59,7 @@ export class UriAwareCommandHandler<T extends MaybeArray<URI>> implements UriCom
59
59
  protected getUri(...args: any[]): T | undefined {
60
60
  const [maybeUriArray] = args;
61
61
  const firstArgIsOK = this.isMulti()
62
- ? Array.isArray(maybeUriArray) && maybeUriArray.every(uri => uri instanceof URI)
62
+ ? isArray(maybeUriArray, uri => uri instanceof URI)
63
63
  : maybeUriArray instanceof URI;
64
64
 
65
65
  if (firstArgIsOK) {
package/src/common/uri.ts CHANGED
@@ -23,6 +23,10 @@ export class URI {
23
23
  return new URI(Uri.revive(components));
24
24
  }
25
25
 
26
+ public static fromFilePath(path: string): URI {
27
+ return new URI(Uri.file(path));
28
+ }
29
+
26
30
  private readonly codeUri: Uri;
27
31
  private _path: Path | undefined;
28
32
 
@@ -0,0 +1,33 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 STMicroelectronics.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ /**
18
+ * Denotes a column in the editor window.
19
+ * Columns are used to show editors side by side.
20
+ */
21
+ export enum ViewColumn {
22
+ Active = -1,
23
+ Beside = -2,
24
+ One = 1,
25
+ Two = 2,
26
+ Three = 3,
27
+ Four = 4,
28
+ Five = 5,
29
+ Six = 6,
30
+ Seven = 7,
31
+ Eight = 8,
32
+ Nine = 9
33
+ }