vuejs / vetur

Vue tooling for VS Code.
https://vuejs.github.io/vetur/
MIT License
5.75k stars 594 forks source link

intellisence relative to first tsconfig up from src #1360

Open shaunc opened 5 years ago

shaunc commented 5 years ago

Info

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 commented 4 years ago

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:

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 commented 4 years ago

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 commented 4 years ago

Hi everyone, 
If you interested this issue,
 you can go to https://github.com/vuejs/vetur/pull/2377 and https://github.com/vuejs/vetur/pull/2378. View and post your ideas.