TypeFox / monaco-languageclient

Repo hosts npm packages for monaco-languageclient, vscode-ws-jsonrpc, monaco-editor-wrapper, @typefox/monaco-editor-react and monaco-languageclient-examples
https://www.npmjs.com/package/monaco-languageclient
MIT License
992 stars 171 forks source link

How to to use multiple workspacefolders? #653

Open zerocewl opened 1 month ago

zerocewl commented 1 month ago

I'm trying to enable auto completion in the monaco editor from different custom python folders using python-lsp-server. For a single folder this works fine using the workspaceFolder setting from the clientConfig as suggested in the python example config. So for my requirements i tried to use workspaceFolders, but i can not manage to set more folders, i think i'm missing something on the client side.

In the languageClientConfig startOptions i used workspace/didChangeWorkspaceFolders which seems to work with python-lsp-server.

On the client side is no setting for workspaceFolders so i tried to implement a custom workspaceProvider together with a custom workspace file, but this setting seem not to be used at all.

e.g.

  const userConfig: UserConfig = {
    languageClientConfig: {
      options: {
        name: 'Python Language Server',
        $type: 'WebSocket',
        host: 'localhost',
        port: 9002,
        path: 'python',
        startOptions: {
          onCall: (languageClient?: MonacoLanguageClient) => {
            languageClient?.sendRequest(
              'workspace/didChangeConfiguration',
              pluginConfig
            );
            languageClient?.sendRequest('workspace/didChangeWorkspaceFolders', {
              event: {
                added: [
                  {
                    name: 'workspace',
                    uri: URI.file(customUrl).toString(),
                  },
                ],
                removed: [
                ],
              },
            });
          },
          reportStatus: true,
        },
      },
      clientOptions: {
...
    },
    wrapperConfig: {
      serviceConfig: {
        userServices: {
          ...getConfigurationServiceOverride(),
        },
        debugLogging: true,
        workspaceConfig: {
          workspaceProvider: {
            trusted: true,
            workspace: {
              label: 'workspace',
              workspaceUri: monaco.Uri.file(customUrl ?? ''),
            },
            async open() {
              return true;
            },
          },
        },
      },
 ...

Can you suggest what i'm missing here? Is there any working example how to use multiple workspaceFolders?

kaisalmen commented 1 month ago

Is there any working example how to use multiple workspaceFolders?

Hi @zerocewl no we don't have such an example. What I observed though is that the pyright language server requires to have the files physically available (e.g. import). The import to hello2.py in this example is not marked as erroneous if the file exists. As client and server don't share the same file system this leads to problems. I am currently looking for a solution.

I don't know how pyright behaves in this scenario with multiple workspaces. Have you tried this in VSCode just to see if or how it works there?

CGNonofr commented 1 month ago

To have multiple workspace folders, you can use the workspaceUri but it should link to an existing file on the virtual filesystem

see https://github.com/CodinGame/monaco-vscode-api/blob/656c48cddc9ac2c9aead4d087edf18be991a49c7/demo/src/setup.common.ts#L174-L178