Does IntelliJ's TypeScript service handle custom module resolution?

TypeScript's language service API supports the ability for custom module-resolution logic. I've been able to successfully implement this logic in the compiler using the compiler API, and so I know that it works. However, the same logic implemented via the language service API doesn't seem to work; modules that resolve when compiling still show up as "not found" in the IDE ("Error: TS2307: Cannot find module '...'").

The code I'm implementing is similar to https://github.com/HerringtonDarkholme/ts-css-plugin/blob/master/index.ts, but a bit simpler -- I only implement the resolveModuleNames logic and do nothing as far as adding source files. 

I set the TSS_LOG environment property and I am able to see the plugin being loaded in the log file. However, I do not see any log messages from the resolveModuleNames method.

Is this supported at all? Does the IDE ever call this method, or does it only use tsconfig.js to resolve modules?

0
3 comments

how are you loading your custom plugin into the language service?

0
Avatar
Permanently deleted user

As generally documented -- I basically have a tsconfig.json file with the plugin inside the "plugins" property under "compilerOptions". I did notice that there is a different resolveModuleNames method being called that is directly on the ts object; I basically instrumented all the functions I could find and wrote to a log file to figure this out. I was able to get the modules to resolve and the errors to stop showing up.

But I do have another question -- does IntelliJ use the the TypeScript Language Service to also navigate to the location of modules? For example, if I Ctrl+Click on the module name, it jumps to the pertinent file. However, my module paths use a delimeter other than "/" (I can't get into too much details as to why we have a different path separator because it's part of an internal platform). So for example, say we we have the statement:

import * as myModule from "this:is:my:module";

In this case, IntelliJ cannot jump to the file directly (which is basically at <source-root>/this/is/my/module.ts).  I was able to resolve this by providing mappings in the "paths" property under "compilerOptions" from "this:is:my:module" to <source-root>/this/is/my/module.ts. However, sometimes the modules use relative paths and it would be nice if there was a way to convey to IntelliJ that it should use the fully-resolved name. For example, let's say there is a module under <source-root>/this/is/my/other/cool-module.ts, which wants to import the module at <source-root>/this/is/my/module.ts. In cool-module.ts, I can import it like so:

import * as myModule from "..:module";

But that path does not exist under "paths" and so IntelliJ cannot resolve it. Is there a way to convey to IntelliJ via the plugin, that it should use the fully-resolved name of the module when trying to go to a declaration? I have decorated ts.resolveModuleNames (apparently that's what was being used to resolve the module name) so that no errors show up complaining that the module is unresolved. But I would also like to have IntelliJ use this information so that I can go to the file by clicking on the relative module-name. This will also alleviate having to hardcode an entry for every module inside "paths". Is it possible to do this using the language service?

Thanks!

0

>Is there a way to convey to IntelliJ via the plugin, that it should use the fully-resolved name of the module when trying to go to a declaration?

No way to do this via service API:( TypeScript service is only used for completion/annotation, your need IDE support to be able to navigate to files using a custom path delimiter. You have to develop IDEA plugin for this... 

See http://www.jetbrains.org/intellij/sdk/docs/intro/intellij_platform.html

Feel free to ask questions at https://intellij-support.jetbrains.com/hc/en-us/community/topics/200366979-IntelliJ-IDEA-Open-API-and-Plugin-Development.

 

1

Please sign in to leave a comment.