-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Add full type hover popup to VS Code commands #35601
Comments
@Arlen22 This is what microsoft/vscode#64566 is about: being able to expand the error to see more detail.Even in JS there are types that are too large to display (or infinite), so it is not possible to just always expand the Can you provide sample code that shows when the |
An infinite recursion should simply be marked as Normally the types I work with are not too large to display. If they are I can usually break them apart into smaller chunks in one way or another, either by making minor edits to the Javascript or by handwriting a Record, or stuff like that. It's just that the |
Can you provide some specific code examples? |
Array<{
"server_id": number; "server_uri": string; "itemType": string; "key": string;
"title": string; "summary": string; "thumbnail": string; "videocover": string;
"url": { "H264": string[]; "location": string; };
} | { "itemType": string; ... 7 more ...; "url"?: undefined; }>.shift(): {
"server_id": number;
"server_uri": string;
"itemType": string;
"key": string;
"title": string;
"summary": string;
"thumbnail": string;
"videocover": string;
"url": {
"H264": string[];
"location": string;
};
} | {
"itemType": string;
... 7 more ...;
"url"?: undefined;
} |
ceTouchableFeedback<{
onPress: () => void;
object_id: number;
name: "header" | "italic" | "bold" | "underline" | "repeat" | "link" | "search" | "image"
| "key" | "code" | "map" | "table" | "th" | "circle" | ... 771 more ... | "snowflake-o";
style: {
...;
};
}>(options: TouchableFeedbackOptions<...>, ...children: any[]): any (+1 overload) The name field is obvious and useless and I would just remove the contents or change them to a named reference, but the generic inside options: TouchableFeedbackOptions gives me no information, and I critically need to know what the exact properties are being brought in. |
Moving upstream to get more feedback from the TS Team |
This is same request I had in the diagnostics issue. Use case I had is that I often found myself seeing a type in the hover tip, and copying it out. It never worked after the changes. I actually don't understand why the hover tip needs to be abbreviated with three dots. It has a scrollbar. It's perfect abbreviation itself, you can expand it by scrolling! Even if the three dots were expandable by clicking, it would be worse UI in terms of usability, scrolling is easier way to "expand" the view. P.S. Recursive types are an outlier, I don't mind having dots for them (since it can be infinite). I think in general VSCode should try to show as much as possible of the type, and user can scroll if they wish to see more of the type. |
Can we somehow make this a VS Code setting? I guess this is in Typescript now, so whatever the equivalent would be here. |
And now this evening I am diagnosing type problems and it is not showing me a second type that I know is different than the first one that it is showing me. It’s a union on the values of an object and it is only expanding the first type in the union. |
Just as a heads up, there's a |
Ah, apparently it doesn't work always. Btw, this is a duplicate of #26238 |
I desperately need this feature. Infer types from usage is giving me three dots when I use it if the original type has three dots. I also can't debug type problems because the three dots is not dependable and never guarantees that any particular type is actually repeated. Since this is a TypeScript feature I can just build a custom TypeScript package, but I don't know where I would do that. Any ideas? |
This comment has been minimized.
This comment has been minimized.
What about a setting that just allows you to set a max tooltip length, and only apply ellipsis if tooltip length exceeds maximum? This would be a little bit like |
"noErrorTruncation": true Did not work correctly for me even though it's been proposed several times as a solution in other questions like this one. A quick fix that actually does work would be... some kind of a more offensive solution ;p This will get you what you are waiting for. A nice 800 chars long max type definition on hover. You can of course custom this value as much as you want. This might not be politically correct for you will need to do it again after every vs code update, but it works just fine and you'll finally get your full type on hover. in vscode: ctrl + shift + P -> type "restart ts server" -> press enter. wait a couple seconds, it's fairly quick. |
As @LoveriusB mentioned above, we can change the value of |
look at microsoft/TypeScript#35601 (comment) to get typescript to stop truncating
Confirmed that this works really great #35601 (comment) Combined with patch-package and it becomes automatic. Thanks for the awesome workaround until we get this in core. |
@RyanCavanaugh Can this be added as a config option of some kind so it can be changed in VS Code settings? I don't know the internals of the language server, but my end goal would be for it to be a setting in the Typescript section of VS code, however that works. Also, it is very simple to avoid recursion. I don't know what the preferred way of doing it is but you could at least just substitute it with the never type or a keyword like type reference = { my: { recursive: { property: reference } } };
type root = { path: { to: { first: { reference: reference } } } }; or something of that nature. I'm not sure that's required, but it would also work. |
Also going back to my OP, isn't there a way that Typescript files could make use of intellisense for Javascript files the same way other Javascript files can? Even just setting the import to |
Any updates? |
+1 |
+1 :)) |
Found myself going back and making the edit every so often so I made a bash snippet . For mac users just copy and paste into your terminal. Change the value to whatever you like. :'
Mac OS | Visual Studio Code
Replace 1000 with any number
'
value='defaultMaximumTruncationLength = 1000'
sudo sed -i '' "s/defaultMaximumTruncationLength = 160/$value/" "/Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js" For those of you using Visual Studio Code Insiders :'
Mac OS | Visual Studio Code Insiders
Replace 1000 with any number
'
value='defaultMaximumTruncationLength = 1000'
sudo sed -i '' "s/defaultMaximumTruncationLength = 160/$value/" "/Applications/Visual Studio Code - Insiders.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js" |
+1 on this being a really useful feature. Right now I'm using the "Typescript Explorer" vscode extension but would hope this to be built in. |
For those plusoners I just want to remind that you by doing that also sending emails to at least 25 people... |
The ts.defaultMaximumTruncationLength hack works great! Steps to remove abbreviations from type hints:
Hope it helps anyone looking for this. |
This comment has been minimized.
This comment has been minimized.
For those who haven't seen this plugin:
https://marketplace.visualstudio.com/items?itemName=mxsdev.typescript-explorer |
This comment has been minimized.
This comment has been minimized.
Thank you for sharing. Nextlevel useful ✍️ |
Long term solution by @extremegf in vscode
PS.
|
I'm useing typescript v5, I found that on |
+1 |
EDIT: I fixed it patching diff --git a/lib/typescript.js b/lib/typescript.js
index 90f3266ee69f247b20bd892b1a975220489f094f..87f11795f1f298928cb9d9f26e13de51817a7656 100644
--- a/lib/typescript.js
+++ b/lib/typescript.js
@@ -16056,7 +16056,7 @@ function isInternalDeclaration(node, sourceFile) {
// src/compiler/utilities.ts
var resolvingEmptyArray = [];
var externalHelpersModuleNameText = "tslib";
-var defaultMaximumTruncationLength = 160;
+var defaultMaximumTruncationLength = 1e6;
var noTruncationMaximumTruncationLength = 1e6;
function getDeclarationOfKind(symbol, kind) {
const declarations = symbol.declarations; Old post:It used to work in TS 5.4, but now it doesn't (I tried every minor version back to 5.0.4). Even in 5.6, with the following patch, complex types are truncated: diff --git a/lib/tsc.js b/lib/tsc.js
index 37e7f28602e6337b6216810d6a40e6701a99f0a5..6ac55bc88de4c3415cac5e218b2b4dad0a3adfc1 100644
--- a/lib/tsc.js
+++ b/lib/tsc.js
@@ -12463,7 +12463,7 @@ function isInternalDeclaration(node, sourceFile) {
// src/compiler/utilities.ts
var resolvingEmptyArray = [];
var externalHelpersModuleNameText = "tslib";
-var defaultMaximumTruncationLength = 160;
+var defaultMaximumTruncationLength = 1e5;
var noTruncationMaximumTruncationLength = 1e6;
function getDeclarationOfKind(symbol, kind) {
const declarations = symbol.declarations; Results in:
I suspect this is related to VS Code updates, even though I'm using the TypeScript workspace version. |
Thanks, I was halfway making my extension for vs code, you saved me a lot of time. |
I would still happily use your extension :) |
Back to update my workaround : If you have bun as your package manager you can use the Step 1: Run Bun Patchbun patch typescript@5.8.0-dev.20241113 Step 2: Edit The Package./patches/typescript@5.8.0-dev.20241113.patch diff --git a/node_modules/typescript/.DS_Store b/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..f9f60d0a8f94f19a9f55d4bcbfeaf7866207ada5
Binary files /dev/null and b/.DS_Store differ
diff --git a/lib/typescript.js b/lib/typescript.js
index 4ed5056a2ff6648b59de5d2a871dab64e8c97a66..ccda9e88105bac6e5003210d98bb4c6cef867aa6 100644
--- a/lib/typescript.js
+++ b/lib/typescript.js
@@ -16116,7 +16116,7 @@ function isInternalDeclaration(node, sourceFile) {
// src/compiler/utilities.ts
var resolvingEmptyArray = [];
var externalHelpersModuleNameText = "tslib";
-var defaultMaximumTruncationLength = 160;
+var defaultMaximumTruncationLength = 30000;
var noTruncationMaximumTruncationLength = 1e6;
function getDeclarationOfKind(symbol, kind) {
const declarations = symbol.declarations;
Step 3: Commit The Patch bun patch --commit 'node_modules/typescript' Troubleshooting Prees Command Shift P Search " Typescript Select " Lastly restart the language server |
Several issues have been opened for this problem, but they have been closed as a duplicate of an issue which barely mentions the problem, let alone addresses it: microsoft/vscode#64566
The closed issues are:
The problem is simple. The three dots means you can't copy and paste definitions like you used to be able to. This is an absolutely essential feature because TypeScript isn't even close to being used everywhere, and the intellisense of Javascript files inside TypeScript files is way worse than inside Javascript files. This basically means the easiest way to create a d.ts file is to copy the type definition in the hover inside Javascript and then paste it into a d.ts file so TypeScript files can use it. It also helps me debug overloads and unions when things are going awry.
Even just a command that would popup the hover with the full definition instead of the abbreviated definition would be incredibly useful. Currently the shortcut is
Ctrl+k, Ctrl+i
for the abbreviated definition, so I take it there is a command behind it that can be typed into the command list (ctrl+shift+p
). So even just adding the command for people to manually add a shortcut for would be really useful.I can work around it, but I spend hours more time per week because of it.
The text was updated successfully, but these errors were encountered: