Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update deps #44

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ module.exports = {
],
root: true,
rules: {
"@typescript-eslint/no-unused-vars": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-duplicate-enum-values": "off",
"@typescript-eslint/no-floating-promises": "off",
"import/no-extraneous-dependencies": [
"error",
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
"@types/mocha": "^10.0.0",
"@types/node": "^18.8.0",
"@types/react": "^18.0.24",
"@typescript-eslint/eslint-plugin": "^5.40.1",
"@typescript-eslint/parser": "^5.40.1",
"@wdio/cli": "^8.0.15",
"@wdio/local-runner": "^8.0.15",
"@wdio/mocha-framework": "^8.0.14",
"@wdio/spec-reporter": "^8.0.14",
"@typescript-eslint/eslint-plugin": "^6.9.0",
"@typescript-eslint/parser": "^6.9.0",
"@wdio/cli": "~8.0.15",
"@wdio/local-runner": "~8.0.15",
"@wdio/mocha-framework": "~8.0.14",
"@wdio/spec-reporter": "~8.0.14",
"eslint": "^8.26.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.2",
Expand All @@ -47,8 +47,8 @@
"mocha": "^10.0.0",
"prettier": "2.7.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"wdio-vscode-service": "^5.0.0"
"typescript": "^5.3.0",
"wdio-vscode-service": "^5.2.3"
},
"resolutions": {
"@types/react": "^18.0.24"
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"type": "commonjs",
"license": "MIT",
"devDependencies": {
"typescript": "^4.8.4"
"typescript": "^5.3.0"
}
}
10 changes: 5 additions & 5 deletions packages/api/src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,8 +434,8 @@ function _generateTypeTree(
types: parseTypes(getTypeArguments(tsCtx, type)!),
names: (
type.target as ts.TupleType
).labeledElementDeclarations?.map((s) =>
s.name.getText()
).labeledElementDeclarations?.map(
(s) => s?.name.getText() || ""
),
...(isReadonly && { readonly: true }),
}
Expand Down Expand Up @@ -558,8 +558,8 @@ function _generateTypeTree(
return {
kind: "substitution",
baseType: parseType((type as ts.SubstitutionType).baseType),
substitute: parseType(
(type as ts.SubstitutionType).substitute
constraint: parseType(
(type as ts.SubstitutionType).constraint
),
}
} else if (flags & ts.TypeFlags.NonPrimitive) {
Expand Down Expand Up @@ -908,7 +908,7 @@ export function getTypeInfoChildren(info: TypeInfo): TypeInfo[] {
}

case "substitution": {
return [info.baseType, info.substitute]
return [info.baseType, info.constraint]
}

case "template_literal": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export type TypeInfoNoId = {
| {
kind: "substitution"
baseType: TypeInfo
substitute: TypeInfo
constraint: TypeInfo
}
| { kind: "non_primitive" }
| { kind: "intrinsic" }
Expand Down
8 changes: 5 additions & 3 deletions packages/api/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export function createType(ctx: TypescriptContext, flags: ts.TypeFlags) {
export function createObjectType(
ctx: TypescriptContext,
objectFlags: ts.ObjectFlags,
flags: ts.TypeFlags = 0
flags: ts.TypeFlags = 2
): ObjectTypeInternal {
const type = createType(
ctx,
Expand All @@ -239,7 +239,7 @@ export function createObjectType(
export function createUnionType(
ctx: TypescriptContext,
types: ts.Type[] = [],
flags: ts.TypeFlags = 0
flags: ts.TypeFlags = 2
): UnionTypeInternal {
const type = createType(
ctx,
Expand All @@ -257,7 +257,7 @@ export function createUnionType(
export function createIntersectionType(
ctx: TypescriptContext,
types: ts.Type[] = [],
flags: ts.TypeFlags = 0
flags: ts.TypeFlags = 2
): IntersectionTypeInternal {
const type = createType(
ctx,
Expand Down Expand Up @@ -668,6 +668,8 @@ function getLeftHandSideExpression(node: ts.CallLikeExpression) {
return node.tag
} else if ("tagName" in node) {
return node.tagName
} else if ("left" in node) {
return node.left
} else {
return node.expression
}
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-explorer-vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
"fs-extra": "^10.1.0",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"typescript": "^4.8.4",
"typescript": "^5.3.0",
"vsce": "^2.13.0"
}
}
24 changes: 12 additions & 12 deletions packages/typescript-explorer-vscode/src/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from "vscode"
import * as Proto from "typescript/lib/protocol"
import type * as ts from "typescript/lib/tsserverlibrary"

export interface IFilePathToResourceConverter {
/**
Expand Down Expand Up @@ -41,7 +41,7 @@ function processInlineTags(text: string): string {
}

function getTagBodyText(
tag: Proto.JSDocTagInfo,
tag: ts.server.protocol.JSDocTagInfo,
filePathConverter: IFilePathToResourceConverter
): string | undefined {
if (!tag.text) {
Expand Down Expand Up @@ -91,7 +91,7 @@ function getTagBodyText(
}

function getTagDocumentation(
tag: Proto.JSDocTagInfo,
tag: ts.server.protocol.JSDocTagInfo,
filePathConverter: IFilePathToResourceConverter
): string | undefined {
switch (tag.name) {
Expand Down Expand Up @@ -129,7 +129,7 @@ function getTagDocumentation(
}

export function plainWithLinks(
parts: readonly Proto.SymbolDisplayPart[] | string,
parts: readonly ts.server.protocol.SymbolDisplayPart[] | string,
filePathConverter: IFilePathToResourceConverter
): string {
return processInlineTags(convertLinkTags(parts, filePathConverter))
Expand All @@ -139,7 +139,7 @@ export function plainWithLinks(
* Convert `@link` inline tags to markdown links
*/
function convertLinkTags(
parts: readonly Proto.SymbolDisplayPart[] | string | undefined,
parts: readonly ts.server.protocol.SymbolDisplayPart[] | string | undefined,
filePathConverter: IFilePathToResourceConverter
): string {
if (!parts) {
Expand All @@ -155,7 +155,7 @@ function convertLinkTags(
let currentLink:
| {
name?: string
target?: Proto.FileSpan
target?: ts.server.protocol.FileSpan
text?: string
readonly linkcode: boolean
}
Expand Down Expand Up @@ -222,7 +222,7 @@ function convertLinkTags(
if (currentLink) {
currentLink.name = part.text
currentLink.target = (
part as Proto.JSDocLinkDisplayPart
part as ts.server.protocol.JSDocLinkDisplayPart
).target
}
break
Expand All @@ -242,7 +242,7 @@ function convertLinkTags(
}

export function tagsMarkdownPreview(
tags: readonly Proto.JSDocTagInfo[],
tags: readonly ts.server.protocol.JSDocTagInfo[],
filePathConverter: IFilePathToResourceConverter
): string {
return tags
Expand All @@ -251,8 +251,8 @@ export function tagsMarkdownPreview(
}

export function markdownDocumentation(
documentation: Proto.SymbolDisplayPart[] | string,
tags: Proto.JSDocTagInfo[],
documentation: ts.server.protocol.SymbolDisplayPart[] | string,
tags: ts.server.protocol.JSDocTagInfo[],
// filePathConverter: IFilePathToResourceConverter,
baseUri: vscode.Uri | undefined
): vscode.MarkdownString {
Expand All @@ -270,8 +270,8 @@ export function markdownDocumentation(

export function addMarkdownDocumentation(
out: vscode.MarkdownString,
documentation: Proto.SymbolDisplayPart[] | string | undefined,
tags: Proto.JSDocTagInfo[] | undefined,
documentation: ts.server.protocol.SymbolDisplayPart[] | string | undefined,
tags: ts.server.protocol.JSDocTagInfo[] | undefined,
converter: IFilePathToResourceConverter
): vscode.MarkdownString {
if (documentation) {
Expand Down
14 changes: 12 additions & 2 deletions packages/typescript-explorer-vscode/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode"
import type * as Proto from "typescript/lib/protocol"
import type * as ts from "typescript/lib/tsserverlibrary"

import {
CustomTypeScriptRequestId,
CustomTypeScriptRequestOfId,
Expand All @@ -9,6 +10,7 @@ import {
TypeInfo,
} from "@ts-type-explorer/api"
import {
getDurationAlert,
positionFromLineAndCharacter,
rangeFromLineAndCharacters,
rangeToTextRange,
Expand All @@ -26,14 +28,21 @@ async function getQuickInfoAtPosition(
"quickinfo-full",
toFileLocationRequestArgs(fileName, position)
)
.then((r) => (r as Proto.QuickInfoResponse).body)
.then((r) => (r as ts.server.protocol.QuickInfoResponse).body)
}

async function customTypescriptRequest<Id extends CustomTypeScriptRequestId>(
fileName: string,
position: vscode.Position,
request: CustomTypeScriptRequestOfId<Id>
): Promise<CustomTypeScriptResponseBody<Id> | undefined> {
const { register, abort } = getDurationAlert(
"TSServer needs more time to respond, please wait a few seconds",
3000
)

register()

return await vscode.commands
.executeCommand("typescript.tsserverRequest", "completionInfo", {
...toFileLocationRequestArgs(fileName, position),
Expand All @@ -44,6 +53,7 @@ async function customTypescriptRequest<Id extends CustomTypeScriptRequestId>(
triggerCharacter: request,
})
.then((val) => {
abort()
if (!val) return undefined

const response = val as CustomTypeScriptResponse
Expand Down
20 changes: 18 additions & 2 deletions packages/typescript-explorer-vscode/src/util.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as vscode from "vscode"
import type * as ts from "typescript"
import { TextRange } from "@ts-type-explorer/api"
import type * as Proto from "typescript/lib/protocol"
import { dialogueErrors, logErrors } from "./config"

export const positionToLineAndCharacter = (
Expand All @@ -19,7 +18,7 @@ export const rangeToTextRange = (range: vscode.Range): TextRange => ({
export const toFileLocationRequestArgs = (
file: string,
position: vscode.Position
): Proto.FileLocationRequestArgs => ({
): ts.server.protocol.FileLocationRequestArgs => ({
file,
line: position.line + 1,
offset: position.character + 1,
Expand Down Expand Up @@ -93,3 +92,20 @@ export function isDocumentSupported({ languageId }: vscode.TextDocument) {
languageId === "javascriptreact"
)
}

export function getDurationAlert(content: string, duration: number) {
let timer: NodeJS.Timeout | undefined
return {
register: () => {
timer = setTimeout(() => {
vscode.window.showInformationMessage(
`Typescript Explorer: ${content}`
)
}, duration)
},
abort: () => {
timer && clearTimeout(timer)
timer = undefined
},
}
}
16 changes: 15 additions & 1 deletion packages/typescript-explorer-vscode/src/view/typeTreeView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import * as vscode from "vscode"
import { showTypeParameterInfo, showBaseClassInfo } from "../config"
import { markdownDocumentation } from "../markdown"
import { StateManager } from "../state/stateManager"
import { logError, rangeFromLineAndCharacters, showError } from "../util"
import {
getDurationAlert,
logError,
rangeFromLineAndCharacters,
showError,
} from "../util"
import { getQuickInfoAtLocation, getTypeTreeAtLocation } from "../server"
import { getMetaWithTypeArguments, getMeta } from "./typeTreeViewLocalizer"

Expand Down Expand Up @@ -94,13 +99,22 @@ export class TypeTreeProvider implements vscode.TreeDataProvider<TypeTreeItem> {
}

async getChildren(element?: TypeTreeItem): Promise<TypeTreeItem[]> {
const { register, abort } = getDurationAlert(
"TSServer needs more time to get children information, please wait a few seconds",
3000
)

register()

const children = await this.getChildrenWorker(element).catch((e) => {
logError(e, "Error getting children")
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
showError(e.message ?? "Error getting children")
return []
})

abort()

this._onDidGetChildren.fire({ parent: element, children })

return children
Expand Down
2 changes: 1 addition & 1 deletion packages/typescript-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"@ts-type-explorer/api": "^0.4.0"
},
"devDependencies": {
"typescript": "^4.8.4"
"typescript": "^5.3.0"
}
}
1 change: 1 addition & 0 deletions packages/typescript-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
TypescriptContext,
} from "@ts-type-explorer/api"
import { SourceFileTypescriptContext } from "@ts-type-explorer/api"
import type * as ts from "typescript/lib/tsserverlibrary"

// TODO: add config for e.g. max depth

Expand Down
1 change: 0 additions & 1 deletion tests/lib/tsUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function createTsContext(fileName: string): SourceFileTypescriptContext {
program,
sourceFile,
typeChecker,
// @ts-expect-error - semantic type difference
ts,
}
}
Loading