Skip to content

workspace folders are configured twice at startup #1372

@FlorianKroiss

Description

@FlorianKroiss

During initialization of the language server, we already transmit the workspace folders, see

initParams.setWorkspaceFolders(getRelevantWorkspaceFolders());

When we are done with the initialization, we immediately schedule a job to send a WorkspaceFoldersChangeEvent with same projects again, see:

private void watchProjects() {
if (!supportsWorkspaceFolderCapability()) {
return;
}
final LanguageServer currentLS = context.languageServer;
new WorkspaceJob("Setting watch projects on server " + serverDefinition.label) { //$NON-NLS-1$
@Override
public IStatus runInWorkspace(@Nullable IProgressMonitor monitor) throws CoreException {
final var wsFolderEvent = new WorkspaceFoldersChangeEvent();
wsFolderEvent.getAdded().addAll(getRelevantWorkspaceFolders());
if (currentLS != null && currentLS == context.languageServer) {
currentLS.getWorkspaceService()
.didChangeWorkspaceFolders(new DidChangeWorkspaceFoldersParams(wsFolderEvent));
}
ResourcesPlugin.getWorkspace().addResourceChangeListener(workspaceFolderUpdater,
IResourceChangeEvent.POST_CHANGE | IResourceChangeEvent.PRE_DELETE | IResourceChangeEvent.PRE_CLOSE);
return Status.OK_STATUS;
}
}.schedule();
}

Depending on how the language server handles a WorkspaceFoldersChangeEvent, this might degrade the initial responsiveness of the LS quite a bit.
For example, basedpyright has to remove all workspace folders only to add them all back again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions