Skip to content

Commit

Permalink
Revert "[typescript-language-features] Expandable hover (#228255)"
Browse files Browse the repository at this point in the history
This reverts commit 0f9abf3.
  • Loading branch information
gabritto committed Feb 7, 2025
1 parent e887b8e commit 746caa3
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 61 deletions.
30 changes: 10 additions & 20 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 @@ -824,16 +823,16 @@
],
"enumDescriptions": [
"%typescript.locale.auto%",
"Deutsch",
"español",
"Deutsch",
"español",
"English",
"français",
"italiano",
"日本語",
"한국어",
"русский",
"中文(简体)",
"中文(繁體)"
"français",
"italiano",
"日本語",
"한국어",
"русский",
"中文(简体)",
"中文(繁體)"
],
"markdownDescription": "%typescript.locale%",
"scope": "window"
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
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export class API {
public static readonly v544 = API.fromSimpleString('5.4.4');
public static readonly v540 = API.fromSimpleString('5.4.0');
public static readonly v560 = API.fromSimpleString('5.6.0');
public static readonly v570 = API.fromSimpleString('5.7.0');

public static fromVersionString(versionString: string): API {
let version = semver.valid(versionString);
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",
]
}

0 comments on commit 746caa3

Please sign in to comment.