Merge pull request #240011 from gabritto/reverthover

Revert "[typescript-language-features] Expandable hover (#228255)"
This commit is contained in:
Matt Bierner
2025-02-26 14:39:54 -08:00
committed by GitHub
4 changed files with 10 additions and 52 deletions

View File

@@ -11,8 +11,7 @@
"workspaceTrust",
"multiDocumentHighlightProvider",
"codeActionAI",
"codeActionRanges",
"editorHoverVerbosityLevel"
"codeActionRanges"
],
"capabilities": {
"virtualWorkspaces": {
@@ -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"
]
}
}
},

View File

@@ -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",

View File

@@ -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,
@@ -25,24 +24,17 @@ 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);
});
@@ -50,24 +42,9 @@ class TypeScriptHoverProvider implements vscode.HoverProvider {
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(
@@ -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(

View File

@@ -14,7 +14,6 @@
"../../src/vscode-dts/vscode.proposed.codeActionAI.d.ts",
"../../src/vscode-dts/vscode.proposed.codeActionRanges.d.ts",
"../../src/vscode-dts/vscode.proposed.multiDocumentHighlightProvider.d.ts",
"../../src/vscode-dts/vscode.proposed.workspaceTrust.d.ts",
"../../src/vscode-dts/vscode.proposed.editorHoverVerbosityLevel.d.ts",
"../../src/vscode-dts/vscode.proposed.workspaceTrust.d.ts"
]
}