tss-react icon indicating copy to clipboard operation
tss-react copied to clipboard

Can't navigate to class definition

Open ajnozari opened this issue 3 years ago • 21 comments

I have a weird bug where my classes are auto-filled. My IDE does not seem to determine where the class is initially defined.

This occurs only when returning a callback, not when an object is passed to makeStyles(). I am using this with MUI and upgraded from v4->v5, so I may have just missed something.

Please let me know if you need any further information and I will do my best to get it to you.

ajnozari avatar Sep 28 '22 01:09 ajnozari

Hi @ajnozari,

Can you send me a screenshot?

garronej avatar Sep 28 '22 01:09 garronej

Screen Shot 2022-09-28 at 5 56 26 PM

That's a screen cap that shows my makestyles and an element using a style, I can include a screencap for the whole page if you want.

ajnozari avatar Sep 28 '22 21:09 ajnozari

I don't see the relevent things in your screen.
The important parts are cropped.

What I can already tell you is:

  • A hook should always start with use I'm surprised you don't get warnings about it.
  • You don't need to annotate Theme
- const styles = makeStyles()((theme: Theme)=> ({
+ const useStyles = makeStyles()(theme => ({

garronej avatar Sep 28 '22 22:09 garronej

Roger I'll try that and see what happens

ajnozari avatar Sep 28 '22 22:09 ajnozari

Screen Shot 2022-09-28 at 6 55 52 PM

Here's a smaller screen than the last one easier to see everything

ajnozari avatar Sep 28 '22 22:09 ajnozari

If I type the exacte same code in VSCode it works:

image

Looks like you are using Inteliji and it's missconfigured....

garronej avatar Sep 28 '22 23:09 garronej

That's the weird thing, if I don't pass a theme (when not needed), it works fine, and it's able to find the declaration.

It only shows like this when I use an arrow function to pass the theme. I'm also able to work around it by passing the theme from the component via the useTheme hook, and referencing that in the object. See below:

Screen Shot 2022-09-29 at 9 16 19 PM

I also tried resetting my IDE to default settings but saw no change. Perhaps it's something weird with Intellij? But you can see in the picture the root in classes.root is now purple, which means it's picked up properly...

ajnozari avatar Sep 30 '22 01:09 ajnozari

Have you tried opening your project with VSCode?
Upgrading TypeScript?

garronej avatar Sep 30 '22 01:09 garronej

I don’t use VSCode so that won’t help me.

mill try updating typescript and see if that helps.

ajnozari avatar Sep 30 '22 09:09 ajnozari

I don’t use VSCode so that won’t help me.

That will help you make sure that the problem is related to Intelliji....

garronej avatar Sep 30 '22 10:09 garronej

I have the same issue Mainly I use WebStorm, but I also checked it in VS Code, and there is the same issue Also, you can check it at your documentation: https://stackblitz.com/edit/tss-react-wv2set?file=Hello.tsx,index.tsx,tss.ts Try to open Hello.tsx and find definition of label className

So IDE shows me the className which I define at makeStyles image

But then if I click on the class definition it could not find the right path. image I've upgraded typescript to 4.8.4

I remember I've played with examples of tss v3 via WebStorm and it works fine, but in my project, it did not :(

osa911 avatar Oct 03 '22 19:10 osa911

@osa911 Thanks for reporting but I think the problem @ajnozari is facing is different.
In his case, when he types classes. he dosen't get any suggestion.

Now about the fact that it isn't possible to navigate to the de declaration... this dosen't suprise me, it would be neat if it worked but, to my knoelage, it never did.

If you can provide evidence of navigation working with older version of TSS I can investigate.

garronej avatar Oct 03 '22 20:10 garronej

@garronej I have a fork of your project and there it works))) https://github.com/osa911/tss-react/blob/main/src/test/apps/ssr/pages/index.tsx And also it was working on my project as well but I did not find how it was :smiley:

https://user-images.githubusercontent.com/14163474/193691414-db26ab27-035e-43bf-bf1b-d5170f67bc38.mov

osa911 avatar Oct 03 '22 21:10 osa911

very intresting thank you, I'll see if I can make it work again
it's true that it's very conveignent

garronej avatar Oct 03 '22 22:10 garronej

I've played a little bit locally with this and it looks like a bug, not a feature))

osa911 avatar Oct 03 '22 22:10 osa911

I've played a little bit locally with this and it looks like a bug, not a feature))

lol, I don't understand, what do you mean?

garronej avatar Oct 03 '22 22:10 garronej

If I replace import makeStyles

import { makeStyles } from "../shared/makeStyles";

to makeStyles definition

import { createMakeAndWithStyles } from "tss-react";
import { useTheme } from "@mui/material/styles";

export const { makeStyles, useStyles, withStyles } = createMakeAndWithStyles({ useTheme });

it will break goto definition...

https://user-images.githubusercontent.com/14163474/193700627-4a3e8848-bcee-47c4-b80d-5015c4a8d2e4.mov

osa911 avatar Oct 03 '22 23:10 osa911

@osa911 Thanks for reporting but I think the problem @ajnozari is facing is different. In his case, when he types classes. he dosen't get any suggestion.

Now about the fact that it isn't possible to navigate to the de declaration... this dosen't suprise me, it would be neat if it worked but, to my knoelage, it never did.

If you can provide evidence of navigation working with older version of TSS I can investigate.

possible

So I'm sorry if I confused you, I do get suggestions, it that when I hover over the classes.className my IDE doesn't know where it's being referenced from, weirdly it DOES offer the classes as a suggestion.

Something weird must be going on with PHPStorm for it to not know where the object is defined, but still be able to give it in autocomplete

ajnozari avatar Oct 09 '22 04:10 ajnozari

I have the same issue Mainly I use WebStorm, but I also checked it in VS Code, and there is the same issue Also, you can check it at your documentation: https://stackblitz.com/edit/tss-react-wv2set?file=Hello.tsx,index.tsx,tss.ts Try to open Hello.tsx and find definition of label className

So IDE shows me the className which I define at makeStyles image

But then if I click on the class definition it could not find the right path. image I've upgraded typescript to 4.8.4

I remember I've played with examples of tss v3 via WebStorm and it works fine, but in my project, it did not :(

This is the exact issue I'm facing, I just explained it very poorly

ajnozari avatar Oct 09 '22 04:10 ajnozari

This is the exact issue I'm facing, I just explained it very poorly

ok thank you for clearing this out, I didn't read what you said carefully enough.

garronej avatar Oct 09 '22 04:10 garronej

Now that I know it is possible to navigate

Hi @osa911, @ajnozari
I tried all I could to reproduce a scenario where this was working but I failed. 😞

The steps I took

git clone https://github.com/garronej/tss-react
cd tss-react
# Back to commit n°500
git checkout 11b4c5884ead610f9f31249b21518647ea69008d
yarn 
yarn build
yarn start_ssr
# > Select TypeScript version > Use Workspace version 4.6.4

Then I navigate to src/test/apps/ssr/pages/index.tsx and after right click -> Go to definition:

image

I am very willing to work on this, if this is actually possible with open source tooling.

I'm afraid that it was only working in the first place for both of you thanks to some Inteliji specific heuristic.
I'm afraid the TypeScript compiler itself isn't capable of producing the line number where the classes are declared.

garronej avatar Oct 11 '22 02:10 garronej

Something strange I noticed is that if I pass an object to makeStyles instead of a callback it works fine and I am able to navigate to the definition of the class just fine.

So I agree something weird is happening with TS.

ajnozari avatar Oct 22 '22 21:10 ajnozari

I'm now convinced of that:

I'm afraid that it was only working in the first place for both of you thanks to some Inteliji specific heuristic. I'm afraid the TypeScript compiler itself isn't capable of producing the line number where the classes are declared.

Closing since it's an intellij feature that I have no contrôle about.

Thanks for reporting anyway.

garronej avatar Oct 22 '22 21:10 garronej

Has anyone found a way to make the navigation work? A click on "card" here still moves me to a wrong area. it worked fine with mui v4 makeStyles.

I know that it is related to the type of "classes". Since "classes" has a type like this: const classes: Record<"classA" | "classB" | "classC" | "classD", string>

the relation to the definition in "tssStyles.create" is lost.

But i have no idea how i could update the type.

grafik grafik

MasterRedStorm avatar Jun 06 '24 10:06 MasterRedStorm