Skip to content

mfigard/webstorm-minimal-tsserver-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

webstorm-minimal-tsserver-plugin

Minimal reporoduction repo to show differences in TS Server plugin handling in VSCode and Webstorm.

The writing of the plugin is based off this documentation: https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin.

Setup

This repo uses Yarn as its project manager. Everything is committed in the repo so no additional command needs to be run.

Webstorm setup

TypeScript version

Open Settings > Languages & Frameworks > TypeScript and make sure TypeScript is loaded from ~/<path-to-your-project>/webstorm-minimal-tsserver-plugin/node_modules/typescript

image

TypeScript debugging

Open Help > Diagnostic Tools > Debug Log Settings... and make sure it includes the line com.intellij.lang.javascript.service.JSLanguageServiceQueue:trace

image

Restart the TypeScript language service and hit "Reload from disk" on the repo root: the TypeScript debug log should appear at the root of the repo with the name .log<ID>

image

VSCode setup

TypeScript version

cmd + shift + P > TypesScript: Select TypeScript version... and make sure to select the workspace version

image

TypeScript debugging

Open the TypeScript logs by doing cmd + shift + P > TypeScript: Open TS Server logs

Note: TypeScript logging may not be enabled, this command should offer to turn on logging if you don't have it enabled

image

The logs should somewhere around /Users/<user>/Library/Application Support/Code/logs/<id>/window3/exthost/vscode.typescript-language-features/tsserver-log-<log-id>/tsserver.log: you can see the exact path by opening the TypeScript output and checking for the path in the logs.

image

Results

Completion entry details

Goal

Add the custom suggestion myCustomFunction3 to the completions list with details like its source. Upon accepting the suggestion, the corresponding import should be added.

Trigger

  • Open packages/my-package/main.ts
  • Place the cursor after myCustomFunction (line 5)
  • Press ctrl + space on both Webstorm and VSCode

Plugin code

In plugins/tsserver/src/index.js:

  • Adding an entry to the completions list: function getCompletionsAtPosition (lines 18 to 49)
  • Adding details to the custom entry: function getCompletionEntryDetails (lines 52 to 124)

Observed behavior

VSCode (expected) Webstorm
The suggestion should appear in the list the same way other suggestions do. When selecting it, the import defined in the plugin is added. The custom entry myCustomFunction3 is shown in the list but doesn't appear the same way as other suggestions, with "No documentation found" in the info panel. When selecting it, the import defined in the plugin is not added
image image
vscode-custom-entry-details.mov
webstorm-custom-entry-details.mov

Conclusion

The details added in getCompletionEntryDetails seem to not be taken into account, especially the following fields:

  • displayParts showing the source of the function
  • codeActions defining the import line to add when selecting the custom completions entry

Custom code action commands

Goal

Add the custom quick fix "Add dependency for 'myCustomFunction3'" to the list of quick fixes. Upon selecting the custom quick fix, the function applyCodeActionCommand should be triggered with the name installCustomPackage, showing a log in the TS Server log.

Trigger

  • Open packages/my-package/main.ts
  • Place the cursor inside "custom-package" (line 1)
  • Display the list of quick fixes:
    • On VSCode: press cmd + .
    • On Webstorm: press opt + return

Plugin code

In plugins/tsserver/src/index.js:

  • Adding a custom quick fix for the TS error TS2307: function getCodeFixesAtPosition (lines 155 to 176)
  • Applying the custom code action command: function applyCodeActionCommand (lines 220 to 234)

Observed behavior

VSCode (expected) Webstorm
The custom quick fix appears in the list. When selecting it and looking at the logs, the function applyCodeActionCommand is triggered with the custom action name installCustomPackage. The custom quick fix appears in the list. When selecting it and looking at the logs, only the function getCodeFixesAtPosition is triggered but no logs from applyCodeActionCommand are found.
image image
image image

Conclusion

The function applyCodeActionCommand seems to not be triggered on Webstorm, which prevents custom code action commands from being run.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published