microsoft / typespec

https://typespec.io/
MIT License
4.42k stars 207 forks source link

Allow multiple `ts-server` path configs in VSCode extension and reload on path change #4758

Open boan-anbo opened 13 hours ago

boan-anbo commented 13 hours ago

Issue

It is common to open multiple workspaces in VSCode for the same TypeSpec project, especially in monorepos.

Currently, tsp-server.path only accepts a single string.

https://github.com/microsoft/typespec/blob/5f21e0c53b767f5bbf5dfbe8795c530b1534fc81/packages/typespec-vscode/package.json#L61-L66

So if you change workspace locations, you will have to change the tsp-server path.

For example:

// you initially set the path relative to the root folder, 
// e.g. `${workspaceFolder}/packages/tsp_project/node_modules/@typespec/compiler`, 
// it only works when you open the monorepo root folder.
monorepo_root_folder:
    packages:
         // if you open another workspace window here, you'll have to reconfig the path to
         // `${workspaceFolder}/node_modules/@typespec/compiler`
          tsp_project:

This shouldn't be a problem if VSCode does well with monorepo detection, but it doesn't. So it's important to allow multiple paths, in the order of priority.

What's adding to the issue is that the extension currently doesn't reload on path change. Restart TSP Server doesn't work either. You have to uninstall and reinstall the extension for the new path to take effect.

Proposal

  1. Support path array for tsp-server.path config, in the order of search priority.
  2. Restart the extension automatically on config change.

I could open a PR if desired.

timotheeguerin commented 5 hours ago

I don't think we can load multiple language server(on top of the performance implication). VSCode typescript also requires you to pass a single path to the typescript version used.

What mono repo setup do you have so the server needs to be different?

What's adding to the issue is that the extension currently doesn't reload on path change. Restart TSP Server doesn't work either. You have to uninstall and reinstall the extension for the new path to take effect.

That would seem like quite an issue, do you mean if you change the server-path config it won't reload even if you do Restart TSP server or Reload window? Could you share the logs when that is happening

(filed a separate one #4765 on auto reloading)