From ceaeee01bca2261a771e4066046b1ad4880ef8fb Mon Sep 17 00:00:00 2001 From: smart-bo Date: Wed, 8 Sep 2021 11:38:05 -0400 Subject: [PATCH 1/8] issue 10025 --- packages/plugin/src/theia.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin/src/theia.d.ts b/packages/plugin/src/theia.d.ts index b02a840bda621..880018e7fb0c2 100644 --- a/packages/plugin/src/theia.d.ts +++ b/packages/plugin/src/theia.d.ts @@ -6154,7 +6154,7 @@ declare module '@theia/plugin' { * * @sample `let sel:DocumentSelector = { scheme: 'file', language: 'typescript' }`; */ - export type DocumentSelector = DocumentFilter | string | Array; + export type DocumentSelector = DocumentFilter | string | ReadonlyArray; /** * A tuple of two characters, like a pair of From 1ad9b1e2136f3e40db61e32a7d493fcb48ec69e9 Mon Sep 17 00:00:00 2001 From: smart-bo Date: Wed, 8 Sep 2021 16:06:36 -0400 Subject: [PATCH 2/8] fix errors from #10025 --- packages/plugin-ext/src/plugin/languages.ts | 5 ++++- packages/plugin-ext/src/plugin/type-converters.ts | 11 +++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts index c8e538f9bdb71..7311b57292e95 100644 --- a/packages/plugin-ext/src/plugin/languages.ts +++ b/packages/plugin-ext/src/plugin/languages.ts @@ -204,11 +204,14 @@ export class LanguagesExtImpl implements LanguagesExt { } private transformDocumentSelector(selector: theia.DocumentSelector): SerializedDocumentFilter[] { - if (Array.isArray(selector)) { + if (isArray(selector)) { return selector.map(sel => this.doTransformDocumentSelector(sel)!); } return [this.doTransformDocumentSelector(selector)!]; + function isArray(arg: any): arg is readonly any[] { + return Array.isArray(arg); + } } private doTransformDocumentSelector(selector: string | theia.DocumentFilter): SerializedDocumentFilter | undefined { diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 9580d1515d79a..2cb823be25746 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -169,9 +169,9 @@ export function fromRangeOrRangeWithMessage(ranges: theia.Range[] | theia.Decora }); } else { return ranges.map((r): DecorationOptions => - ({ - range: fromRange(r)! - })); + ({ + range: fromRange(r)! + })); } } @@ -213,7 +213,7 @@ export function toMarkdown(value: model.MarkdownString): MarkdownString { export function fromDocumentSelector(selector: theia.DocumentSelector | undefined): LanguageSelector | undefined { if (!selector) { return undefined; - } else if (Array.isArray(selector)) { + } else if (isArray(selector)) { return selector.map(fromDocumentSelector); } else if (typeof selector === 'string') { return selector; @@ -224,6 +224,9 @@ export function fromDocumentSelector(selector: theia.DocumentSelector | undefine pattern: fromGlobPattern(selector.pattern!) } as LanguageFilter; } + function isArray(arg: any): arg is readonly any[] { + return Array.isArray(arg); + } } From 32946a306b0fe37e1db60d7c7d82f9807744f764 Mon Sep 17 00:00:00 2001 From: smart-bo Date: Wed, 8 Sep 2021 16:52:33 -0400 Subject: [PATCH 3/8] issue 10025 --- git | 62 +++++++++++++++++++ packages/plugin-ext/src/plugin/languages.ts | 2 +- .../plugin-ext/src/plugin/type-converters.ts | 2 +- 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 git diff --git a/git b/git new file mode 100644 index 0000000000000..3032a407130ba --- /dev/null +++ b/git @@ -0,0 +1,62 @@ +commit 1ad9b1e2136f3e40db61e32a7d493fcb48ec69e9 (HEAD -> gh10025, origin/gh10025) +Author: smart-bo +Date: Wed Sep 8 16:06:36 2021 -0400 + + fix errors from #10025 + +diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts +index c8e538f9bdb..7311b57292e 100644 +--- a/packages/plugin-ext/src/plugin/languages.ts ++++ b/packages/plugin-ext/src/plugin/languages.ts +@@ -204,11 +204,14 @@ export class LanguagesExtImpl implements LanguagesExt { + } +  + private transformDocumentSelector(selector: theia.DocumentSelector): SerializedDocumentFilter[] { +- if (Array.isArray(selector)) { ++ if (isArray(selector)) { + return selector.map(sel => this.doTransformDocumentSelector(sel)!); + } +  + return [this.doTransformDocumentSelector(selector)!]; ++ function isArray(arg: any): arg is readonly any[] { ++ return Array.isArray(arg); ++ } + } +  + private doTransformDocumentSelector(selector: string | theia.DocumentFilter): SerializedDocumentFilter | undefined { +diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts +index 9580d1515d7..2cb823be257 100644 +--- a/packages/plugin-ext/src/plugin/type-converters.ts ++++ b/packages/plugin-ext/src/plugin/type-converters.ts +@@ -169,9 +169,9 @@ export function fromRangeOrRangeWithMessage(ranges: theia.Range[] | theia.Decora + }); + } else { + return ranges.map((r): DecorationOptions => +- ({ +- range: fromRange(r)! +- })); ++ ({ ++ range: fromRange(r)! ++ })); + } + } +  +@@ -213,7 +213,7 @@ export function toMarkdown(value: model.MarkdownString): MarkdownString { + export function fromDocumentSelector(selector: theia.DocumentSelector | undefined): LanguageSelector | undefined { + if (!selector) { + return undefined; +- } else if (Array.isArray(selector)) { ++ } else if (isArray(selector)) { + return selector.map(fromDocumentSelector); + } else if (typeof selector === 'string') { + return selector; +@@ -224,6 +224,9 @@ export function fromDocumentSelector(selector: theia.DocumentSelector | undefine + pattern: fromGlobPattern(selector.pattern!) + } as LanguageFilter; + } ++ function isArray(arg: any): arg is readonly any[] { ++ return Array.isArray(arg); ++ } +  + } +  diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts index 7311b57292e95..7ce6a45cc4233 100644 --- a/packages/plugin-ext/src/plugin/languages.ts +++ b/packages/plugin-ext/src/plugin/languages.ts @@ -209,7 +209,7 @@ export class LanguagesExtImpl implements LanguagesExt { } return [this.doTransformDocumentSelector(selector)!]; - function isArray(arg: any): arg is readonly any[] { + function isArray(arg: unknown): arg is readonly unknown[] { return Array.isArray(arg); } } diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 2cb823be25746..49042e8e965d4 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -224,7 +224,7 @@ export function fromDocumentSelector(selector: theia.DocumentSelector | undefine pattern: fromGlobPattern(selector.pattern!) } as LanguageFilter; } - function isArray(arg: any): arg is readonly any[] { + function isArray(arg: unknown): arg is readonly unknown[] { return Array.isArray(arg); } From 0c1f37b1fbbe3417704a8ff28f69f6c455991c5b Mon Sep 17 00:00:00 2001 From: smart-bo Date: Wed, 8 Sep 2021 16:58:35 -0400 Subject: [PATCH 4/8] issue 10025 --- git | 62 ------------------------------------------------------------- 1 file changed, 62 deletions(-) delete mode 100644 git diff --git a/git b/git deleted file mode 100644 index 3032a407130ba..0000000000000 --- a/git +++ /dev/null @@ -1,62 +0,0 @@ -commit 1ad9b1e2136f3e40db61e32a7d493fcb48ec69e9 (HEAD -> gh10025, origin/gh10025) -Author: smart-bo -Date: Wed Sep 8 16:06:36 2021 -0400 - - fix errors from #10025 - -diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts -index c8e538f9bdb..7311b57292e 100644 ---- a/packages/plugin-ext/src/plugin/languages.ts -+++ b/packages/plugin-ext/src/plugin/languages.ts -@@ -204,11 +204,14 @@ export class LanguagesExtImpl implements LanguagesExt { - } -  - private transformDocumentSelector(selector: theia.DocumentSelector): SerializedDocumentFilter[] { -- if (Array.isArray(selector)) { -+ if (isArray(selector)) { - return selector.map(sel => this.doTransformDocumentSelector(sel)!); - } -  - return [this.doTransformDocumentSelector(selector)!]; -+ function isArray(arg: any): arg is readonly any[] { -+ return Array.isArray(arg); -+ } - } -  - private doTransformDocumentSelector(selector: string | theia.DocumentFilter): SerializedDocumentFilter | undefined { -diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts -index 9580d1515d7..2cb823be257 100644 ---- a/packages/plugin-ext/src/plugin/type-converters.ts -+++ b/packages/plugin-ext/src/plugin/type-converters.ts -@@ -169,9 +169,9 @@ export function fromRangeOrRangeWithMessage(ranges: theia.Range[] | theia.Decora - }); - } else { - return ranges.map((r): DecorationOptions => -- ({ -- range: fromRange(r)! -- })); -+ ({ -+ range: fromRange(r)! -+ })); - } - } -  -@@ -213,7 +213,7 @@ export function toMarkdown(value: model.MarkdownString): MarkdownString { - export function fromDocumentSelector(selector: theia.DocumentSelector | undefined): LanguageSelector | undefined { - if (!selector) { - return undefined; -- } else if (Array.isArray(selector)) { -+ } else if (isArray(selector)) { - return selector.map(fromDocumentSelector); - } else if (typeof selector === 'string') { - return selector; -@@ -224,6 +224,9 @@ export function fromDocumentSelector(selector: theia.DocumentSelector | undefine - pattern: fromGlobPattern(selector.pattern!) - } as LanguageFilter; - } -+ function isArray(arg: any): arg is readonly any[] { -+ return Array.isArray(arg); -+ } -  - } -  From c1f78a0367e1e089247294fa311c925e8be7517a Mon Sep 17 00:00:00 2001 From: smart-bo Date: Mon, 13 Sep 2021 15:06:36 -0400 Subject: [PATCH 5/8] share isArray function --- packages/plugin-ext/src/common/arrays.ts | 7 +++++++ packages/plugin-ext/src/plugin/languages.ts | 7 ++++--- packages/plugin-ext/src/plugin/type-converters.ts | 4 +--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/plugin-ext/src/common/arrays.ts b/packages/plugin-ext/src/common/arrays.ts index c4d5273b1c974..0d445ff241a0c 100644 --- a/packages/plugin-ext/src/common/arrays.ts +++ b/packages/plugin-ext/src/common/arrays.ts @@ -44,3 +44,10 @@ export interface Splice { readonly deleteCount: number; readonly toInsert: T[]; } + +/** + * @returns True if the input object is an array. + */ +export function isArray(arg: unknown): arg is readonly unknown[] { + return Array.isArray(arg); +} diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts index 7ce6a45cc4233..c7e6510f95b93 100644 --- a/packages/plugin-ext/src/plugin/languages.ts +++ b/packages/plugin-ext/src/plugin/languages.ts @@ -90,6 +90,7 @@ import { DeclarationAdapter } from './languages/declaration'; import { CallHierarchyAdapter } from './languages/call-hierarchy'; import { BinaryBuffer } from '@theia/core/lib/common/buffer'; import { DocumentSemanticTokensAdapter, DocumentRangeSemanticTokensAdapter } from './languages/semantic-highlighting'; +import { isArray } from '../common/arrays'; type Adapter = CompletionAdapter | SignatureHelpAdapter | @@ -209,9 +210,9 @@ export class LanguagesExtImpl implements LanguagesExt { } return [this.doTransformDocumentSelector(selector)!]; - function isArray(arg: unknown): arg is readonly unknown[] { - return Array.isArray(arg); - } + // function isArray(arg: unknown): arg is readonly unknown[] { + // return Array.isArray(arg); + // } } private doTransformDocumentSelector(selector: string | theia.DocumentFilter): SerializedDocumentFilter | undefined { diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 49042e8e965d4..8fd03320848f2 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -27,6 +27,7 @@ import { isMarkdownString, MarkdownString } from './markdown-string'; import * as types from './types-impl'; import { UriComponents } from '../common/uri-components'; import { TaskGroup } from './types-impl'; +import { isArray } from '../common/arrays'; const SIDE_GROUP = -2; const ACTIVE_GROUP = -1; @@ -224,9 +225,6 @@ export function fromDocumentSelector(selector: theia.DocumentSelector | undefine pattern: fromGlobPattern(selector.pattern!) } as LanguageFilter; } - function isArray(arg: unknown): arg is readonly unknown[] { - return Array.isArray(arg); - } } From de0d6260baf9e0f4f52c7b0ea176df147d5739ad Mon Sep 17 00:00:00 2001 From: smart-bo Date: Mon, 13 Sep 2021 15:20:23 -0400 Subject: [PATCH 6/8] Change function isArray to isArrayAsReadonly --- packages/plugin-ext/src/common/arrays.ts | 4 ++-- packages/plugin-ext/src/plugin/languages.ts | 7 ++----- packages/plugin-ext/src/plugin/type-converters.ts | 4 ++-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/plugin-ext/src/common/arrays.ts b/packages/plugin-ext/src/common/arrays.ts index 0d445ff241a0c..287aa955a318d 100644 --- a/packages/plugin-ext/src/common/arrays.ts +++ b/packages/plugin-ext/src/common/arrays.ts @@ -46,8 +46,8 @@ export interface Splice { } /** - * @returns True if the input object is an array. + * @returns True if the input object is readonlyarray. */ -export function isArray(arg: unknown): arg is readonly unknown[] { +export function isArrayAsReadonly(arg: unknown): arg is readonly unknown[] { return Array.isArray(arg); } diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts index c7e6510f95b93..3d6fc8aa5ad0c 100644 --- a/packages/plugin-ext/src/plugin/languages.ts +++ b/packages/plugin-ext/src/plugin/languages.ts @@ -90,7 +90,7 @@ import { DeclarationAdapter } from './languages/declaration'; import { CallHierarchyAdapter } from './languages/call-hierarchy'; import { BinaryBuffer } from '@theia/core/lib/common/buffer'; import { DocumentSemanticTokensAdapter, DocumentRangeSemanticTokensAdapter } from './languages/semantic-highlighting'; -import { isArray } from '../common/arrays'; +import { isArrayAsReadonly } from '../common/arrays'; type Adapter = CompletionAdapter | SignatureHelpAdapter | @@ -205,14 +205,11 @@ export class LanguagesExtImpl implements LanguagesExt { } private transformDocumentSelector(selector: theia.DocumentSelector): SerializedDocumentFilter[] { - if (isArray(selector)) { + if (isArrayAsReadonly(selector)) { return selector.map(sel => this.doTransformDocumentSelector(sel)!); } return [this.doTransformDocumentSelector(selector)!]; - // function isArray(arg: unknown): arg is readonly unknown[] { - // return Array.isArray(arg); - // } } private doTransformDocumentSelector(selector: string | theia.DocumentFilter): SerializedDocumentFilter | undefined { diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 8fd03320848f2..1c08d0ec446aa 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -27,7 +27,7 @@ import { isMarkdownString, MarkdownString } from './markdown-string'; import * as types from './types-impl'; import { UriComponents } from '../common/uri-components'; import { TaskGroup } from './types-impl'; -import { isArray } from '../common/arrays'; +import { isArrayAsReadonly } from '../common/arrays'; const SIDE_GROUP = -2; const ACTIVE_GROUP = -1; @@ -214,7 +214,7 @@ export function toMarkdown(value: model.MarkdownString): MarkdownString { export function fromDocumentSelector(selector: theia.DocumentSelector | undefined): LanguageSelector | undefined { if (!selector) { return undefined; - } else if (isArray(selector)) { + } else if (isArrayAsReadonly(selector)) { return selector.map(fromDocumentSelector); } else if (typeof selector === 'string') { return selector; From b289c0a035a6ac7ced9b6c8820fd7081ee6c6f9c Mon Sep 17 00:00:00 2001 From: smart-bo Date: Mon, 13 Sep 2021 15:56:44 -0400 Subject: [PATCH 7/8] Specify comment and modify function name to 'isReadonlyArray' --- packages/plugin-ext/src/common/arrays.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/plugin-ext/src/common/arrays.ts b/packages/plugin-ext/src/common/arrays.ts index 287aa955a318d..c185146a6f785 100644 --- a/packages/plugin-ext/src/common/arrays.ts +++ b/packages/plugin-ext/src/common/arrays.ts @@ -46,8 +46,9 @@ export interface Splice { } /** - * @returns True if the input object is readonlyarray. + * @returns 'true' if the 'arg' is a 'ReadonlyArray'. */ -export function isArrayAsReadonly(arg: unknown): arg is readonly unknown[] { +export function isReadonlyArray(arg: unknown): arg is readonly unknown[] { + // Since Typescript does not properly narrow down typings for 'ReadonlyArray' we need to help it. return Array.isArray(arg); } From a8d2beb825200011df8678904b13ca2dd17d649f Mon Sep 17 00:00:00 2001 From: smart-bo Date: Mon, 13 Sep 2021 16:59:54 -0400 Subject: [PATCH 8/8] Update function name --- packages/plugin-ext/src/plugin/languages.ts | 4 ++-- packages/plugin-ext/src/plugin/type-converters.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/plugin-ext/src/plugin/languages.ts b/packages/plugin-ext/src/plugin/languages.ts index 3d6fc8aa5ad0c..674c00ae34281 100644 --- a/packages/plugin-ext/src/plugin/languages.ts +++ b/packages/plugin-ext/src/plugin/languages.ts @@ -90,7 +90,7 @@ import { DeclarationAdapter } from './languages/declaration'; import { CallHierarchyAdapter } from './languages/call-hierarchy'; import { BinaryBuffer } from '@theia/core/lib/common/buffer'; import { DocumentSemanticTokensAdapter, DocumentRangeSemanticTokensAdapter } from './languages/semantic-highlighting'; -import { isArrayAsReadonly } from '../common/arrays'; +import { isReadonlyArray } from '../common/arrays'; type Adapter = CompletionAdapter | SignatureHelpAdapter | @@ -205,7 +205,7 @@ export class LanguagesExtImpl implements LanguagesExt { } private transformDocumentSelector(selector: theia.DocumentSelector): SerializedDocumentFilter[] { - if (isArrayAsReadonly(selector)) { + if (isReadonlyArray(selector)) { return selector.map(sel => this.doTransformDocumentSelector(sel)!); } diff --git a/packages/plugin-ext/src/plugin/type-converters.ts b/packages/plugin-ext/src/plugin/type-converters.ts index 1c08d0ec446aa..ec5fcc2bfcfd6 100644 --- a/packages/plugin-ext/src/plugin/type-converters.ts +++ b/packages/plugin-ext/src/plugin/type-converters.ts @@ -27,7 +27,7 @@ import { isMarkdownString, MarkdownString } from './markdown-string'; import * as types from './types-impl'; import { UriComponents } from '../common/uri-components'; import { TaskGroup } from './types-impl'; -import { isArrayAsReadonly } from '../common/arrays'; +import { isReadonlyArray } from '../common/arrays'; const SIDE_GROUP = -2; const ACTIVE_GROUP = -1; @@ -214,7 +214,7 @@ export function toMarkdown(value: model.MarkdownString): MarkdownString { export function fromDocumentSelector(selector: theia.DocumentSelector | undefined): LanguageSelector | undefined { if (!selector) { return undefined; - } else if (isArrayAsReadonly(selector)) { + } else if (isReadonlyArray(selector)) { return selector.map(fromDocumentSelector); } else if (typeof selector === 'string') { return selector;