Skip to content

TSServer Plugins with sub-packages/paths are not loadedΒ #57047

@kitten

Description

@kitten

πŸ”Ž 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:

  • 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;
    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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions