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

Revert "[typescript-language-features] Expandable hover (#228255)" #240011

Open
wants to merge 4 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
12 changes: 1 addition & 11 deletions extensions/typescript-language-features/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"workspaceTrust",
"multiDocumentHighlightProvider",
"codeActionAI",
"codeActionRanges",
"editorHoverVerbosityLevel"
"codeActionRanges"
],
"capabilities": {
"virtualWorkspaces": {
Expand Down Expand Up @@ -1515,15 +1514,6 @@
"type": "boolean",
"default": true,
"markdownDescription": "%configuration.updateImportsOnPaste%"
},
"typescript.experimental.expandableHover": {
"type": "boolean",
"default": false,
"description": "%configuration.expandableHover%",
"scope": "window",
"tags": [
"experimental"
]
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions extensions/typescript-language-features/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,7 @@
"configuration.tsserver.web.projectWideIntellisense.suppressSemanticErrors": "Suppresses semantic errors on web even when project wide IntelliSense is enabled. This is always on when project wide IntelliSense is not enabled or available. See `#typescript.tsserver.web.projectWideIntellisense.enabled#`",
"configuration.tsserver.web.typeAcquisition.enabled": "Enable/disable package acquisition on the web. This enables IntelliSense for imported packages. Requires `#typescript.tsserver.web.projectWideIntellisense.enabled#`. Currently not supported for Safari.",
"configuration.tsserver.nodePath": "Run TS Server on a custom Node installation. This can be a path to a Node executable, or 'node' if you want VS Code to detect a Node installation.",
"configuration.updateImportsOnPaste": "Enable updating imports when pasting code. Requires TypeScript 5.7+.\n\nBy default this shows a option to update imports after pasting. You can use the `#editor.pasteAs.preferences#` setting to update imports automatically when pasting: `\"editor.pasteAs.preferences\": [ \"text.updateImports.jsts\" ]`.",
"configuration.expandableHover": "Enable expanding/contracting the hover to reveal more/less information from the TS server.",
"configuration.updateImportsOnPaste": "Automatically update imports when pasting code. Requires TypeScript 5.6+.",
"walkthroughs.nodejsWelcome.title": "Get started with JavaScript and Node.js",
"walkthroughs.nodejsWelcome.description": "Make the most of Visual Studio Code's first-class JavaScript experience.",
"walkthroughs.nodejsWelcome.downloadNode.forMacOrWindows.title": "Install Node.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ import { DocumentSelector } from '../configuration/documentSelector';
import { documentationToMarkdown } from './util/textRendering';
import * as typeConverters from '../typeConverters';
import FileConfigurationManager from './fileConfigurationManager';
import { API } from '../tsServer/api';



class TypeScriptHoverProvider implements vscode.HoverProvider {
private lastHoverAndLevel: [vscode.Hover, number] | undefined;

public constructor(
private readonly client: ITypeScriptServiceClient,
Expand All @@ -25,49 +24,27 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
public async provideHover(
document: vscode.TextDocument,
position: vscode.Position,
token: vscode.CancellationToken,
context?: vscode.HoverContext,
): Promise<vscode.VerboseHover | undefined> {
token: vscode.CancellationToken
): Promise<vscode.Hover | undefined> {
const filepath = this.client.toOpenTsFilePath(document);
if (!filepath) {
return undefined;
}

const enableExpandableHover = vscode.workspace.getConfiguration('typescript').get('experimental.expandableHover');
let verbosityLevel: number | undefined;
if (enableExpandableHover && this.client.apiVersion.gte(API.v570)) {
verbosityLevel = Math.max(0, this.getPreviousLevel(context?.previousHover) + (context?.verbosityDelta ?? 0));
}
const args = { ...typeConverters.Position.toFileLocationRequestArgs(filepath, position), verbosityLevel };

const response = await this.client.interruptGetErr(async () => {
await this.fileConfigurationManager.ensureConfigurationForDocument(document, token);

const args = typeConverters.Position.toFileLocationRequestArgs(filepath, position);
return this.client.execute('quickinfo', args, token);
});

if (response.type !== 'response' || !response.body) {
return undefined;
}

const contents = this.getContents(document.uri, response.body, response._serverType);
const range = typeConverters.Range.fromTextSpan(response.body);
const hover = verbosityLevel !== undefined ?
new vscode.VerboseHover(
contents,
range,
// @ts-expect-error
/*canIncreaseVerbosity*/ response.body.canIncreaseVerbosityLevel,
/*canDecreaseVerbosity*/ verbosityLevel !== 0
) : new vscode.Hover(
contents,
range
);

if (verbosityLevel !== undefined) {
this.lastHoverAndLevel = [hover, verbosityLevel];
}
return hover;
return new vscode.Hover(
this.getContents(document.uri, response.body, response._serverType),
typeConverters.Range.fromTextSpan(response.body));
}

private getContents(
Expand Down Expand Up @@ -95,13 +72,6 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
parts.push(md);
return parts;
}

private getPreviousLevel(previousHover: vscode.Hover | undefined): number {
if (previousHover && this.lastHoverAndLevel && this.lastHoverAndLevel[0] === previousHover) {
return this.lastHoverAndLevel[1];
}
return 0;
}
}

export function register(
Expand Down
1 change: 0 additions & 1 deletion extensions/typescript-language-features/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
"../../src/vscode-dts/vscode.proposed.multiDocumentHighlightProvider.d.ts",
"../../src/vscode-dts/vscode.proposed.workspaceTrust.d.ts",
"../../src/vscode-dts/vscode.proposed.documentPaste.d.ts",
"../../src/vscode-dts/vscode.proposed.editorHoverVerbosityLevel.d.ts",
]
}
Loading