Skip to content
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

goToDefinition doesn't work properly #247

Open
BohdanZinkevych opened this issue Jan 5, 2024 · 12 comments
Open

goToDefinition doesn't work properly #247

BohdanZinkevych opened this issue Jan 5, 2024 · 12 comments

Comments

@BohdanZinkevych
Copy link

BohdanZinkevych commented Jan 5, 2024

In VSCode, 'Go to Definition' (Ctrl + click on a classname) doesn't work for me; it opens the GenericMarkup.module.less file, and that's it.

tscondig.json
"plugins": [ { "name": "typescript-plugin-css-modules", "options": { "classnameTransform": "camelCaseOnly", "goToDefinition": "enabled", } } ]

Steps to reproduce:

  1. Open any .tsx file that uses a CSS module.
  2. Click on a classname imported from the CSS module.
  3. Observe that it navigates to the incorrect place in the opened file.

image
image

Expected behavior:
The CSS module file should open at the correct classname's place.

OS: Windows 11
IDE: VSCode

@dzsodzso63
Copy link

I have the same problem. I upgraded typescript to 5.3.3 and typescript-plugin-css-modules to 5.0.2 and goToDefinition navigates now to the end of the file. It was working before for us
config:

{
        "name": "typescript-plugin-css-modules",
        "options": {
          "classnameTransform": "asIs",
          "customMatcher": "\\.css$",
          "dotenvOptions": {},
          "postcssOptions": {},
          "rendererOptions": {},
          "goToDefinition": true
        }
      }

we used v4 with ts4 before, without any problem

@dzsodzso63
Copy link

Adding a minor info here, before in vscode hovering with cmd key underlined the class before, now it does not happen

@BohdanZinkevych
Copy link
Author

just in case, I use the latest version of typescript-plugin-css-modules and typescript: '4.9.5'

@dzsodzso63
Copy link

Another info from the log:

Info 1145 [13:38:00.415] request:
    {
      "seq": 15,
      "type": "request",
      "command": "definitionAndBoundSpan",
      "arguments": {
        "file": "/.../Filename.tsx",
        "line": 138,
        "offset": 50
      }
    }
Perf 1146 [13:38:00.416] 15::definitionAndBoundSpan: elapsed time (in milliseconds) 0.7883
Info 1147 [13:38:00.416] response:
    {"seq":0,"type":"response","command":"definitionAndBoundSpan","request_seq":15,"success":true,"body":{"definitions":[{"file":".../Filename.css","start":{"line":312,"offset":3},"end":{"line":312,"offset":14},"contextStart":{"line":312,"offset":3},"contextEnd":{"line":312,"offset":23}}],"textSpan":{"start":{"line":138,"offset":44},"end":{"line":138,"offset":53}}}}

Which is important cos Filename.css has no more than 291 lines. It explains why goToDefinition positions to the end of the css file

@mrmckeb
Copy link
Owner

mrmckeb commented Feb 11, 2024

Hi @BohdanZinkevych, goToDefinition is a boolean value. You can see here that it defaults to false. You should be able to get it to work by setting it to true:
https://github.com/mrmckeb/typescript-plugin-css-modules?tab=readme-ov-file#options

@mrmckeb mrmckeb closed this as not planned Won't fix, can't repro, duplicate, stale Feb 11, 2024
@mrmckeb
Copy link
Owner

mrmckeb commented Feb 11, 2024

Hi @dzsodzso63, I think you have a different issue.

Can you please raise a new request with a small reproduction? That will help me investigate further.

Note that this is an experimental feature, and even when working, may not always point to the right line.

@BohdanZinkevych
Copy link
Author

BohdanZinkevych commented Feb 13, 2024

@mrmckeb still doesn't work for me with or without goToDefinition: true

@mrmckeb
Copy link
Owner

mrmckeb commented Feb 13, 2024

Hi @BohdanZinkevych, can you please supply a reproduction? This feature is experimental and won't work perfectly, but should get you close in many cases.

@BohdanZinkevych
Copy link
Author

@mrmckeb yes, it's true, it leads me to the correct file but not to the correct place(line)

@qyzzzz
Copy link
Contributor

qyzzzz commented Feb 18, 2024

Hi @BohdanZinkevych, can you please supply a reproduction? This feature is experimental and won't work perfectly, but should get you close in many cases.

Hi @BohdanZinkevych , thanks for your idea, i really love the "goToDefinition" feature. I create a reproduction of this issue, go to definition always lead me to the last line.
https://github.com/qyzzzz/typescript-plugin-css-modules-goToDefinition-reproduction

@dzsodzso63
Copy link

@mrmckeb looks like the very same issue to me

@mrmckeb mrmckeb reopened this Mar 21, 2024
@mrmckeb
Copy link
Owner

mrmckeb commented Mar 21, 2024

Hi all, I'm away at the moment, but will try to take a look at this in the next week or so.

This is an experimental feature, and I'm not sure we'll ever be able to make it work perfectly as TypeScript doesn't provide an API for this. But, we can try to make it better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants