My experience with loading a custom plugin on TS Server from a file has been quite challenging:
- To start, enabling workspace configuration using local TypeScript is necessary:
npm i typescript
package.json
:
{
"dependencies": {
"typescript": "^4.2.3"
}
}
.vscode/settings.json
{
"typescript.tsdk": "./node_modules/typescript/lib",
// ~/.config/Code/logs/**/tsserver.log
"typescript.tsserver.log": "verbose",
"typescript.enablePromptUseWorkspaceTsdk": true
}
Utilizing local TypeScript is vital as it ensures that the plugin is found within the correct directory by TS Server. Attempting to use global TypeScript leads to complications due to differences in working directories.
Enabling verbose logging may not be essential, but it helps in debugging and ensuring no details are missed during the process of setting up the plugin.
Including workspace TypeScript version prompt is also beneficial for maintaining consistency across projects.
- The next step involves creating your plugin within the project's
node_modules/plugin
directory.
This process may seem suboptimal, as having the source code in the node_modules
folder can be inconvenient. However, due to TS Server's working directory structure, there aren't straightforward alternatives at the moment.
It appears that writing the plugin directly in TypeScript without transpilation is not feasible.
- Finally, configuring TS Server to utilize the plugin and restarting it is required.
Updating the tsconfig.json
file with the plugin information and restarting TS Server is necessary to ensure successful integration.
If anyone has insights on improving this process or addressing the challenges mentioned, any suggestions would be greatly appreciated!
Edit:
An improvement suggestion is provided to streamline the process by adjusting the plugin file referencing methods. However, further enhancements are sought to simplify the setup without relying heavily on the node_modules
directory.
A bug report has been submitted for consideration: https://github.com/microsoft/TypeScript/issues/43124