Fix to use more accurate types with custom isArray() and add lint (#5261)
* Fix to use more accurate types with custom isArray() * Add lint against Array.isArray()
This commit is contained in:
7
packages/codemirror-lsp-client/src/lib/utils.ts
Normal file
7
packages/codemirror-lsp-client/src/lib/utils.ts
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* A safer type guard for arrays since the built-in Array.isArray() asserts `any[]`.
|
||||
*/
|
||||
export function isArray(val: any): val is unknown[] {
|
||||
// eslint-disable-next-line no-restricted-syntax
|
||||
return Array.isArray(val)
|
||||
}
|
||||
@ -2,6 +2,7 @@ import { Text } from '@codemirror/state'
|
||||
import { Marked } from '@ts-stack/markdown'
|
||||
|
||||
import type * as LSP from 'vscode-languageserver-protocol'
|
||||
import { isArray } from '../lib/utils'
|
||||
|
||||
// takes a function and executes it after the wait time, if the function is called again before the wait time is up, the timer is reset
|
||||
export function deferExecution<T>(func: (args: T) => any, wait: number) {
|
||||
@ -45,7 +46,7 @@ export function offsetToPos(doc: Text, offset: number) {
|
||||
export function formatMarkdownContents(
|
||||
contents: LSP.MarkupContent | LSP.MarkedString | LSP.MarkedString[]
|
||||
): string {
|
||||
if (Array.isArray(contents)) {
|
||||
if (isArray(contents)) {
|
||||
return contents.map((c) => formatMarkdownContents(c) + '\n\n').join('')
|
||||
} else if (typeof contents === 'string') {
|
||||
return Marked.parse(contents)
|
||||
|
||||
Reference in New Issue
Block a user