question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot find all references to shared lib's interfaces in VS Code

See original GitHub issue

Current Behavior

VS Code cannot discover references to shared entities that are defined in an nx lib. E.g. in a fresh new angular-nest nx monorepo VS Code cannot find all references to the Message interface defined in api-interfaces.ts. As a consequence, we cannot rename the entity throughout the workspace.

As far as I understood, it happens due to separate Typescript projects we have for apps and libs, and due to the fact, VS Code relies on the Typescript server while identifying references. This issue was described in this Typescript ticket and fixed within this one. It is not reproducible in WebStorm, which perhaps uses another way of reference discovery in a workspace.

That’s rather not a bug of nx per se, but the initial configuration bug/improvement.

Expected Behavior

Find all references and Rename features should work in VS Code throughout all the nx monorepo Typescript subprojects.

To have it working, every nx shared lib should have the following Typescript options enabled: E.g. in libs/api-interfaces/tsconfig.json

{
  ...
  "compilerOptions": {
    ...
    "composite": true,
    "declaration": true
  }
}

More details for the composite option is described here.

Also, we might want to reference lib projects from within application projects. However, I don’t know how beneficial it might be in nx monorepos since it’s not required for fixing the current issue. E.g. in apps/api/tsconfig.json:

{
  ..
  "references": [
      { "path": "../../libs/api-interfaces" }
  ]
}

Steps to Reproduce

  1. Run npx create-nx-workspace@latest test.
  2. Select angular-nest.
  3. Proceed further with any app name and stylesheet format.
  4. Open the workspace with VS Code.
  5. Open api-interfaces.ts (this file should be the first and the only file opened after running VS Code).
  6. Find references to the Message interface via Shift+F12 or Alt+Shift+F12.

Actual result: no reference found.

Environment

  @nrwl/angular : 9.3.0
  @nrwl/cli : 9.3.0
  @nrwl/cypress : 9.3.0
  @nrwl/eslint-plugin-nx : Not Found
  @nrwl/express : Not Found
  @nrwl/jest : 9.3.0
  @nrwl/linter : 9.3.0
  @nrwl/nest : 9.3.0
  @nrwl/next : Not Found
  @nrwl/node : 9.3.0
  @nrwl/react : Not Found
  @nrwl/schematics : Not Found
  @nrwl/tao : 9.3.0
  @nrwl/web : Not Found
  @nrwl/workspace : 9.3.0
  typescript : 3.8.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:23
  • Comments:36 (9 by maintainers)

github_iconTop GitHub Comments

15reactions
johannesschobelcommented, Sep 17, 2021

Dear @FrozenPandaz ,

i know, you nx guys may be very busy because of your conference, but this issue is a real road block for larger projects. may you distribute this issue to someone who may be able to work on the latter? Maybe the solution provided by @JakeGinnivan is suitable and can be incorporated somehow!?

All the best and thanks for your awesome work! Johannes

13reactions
javieroccommented, Mar 30, 2021

I was following the tutorial from nx docs and vscode not recognize @myorg/data shared lib, someone had this issue?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot broken references - Visual Studio - Microsoft Learn
Learn how to troubleshoot broken references that might be caused by something other than your application's inability to find the referenced ...
Read more >
How to navigate to interface's implementation in VS Code as ...
I am code with golang and Find All Reference always return one definition at the interface itself. Do I need to make any...
Read more >
Multi-root Workspaces in Visual Studio Code
You can open and work on multiple project folders in Visual Studio Code with multi-root workspaces.
Read more >
User and Workspace Settings - Visual Studio Code
Nearly every part of VS Code's editor, user interface, and functional behavior has ... When you open the Settings editor, you can search...
Read more >
C/C++ extension FAQ - Visual Studio Code
Files can be corrupted due to the fact that you either have a multi-root workspace where one folder is a child of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found