diff --git a/package.json b/package.json index 3372e9c..5987d2e 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "description": "View \"prettified\" and nested types in hover tooltips and sidebar.", "publisher": "MylesMurphy", "license": "MIT", - "version": "0.0.18", + "version": "0.0.19", "icon": "assets/logo.png", "engines": { "vscode": "^1.44.0" diff --git a/src/hover-provider.ts b/src/hover-provider.ts index ff0b1ec..0696d59 100644 --- a/src/hover-provider.ts +++ b/src/hover-provider.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode' import * as ts from 'typescript' import { prettifyType } from './prettify/prettify-type' -import { EXTENSION_ID } from './consts' +import { EXTENSION_ID, MARKDOWN_MAX_LENGTH } from './consts' import { getProject } from './project-cache' import { washString } from './prettify/prettify-functions' @@ -19,7 +19,7 @@ export function registerHoverProvider (context: vscode.ExtensionContext): void { const offset = document.offsetAt(position) const fileName = document.fileName - const typeString = prettifyType(fileName, content, offset) + let typeString = prettifyType(fileName, content, offset) if (typeString === undefined) return @@ -33,6 +33,10 @@ export function registerHoverProvider (context: vscode.ExtensionContext): void { if (washString(quickInfoText).includes(washString(typeString))) return } + if (typeString.length > MARKDOWN_MAX_LENGTH) { + typeString = typeString.substring(0, MARKDOWN_MAX_LENGTH) + '...' + } + const hoverText = new vscode.MarkdownString() hoverText.appendCodeblock(typeString, document.languageId) return new vscode.Hover(hoverText) diff --git a/src/prettify/prettify-type.ts b/src/prettify/prettify-type.ts index 4d09401..01cf647 100644 --- a/src/prettify/prettify-type.ts +++ b/src/prettify/prettify-type.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode' import { SyntaxKind } from 'ts-morph' import { ulid } from 'ulid' -import { EXTENSION_ID, MARKDOWN_MAX_LENGTH } from '../consts' +import { EXTENSION_ID } from '../consts' import { buildDeclarationString, getPrettifyType, formatDeclarationString } from './prettify-functions' import { getProject } from '../project-cache' import { ScriptElementKind } from 'typescript' @@ -86,10 +86,6 @@ export function prettifyType (fileName: string, content: string, offset: number) // Issue: Prettify doesn't always work for functions or complex types if (prettifiedTypeString === 'any') return - if (prettifiedTypeString.length > MARKDOWN_MAX_LENGTH) { - prettifiedTypeString = prettifiedTypeString.substring(0, MARKDOWN_MAX_LENGTH) + '...' - } - const declarationString = buildDeclarationString(parentNodeKind, nodeText, prettifiedTypeString) const typeString = formatDeclarationString(declarationString, typeIndentation) diff --git a/src/webviews/type-provider.ts b/src/webviews/type-provider.ts index 56ae514..d2f3c64 100644 --- a/src/webviews/type-provider.ts +++ b/src/webviews/type-provider.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode' import { prettifyType } from '../prettify/prettify-type' -import { EXTENSION_ID, IS_DEV } from '../consts' +import { EXTENSION_ID, IS_DEV, MARKDOWN_MAX_LENGTH } from '../consts' export class TypeProvider implements vscode.WebviewViewProvider { private readonly extensionContext: vscode.ExtensionContext @@ -74,7 +74,11 @@ export class TypeProvider implements vscode.WebviewViewProvider { const offset = document.offsetAt(position) updateWebview('', true) - const formattedTypeString = prettifyType(fileName, content, offset) ?? '' + let formattedTypeString = prettifyType(fileName, content, offset) ?? '' + + if (formattedTypeString.length > MARKDOWN_MAX_LENGTH) { + formattedTypeString = formattedTypeString.substring(0, MARKDOWN_MAX_LENGTH) + '...' + } updateWebview(formattedTypeString) }