Skip to content

feat: expose workspace roots in extension API

Warren Gifford requested to merge extension-files into master

Created by: sqs

These new APIs make it easier for language extensions to communicate with language servers, which generally have a 1-to-1 correspondence with workspace roots. Previously extensions could only know the documents that were open; now they can know which repos are open. (They could've determined this by manually munging the URI, but it's much cleaner to have an API designed for this.)

This PR does not need to update the CHANGELOG because it is not user facing

Example snippets:

    /** Gets the workspace root that contains the given URI. */
    function getWorkspaceRoot(uri: string): string | undefined {
        const root = sourcegraph.workspace.roots.find(root =>
            uri.startsWith(root.uri.toString())
        )
        return root ? root.uri.toString() : undefined
    }
        sourcegraph.workspace.onDidChangeRoots).pipe(
            // Only startWith a root if there are roots. Otherwise, there is no need to start, because when a root
            // is present, the observable will emit.
            sourcegraph.workspace.roots.length > 0 ? startWith(void 0) : tap(),
            map(() => sourcegraph.workspace.roots)
        )

Merge request reports

Loading