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

intellisence relative to first tsconfig up from src #1360

Open
3 tasks done
shaunc opened this issue Jul 21, 2019 · 3 comments
Open
3 tasks done

intellisence relative to first tsconfig up from src #1360

shaunc opened this issue Jul 21, 2019 · 3 comments

Comments

@shaunc
Copy link

shaunc commented Jul 21, 2019

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform:
  • Vetur version:
  • VS Code version:

Mac OS, Vetur 0.21.1, vscode 1.36.1

Problem

I have a nuxt/typescript project, and can't resolve paths with "~" in vscode. According to documentation, intellisense works from workspace root. However, I am working in a monorepo, with lots of little packages. I prefer not to have workspaces for each. So the workspace root is not the right place to start from. Rather, I would like to resolve tilde from the directory of the first tsconfig.json up from source code. Is there a way to do this? (If not, this is a feature request.)

Reproducible Case

@blieque
Copy link

blieque commented Dec 6, 2019

I've run into this as well. vscode correctly identifies TypeScript projects as any directory containing a tsconfig.json (even if that isn't the workspace directory), but this doesn't carry over to Vue components.

Consider the following:

monorepo/
 │
 ├─ one-package/
 │   ├─ src/
 │   │   ├─ components/
 │   │   │   └─ Header.vue
 │   │   ├─ App.vue
 │   │   ├─ index.ts
 │   │   └─ router.ts
 │   │
 │   ├─ tsconfig.json
 │   └─ package.json
 │
 ├─ second-package/
 │   ├─ src/
 │   │   ├─ index.ts
 │   │   └─ utils.ts
 │   │
 │   ├─ tsconfig.json
 │   └─ package.json
 │
 ├─ lerna.json
 └─ vue-shim.d.ts

Both of these tsconfig.json files would have "paths": { "@/*": ["src/*"] }. If I open monorepo/ as a workspace in vscode and look at one-package/src/index.ts, I can use Go to definition while my cursor is sat in '@/router' and it'll take me to the file. This doesn't involve Vetur though.

I think the issue crops up when:

  • a Vue component is imported – import App from '@/App.vue'; or
  • a .ts file or Vue component is imported in a Vue component.

vscode still picks up the generic *.vue definition from vue-shim.d.ts, but doesn't find the real component. Go to definition just peeks at the shim file.

I get the impression Vetur is built with the assumption that workspace == TypeScript project root, but this isn't strictly true; a TypeScript project is a directory containing a tsconfig.json. This would presumably involve a fairly wide-reaching refactor to fix. For the time being, open each project in it's own workspace or use Ctrl+P to get around rather than F12.

Edit: FWIW, I think some of the other open tsconfig.json-related issues are perhaps the same underlying thing.

@clouds56
Copy link

Same here, even in workspace there's only one package. As long as there's no tsconfig.json at root of the workspace, Vetur won't work.
Workaround: create a fake tsconfig at root of workspace for Vetur. I don't think it would not work well for multiple packages in monorepo, but might mitigate some error.

{
  ...
  "paths": {
    "@/*": ["one-package/src/*", "second-package/src/*"]
  }
}

@yoyo930021
Copy link
Member

Hi everyone,

If you interested this issue,

you can go to #2377 and #2378.
View and post your ideas.

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

No branches or pull requests

5 participants