zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
49.65k stars 3.04k forks source link

Unable to recognize the types and methods defined in global.d.ts #4393

Open ZhengXiaowei opened 1 year ago

ZhengXiaowei commented 1 year ago

Check for existing issues

Describe the feature

Unable to recognize the types and methods defined in global.d.ts.

I have a global.d.ts file in the src directory, but when writing code in *.ts files, I cannot access the types and methods defined in global.d.ts.

e.g:

image image

If applicable, add mockups / screenshots to help present your vision of the feature

No response

JosephTLyons commented 1 year ago

Hi @ZhengXiaowei, this may be a naive thing to suggest (I'm not really in the world of JavaScript / TypeScript), but I added a tsconfig.json file and told it to look for everything *.ts-related, and it was able to find the global definitions.

SCR-20231103-jrhe
ZhengXiaowei commented 1 year ago

Hi @ZhengXiaowei, this may be a naive thing to suggest (I'm not really in the world of JavaScript / TypeScript), but I added a tsconfig.json file and told it to look for everything *.ts-related, and it was able to find the global definitions.

SCR-20231103-jrhe

I configured it to tsconfig.json but it's still not working.😭

JosephTLyons commented 1 year ago

I dont think you should have to, but did you try restarting the language server (command palette > editor: restart language server) to see if it picked up the changes? Can you include an image of the project tree?

ZhengXiaowei commented 1 year ago

I retry it today, and it's work for the typescript project, but it's doesn't work for the vue-typescript project. it's my project tree:

image
ZhengXiaowei commented 12 months ago

Hi @JosephTLyons, can this issue be fixed?

shellscape commented 9 months ago

This is related to, and extends to declaring modules for custom file type recognition. the TS LS implementation doesn't seem to pick up on this. Consider a declarations.ts file:

declare module '*.graphql' {
  const GraphQL: string;

  // @ts-ignore
  export = GraphQL;
}

declare module '*.yml' {
  const Yaml: string;

  // @ts-ignore
  export = Yaml;
}

This provides instruction to TS that .graphql files and .yml files can be resolved when imported via e.g. import typeDefs from './mutations.graphql';

I've not been able to get Zed to recognize these imports as resolvable, and TS will always present an error that they cannot be resolved.

medz commented 3 months ago

I dont think you should have to, but did you try restarting the language server (command palette > editor: restart language server) to see if it picked up the changes? Can you include an image of the project tree?

Your method works! But I have a question, why does the language server crash after a while?

I am using TypeScript + Vue now. Whenever I immerse myself in editing Vue files, the language server crashes after a while.

Before you gave this solution, I usually forced Zed to close by CMD+Q and reopen it to solve it.

Although your method works, it is too inefficient. Our users cannot always restart the language server frequently. I think Zed did something to cause the TypeScript and Vue language servers to crash and exit. Can we do it like VS Code, automatically restart after detecting the language server crash instead of telling the user nothing.