mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 01:33:15 -05:00
Improve quickinfo/signature/completions baselines (#52308)
This commit is contained in:
committed by
GitHub
parent
6622308206
commit
abd6cb446f
@@ -1972,18 +1972,53 @@ export class TestState {
|
||||
const baselineFile = this.getBaselineFileNameForContainingTestFile();
|
||||
const result = ts.arrayFrom(this.testData.markerPositions.entries(), ([name, marker]) => ({
|
||||
marker: { ...marker, name },
|
||||
quickInfo: this.languageService.getQuickInfoAtPosition(marker.fileName, marker.position)
|
||||
item: this.languageService.getQuickInfoAtPosition(marker.fileName, marker.position)
|
||||
}));
|
||||
Harness.Baseline.runBaseline(baselineFile, stringify(result));
|
||||
const annotations = this.annotateContentWithTooltips(
|
||||
result,
|
||||
"quickinfo",
|
||||
item => item.textSpan,
|
||||
({ displayParts, documentation, tags }) => [
|
||||
...(displayParts ? displayParts.map(p => p.text).join("").split("\n") : []),
|
||||
...(documentation?.length ? documentation.map(p => p.text).join("").split("\n") : []),
|
||||
...(tags?.length ? tags.map(p => `@${p.name} ${p.text?.map(dp => dp.text).join("") ?? ""}`).join("\n").split("\n") : [])
|
||||
]);
|
||||
Harness.Baseline.runBaseline(baselineFile, annotations + "\n\n" + stringify(result));
|
||||
}
|
||||
|
||||
public baselineSignatureHelp() {
|
||||
const baselineFile = this.getBaselineFileNameForContainingTestFile();
|
||||
const result = ts.arrayFrom(this.testData.markerPositions.entries(), ([name, marker]) => ({
|
||||
marker: { ...marker, name },
|
||||
signatureHelp: this.languageService.getSignatureHelpItems(marker.fileName, marker.position, /*options*/ undefined)
|
||||
item: this.languageService.getSignatureHelpItems(marker.fileName, marker.position, /*options*/ undefined)
|
||||
}));
|
||||
Harness.Baseline.runBaseline(baselineFile, stringify(result));
|
||||
const annotations = this.annotateContentWithTooltips(
|
||||
result,
|
||||
"signature help",
|
||||
() => undefined, // use default: marker.position
|
||||
(item, previous) => {
|
||||
const { documentation, tags, prefixDisplayParts, suffixDisplayParts, separatorDisplayParts, parameters } = item.items[item.selectedItemIndex];
|
||||
const tooltip = [];
|
||||
let signature = "";
|
||||
if (prefixDisplayParts.length) signature += prefixDisplayParts.map(p => p.text).join("");
|
||||
const separator = separatorDisplayParts.map(p => p.text).join("");
|
||||
signature += parameters.map((p, i) => {
|
||||
const text = p.displayParts.map(dp => dp.text).join("");
|
||||
return i === item.argumentIndex ? "**" + text + "**" : text;
|
||||
}).join(separator);
|
||||
if (suffixDisplayParts.length) signature += suffixDisplayParts.map(p => p.text).join("");
|
||||
tooltip.push(signature);
|
||||
// only display signature documentation on the last argument when multiple arguments are marked
|
||||
if (previous?.applicableSpan.start !== item.applicableSpan.start) {
|
||||
if (documentation?.length) tooltip.push(...documentation.map(p => p.text).join("").split("\n"));
|
||||
if (tags?.length) {
|
||||
tooltip.push(...tags.map(p => `@${p.name} ${p.text?.map(dp => dp.text).join("") ?? ""}`).join("\n").split("\n"));
|
||||
}
|
||||
}
|
||||
return tooltip;
|
||||
}
|
||||
);
|
||||
Harness.Baseline.runBaseline(baselineFile, annotations + "\n\n" + stringify(result));
|
||||
}
|
||||
|
||||
public baselineCompletions(preferences?: ts.UserPreferences) {
|
||||
@@ -1993,7 +2028,7 @@ export class TestState {
|
||||
const completions = this.getCompletionListAtCaret(preferences);
|
||||
return {
|
||||
marker: { ...marker, name },
|
||||
completionList: {
|
||||
item: {
|
||||
...completions,
|
||||
entries: completions?.entries.map(entry => ({
|
||||
...entry,
|
||||
@@ -2002,7 +2037,60 @@ export class TestState {
|
||||
}
|
||||
};
|
||||
});
|
||||
Harness.Baseline.runBaseline(baselineFile, stringify(result));
|
||||
const annotations = this.annotateContentWithTooltips(
|
||||
result,
|
||||
"completions",
|
||||
item => item.optionalReplacementSpan,
|
||||
item => item.entries?.flatMap(
|
||||
entry => entry.displayParts
|
||||
? entry.displayParts.map(p => p.text).join("").split("\n")
|
||||
: [`(${entry.kindModifiers}${entry.kind}) ${entry.name}`])
|
||||
);
|
||||
Harness.Baseline.runBaseline(baselineFile, annotations + "\n\n" + stringify(result));
|
||||
}
|
||||
|
||||
private annotateContentWithTooltips<T extends ts.QuickInfo | ts.SignatureHelpItems | {
|
||||
optionalReplacementSpan?: ts.TextSpan,
|
||||
entries?: {
|
||||
name: string,
|
||||
kind: string,
|
||||
kindModifiers?: string,
|
||||
displayParts?: unknown,
|
||||
}[]
|
||||
}>(
|
||||
items: ({
|
||||
marker: Marker & { name: string },
|
||||
item: T | undefined
|
||||
})[],
|
||||
opName: "completions" | "quickinfo" | "signature help",
|
||||
getSpan: (t: T) => ts.TextSpan | undefined,
|
||||
getToolTipContents: (t: T, prev: T | undefined) => string[] | undefined): string {
|
||||
const bar = "-".repeat(70);
|
||||
const sorted = items.slice();
|
||||
// sort by file, then *backwards* by position in the file so I can insert multiple times on a line without counting
|
||||
sorted.sort((q1, q2) =>
|
||||
q1.marker.fileName === q1.marker.fileName
|
||||
? (q1.marker.position > q2.marker.position ? -1 : 1)
|
||||
: (q1.marker.fileName > q1.marker.fileName ? 1 : -1));
|
||||
const files: Map<string, string[]> = new Map();
|
||||
let previous: T | undefined;
|
||||
for (const { marker, item } of sorted) {
|
||||
const span = (item ? getSpan(item) : undefined) ?? { start: marker.position, length: 1 };
|
||||
const startLc = this.languageServiceAdapterHost.positionToLineAndCharacter(marker.fileName, span.start);
|
||||
const underline = " ".repeat(startLc.character) + "^".repeat(span.length);
|
||||
let tooltip = [
|
||||
bar,
|
||||
...(item ? getToolTipContents(item, previous) : undefined) ?? [`No ${opName} at /*${marker.name}*/.`],
|
||||
bar,
|
||||
];
|
||||
tooltip = tooltip.map(l => "| " + l);
|
||||
const lines = files.get(marker.fileName) ?? this.getFileContent(marker.fileName).split(/\r?\n/);
|
||||
lines.splice(startLc.line + 1, 0, underline, ...tooltip);
|
||||
files.set(marker.fileName, lines);
|
||||
previous = item;
|
||||
}
|
||||
return Array.from(files.entries(), ([fileName, lines]) => `=== ${fileName} ===\n` + lines.map(l => "// " + l).join("\n"))
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
public baselineSmartSelection() {
|
||||
|
||||
Reference in New Issue
Block a user