Repository navigation
Description
π Search Terms
"language server", "because only package name is allowed plugin name", "language server plugins"
π Version & Regression Information
This behaviour must be going back to 4.2.2 as per #43124.
β― Playground Link
No response
π» Code
tsconfig.json
{
"compilerOptions": {
"plugins": [
{
"name": "package/lsp"
}
]
}
}π Actual behavior
TypeScript rejects sub-path package plugins, as per:
TypeScript/src/server/editorServices.ts
Lines 4490 to 4493 in 23faef9
if (!pluginConfigEntry.name || parsePackageName(pluginConfigEntry.name).rest) { this.logger.info(`Skipped loading plugin ${pluginConfigEntry.name || JSON.stringify(pluginConfigEntry)} because only package name is allowed plugin name`); return; } - and;
TypeScript/src/compiler/moduleNameResolver.ts
Lines 2525 to 2531 in 23faef9
export function parsePackageName(moduleName: string): { packageName: string; rest: string; } { let idx = moduleName.indexOf(directorySeparator); if (moduleName[0] === "@") { idx = moduleName.indexOf(directorySeparator, idx + 1); } return idx === -1 ? { packageName: moduleName, rest: "" } : { packageName: moduleName.slice(0, idx), rest: moduleName.slice(idx + 1) }; }
tsserver log
Info 11 [15:52:00.931] Enabling plugin package/subpath from candidate paths: [...]node_modules/typescript/lib/tsserver.js/../../..
Info 12 [15:52:00.931] Skipped loading plugin package/lsp because only package name is allowed plugin name
π Expected behavior
Plugins are loaded as per either package.json:exports with subfolders specified, or via package/sub-path/package.json or package/sub-path/index.js.
Additional information about the issue
Related issues: #42688 and #42688.
If my understanding is correct, TypeScript only wants to allow packages that:
- have been installed via a package manager, so that opening VSCode without installing doesn't immediately run unauthorised code
- are not relative paths or local code that's checked into a repository
Neither applies to sub-packages. The use-case here is to publish packages that both provide code and an LSP package in one, without splitting this into two packages because of the assertion in TypeScript.
Activity
RyanCavanaugh commentedon Jan 16, 2024
PRs accepted, but this will need to be very carefully vetted. We might need some different syntax to disambiguate that
packageisn't interpreted by anyone to be a relative pathkitten commentedon Feb 1, 2024
PR, as linked, is for the proposed change. Happy to of course make changes, if a different syntax is required, but currently, Iβm assuming that the PR can for now represent behaviour without breaking the documented behaviour that a package name is expected, or how the wiki puts it: