VS Code Extension の contributes.typescriptServerPlugins
#typescript #vscode
TypeScript の Language Server に読み込ませる TypeScript Language Service Plugin を指定するオプション
Vue の VS Code Extension で使われてる
https://github.com/vuejs/language-tools/blob/f6cf306f889d9fd412015944ecfdfd001d2a9f6a/extensions/vscode/package.json#L89-L95
TypeScript Language Server が .vue を処理できるようにする plugin を読み込んでる
利用可能なオプション
https://code.visualstudio.com/api/references/contribution-points#contributes.typescriptServerPlugins
name, enableForWorkspaceTypeScriptVersionsの2つのオプションが指定できる (ように見える)
公式の JSON スキーマもある
https://github.com/microsoft/vscode/blob/1caa1739a73242046a52208e50b4e67529ac7560/extensions/typescript-language-features/schemas/package.schema.json
実はlanguages, configNamespaceオプションも指定できる!!!
https://github.com/microsoft/vscode/blob/b7c13a78e93c2762972be705c032fe8295a87ddb/extensions/typescript-language-features/src/tsServer/plugins.ts#L76-L83
Vue でも使われてる (参考1, 参考2)
VS Code 公式ドキュメントに記載がないのは、多分追記するの忘れてるだけ
mizdra.icon VS Code のドキュメントへの contribution チャンスかも?
languagesはその plugin で処理したい言語の language identifier を指定するオプション
configNamespaceは何だろ
https://github.com/microsoft/vscode/issues/75890
extension configuration (.vscode/settings.json などに書いてるアレ) の namespace (typescript.suggest.autoImportsでいうところのtypescriptの部分) を指定するオプションらしい
TypeScript Language Server と対話してる (VS Code 組み込みの) Extension が、この extension configuration を読んでるらしい
https://github.com/microsoft/vscode/blob/3eb4e36b6d62be9d2285cd6e22802ed6432fc47e/extensions/typescript-language-features/src/languageFeatures/completions.ts#L651-L663
で、読んだ値を TypeScript Language Server に渡してる?
https://github.com/microsoft/vscode/blob/db40434f562994116e5b21c24015a2e40b2504e6/extensions/typescript-language-features/src/languageFeatures/completions.ts#L478
https://github.com/microsoft/TypeScript/blob/3163fe7e3898c1f48cd9bc097b96e3426cd2a453/src/server/protocol.ts#L2167
多分こういうことだろう
configNamespace === "typescript"とすると、TypeScript Language Service Plugin にtypescript.suggest.autoImportsが渡る
configNamespace === "vue"とすると、TypeScript Language Service Plugin にvue.suggest.autoImportsが渡る
vue ではconfigNamespace === "typescript"にしてるっぽい
https://github.com/vuejs/language-tools/blob/f6cf306f889d9fd412015944ecfdfd001d2a9f6a/extensions/vscode/package.json#L93
しかし VS Code Extension から TypeScript Language Server の振る舞いを変えられるの、かなり hacky な感じがする
これどういう経緯で実装されたんだろう
https://github.com/microsoft/vscode/issues/75890#issuecomment-504571500
Keep in mind though this is not an official API. We added it for the angular folks to experiment with and it has not been actively maintained and may be changed/removed in the future
Angular 用に用意された API なの!
確かに https://github.com/microsoft/vscode/issues/25740 見るとそういう感じっぽい
「not an official API」シブい